Skip to content

Commit

Permalink
Fix event handling for Option<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Sep 17, 2024
1 parent b093dde commit c1ad880
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions crates/tui/src/view/component/recipe_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ impl EventHandler for RecipePane {
}

fn children(&mut self) -> Vec<Component<Child<'_>>> {
self.recipe_state
.get_mut()
.map(|state| state.to_child_mut())
.into_iter()
.collect()
if let Some(state) = self.recipe_state.get_mut() {
vec![state.to_child_mut()]
} else {
vec![]
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions crates/tui/src/view/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ pub trait EventHandler {

/// Enable `Component<Option<T>>` with an empty event handler
impl<T: EventHandler> EventHandler for Option<T> {
fn update(&mut self, _: &mut UpdateContext, event: Event) -> Update {
Update::Propagate(event)
fn update(&mut self, context: &mut UpdateContext, event: Event) -> Update {
if let Some(inner) = self.as_mut() {
inner.update(context, event)
} else {
Update::Propagate(event)
}
}

fn children(&mut self) -> Vec<Component<Child<'_>>> {
Vec::new()
if let Some(inner) = self.as_mut() {
inner.children()
} else {
vec![]
}
}
}

Expand Down

0 comments on commit c1ad880

Please sign in to comment.