mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-14 13: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();
|
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
|
/// Returns index of focused inner view
|
||||||
pub fn get_focus_index(&self) -> usize {
|
pub fn get_focus_index(&self) -> usize {
|
||||||
self.focus
|
self.focus
|
||||||
@ -519,6 +529,10 @@ impl View for LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(&mut self, event: Event) -> EventResult {
|
fn on_event(&mut self, event: Event) -> EventResult {
|
||||||
|
if self.is_empty() {
|
||||||
|
return EventResult::Ignored;
|
||||||
|
}
|
||||||
|
|
||||||
self.check_focus_grab(&event);
|
self.check_focus_grab(&event);
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
@ -593,7 +607,7 @@ impl View for LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn important_area(&self, _: Vec2) -> Rect {
|
fn important_area(&self, _: Vec2) -> Rect {
|
||||||
if self.children.is_empty() {
|
if self.is_empty() {
|
||||||
// Return dummy area if we are empty.
|
// Return dummy area if we are empty.
|
||||||
return Rect::from((0, 0));
|
return Rect::from((0, 0));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user