mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
This change fixes cursive issue #428, caused by indexing into an empty list. The issue is corrected by using the .get() method to safely handle the case where the requested index doesn't exist, and renders no label in that case.
This commit is contained in:
parent
833ad6889e
commit
5423a9a003
@ -892,12 +892,15 @@ impl<T: 'static> View for SelectView<T> {
|
||||
printer.print((0, 0), "<");
|
||||
printer.print((x, 0), ">");
|
||||
|
||||
let label = &self.items[self.focus()].label;
|
||||
if let Some(label) =
|
||||
self.items.get(self.focus()).map(|item| &item.label)
|
||||
{
|
||||
// And center the text?
|
||||
let offset =
|
||||
HAlign::Center.get_offset(label.width(), x + 1);
|
||||
|
||||
// And center the text?
|
||||
let offset = HAlign::Center.get_offset(label.width(), x + 1);
|
||||
|
||||
printer.print_styled((offset, 0), label.into());
|
||||
printer.print_styled((offset, 0), label.into());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Non-popup mode: we always print the entire list.
|
||||
|
Loading…
Reference in New Issue
Block a user