mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-12 12:13:08 +00:00
Fix panic with empty LinearLayout
This commit is contained in:
parent
62807f84fb
commit
b2d800c798
@ -145,6 +145,16 @@ impl LinearLayout {
|
||||
self.invalidate();
|
||||
}
|
||||
|
||||
/// Returns the number of children.
|
||||
pub fn len(&self) -> usize {
|
||||
self.children.len()
|
||||
}
|
||||
|
||||
/// Returns `true` if this view has no children.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.children.is_empty()
|
||||
}
|
||||
|
||||
/// Returns index of focused inner view
|
||||
pub fn get_focus_index(&self) -> usize {
|
||||
self.focus
|
||||
@ -519,6 +529,10 @@ impl View for LinearLayout {
|
||||
}
|
||||
|
||||
fn on_event(&mut self, event: Event) -> EventResult {
|
||||
if self.is_empty() {
|
||||
return EventResult::Ignored;
|
||||
}
|
||||
|
||||
self.check_focus_grab(&event);
|
||||
|
||||
let result = {
|
||||
@ -593,7 +607,7 @@ impl View for LinearLayout {
|
||||
}
|
||||
|
||||
fn important_area(&self, _: Vec2) -> Rect {
|
||||
if self.children.is_empty() {
|
||||
if self.is_empty() {
|
||||
// Return dummy area if we are empty.
|
||||
return Rect::from((0, 0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user