-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with value now returns whatever the closure returns
- Loading branch information
1 parent
4c064a5
commit 4e431e5
Showing
9 changed files
with
374 additions
and
413 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use anathema_state::StateId; | ||
use anathema_widgets::components::{AnyComponent, AnyEventCtx, ComponentContext}; | ||
use anathema_widgets::{Elements, WidgetId, WidgetKind, WidgetTree}; | ||
|
||
use crate::events::EventCtx; | ||
|
||
pub(crate) trait Tree<'bp> { | ||
fn with_component<F, V>( | ||
&mut self, | ||
widget_id: WidgetId, | ||
state_id: StateId, | ||
event_ctx: &mut EventCtx<'_, '_, 'bp>, | ||
f: F, | ||
) -> Option<V> | ||
where | ||
F: FnOnce(&mut dyn AnyComponent, AnyEventCtx<'_, '_, '_>) -> V; | ||
} | ||
|
||
impl<'bp> Tree<'bp> for WidgetTree<'bp> { | ||
fn with_component<F, V>( | ||
&mut self, | ||
widget_id: WidgetId, | ||
state_id: StateId, | ||
event_ctx: &mut EventCtx<'_, '_, 'bp>, | ||
f: F, | ||
) -> Option<V> | ||
where | ||
F: FnOnce(&mut dyn AnyComponent, AnyEventCtx<'_, '_, '_>) -> V, | ||
{ | ||
self.with_value_mut(widget_id, |path, widget, tree| { | ||
let WidgetKind::Component(component) = widget else { return None }; | ||
if !component.dyn_component.accept_focus_any() { | ||
return None; | ||
} | ||
|
||
let (node, values) = tree.get_node_by_path(path)?; | ||
let elements = Elements::new(node.children(), values, event_ctx.attribute_storage); | ||
let state = event_ctx.states.get_mut(state_id); | ||
|
||
let component_ctx = ComponentContext::new( | ||
state_id, | ||
component.parent, | ||
component.assoc_functions, | ||
event_ctx.assoc_events, | ||
); | ||
|
||
let lol = AnyEventCtx { | ||
state, | ||
elements, | ||
context: event_ctx.context, | ||
component_ctx, | ||
}; | ||
|
||
let value = f(&mut *component.dyn_component, lol); | ||
Some(value) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.