mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-14 00:47:14 +00:00
fix(widgets/list): fix line length calculation for selectable lists
The code that outputs the list elements uses the full inner width of its block, without taking the width of the highlight symbol into consideration. This allows the elements to overflow the box and draw over the block's border. To fix that, we need to reduce the target width for the list elements.
This commit is contained in:
parent
8debb0d338
commit
8f9aa276e8
1 changed files with 5 additions and 9 deletions
|
@ -188,7 +188,7 @@ where
|
||||||
// Not supported
|
// Not supported
|
||||||
_ => (list_area.left(), list_area.top() + i as u16),
|
_ => (list_area.left(), list_area.top() + i as u16),
|
||||||
};
|
};
|
||||||
let (x, style) = if let Some(s) = selected {
|
let (elem_x, style) = if let Some(s) = selected {
|
||||||
if s == i + state.offset {
|
if s == i + state.offset {
|
||||||
let (x, _) = buf.set_stringn(
|
let (x, _) = buf.set_stringn(
|
||||||
x,
|
x,
|
||||||
|
@ -206,18 +206,14 @@ where
|
||||||
} else {
|
} else {
|
||||||
(x, None)
|
(x, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let max_element_width = (list_area.width - (elem_x - x)) as usize;
|
||||||
match item {
|
match item {
|
||||||
Text::Raw(ref v) => {
|
Text::Raw(ref v) => {
|
||||||
buf.set_stringn(
|
buf.set_stringn(elem_x, y, v, max_element_width, style.unwrap_or(self.style));
|
||||||
x,
|
|
||||||
y,
|
|
||||||
v,
|
|
||||||
list_area.width as usize,
|
|
||||||
style.unwrap_or(self.style),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Text::Styled(ref v, s) => {
|
Text::Styled(ref v, s) => {
|
||||||
buf.set_stringn(x, y, v, list_area.width as usize, style.unwrap_or(s));
|
buf.set_stringn(elem_x, y, v, max_element_width, style.unwrap_or(s));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue