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:
Björn Steinbrink 2020-04-15 14:55:34 +02:00 committed by Florian Dehau
parent 8debb0d338
commit 8f9aa276e8

View file

@ -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));
} }
}; };
} }