Overview
Add event propagation system for UI that handles focus, hover tracking, and
input event routing to the correct widget.
Current State
No response
Scope
Goals:
- Focus management (which widget receives keyboard input)
- Hover tracking for mouse enter/leave
- Event bubbling (child to parent)
- Event capture (parent before child)
Non-Goals:
- Custom event types
- Event cancellation
Proposed API
pub struct UiContext {
root: Box<dyn Widget>,
focused: Option<WidgetId>,
hovered: Option<WidgetId>,
}
impl UiContext {
pub fn new(root: impl Widget + 'static) -> Self;
pub fn handle_mouse_move(&mut self, x: f32, y: f32);
pub fn handle_mouse_button(&mut self, button: Button, pressed: bool);
pub fn handle_key(&mut self, key: Key);
pub fn set_focus(&mut self, widget: WidgetId);
pub fn focused(&self) -> Option<WidgetId>;
pub fn render(&mut self, ctx: &mut RenderContext) -> Vec<RenderCommand>;
}
Acceptance Criteria
Affected Crates
lambda-rs
Notes
- Widget IDs needed for focus tracking
- Consider focus order (tab index)