WrapperWidget::activate passthrough

This commit is contained in:
Jonathan Johnson 2024-09-22 10:35:11 -07:00
parent e178c088c0
commit fb1888d53f
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
4 changed files with 16 additions and 2 deletions

View file

@ -65,6 +65,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
apps.
- The default logging output has been trimmed to only show errors for wgpu,
winit, and naga. Thanks to @bluenote10 for the feedback!
- `WrapperWidget::activate`'s default implementation now activates the wrapped
widget.
### Fixed
@ -82,6 +84,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Resize` now performs a second layout pass, if necessary, to ensure that
children widgets have an opportunity to fill the resized area. Additionally,
the first SizeToFit measurement will be performed with the minimum dimension.
- When a keyboard-activated widget activates another widget during its callback,
the key-up event now sends the deactivate event to the finally-activated
widget.
### Added

View file

@ -306,6 +306,12 @@ impl Tree {
self.data.lock().active
}
pub(crate) fn active_widget_id(&self) -> Option<WidgetId> {
let data = self.data.lock();
data.active.map(|node| data.nodes[node].widget.id())
}
pub(crate) fn hovered_widget(&self) -> Option<LotId> {
self.data.lock().hover
}

View file

@ -674,7 +674,10 @@ pub trait WrapperWidget: Debug + Send + 'static {
/// The widget has become the active widget.
#[allow(unused_variables)]
fn activate(&mut self, context: &mut EventContext<'_>) {}
fn activate(&mut self, context: &mut EventContext<'_>) {
let child = self.child_mut().mounted(context);
context.for_other(&child).activate();
}
/// The widget is no longer active.
#[allow(unused_variables)]

View file

@ -1430,7 +1430,7 @@ where
kludgine,
)
.activate();
self.keyboard_activated = Some(default.id());
self.keyboard_activated = self.tree.active_widget_id();
}
} else if let Some(keyboard_activated) = self
.keyboard_activated