Skip to content

[Feature] UI event propagation and focus #155

@vmarcella

Description

@vmarcella

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

  • Click sets focus to clicked widget
  • Tab key moves focus to next widget
  • Keyboard events go to focused widget
  • Mouse enter/leave tracked for hover states
  • Parent widgets can intercept events

Affected Crates

lambda-rs

Notes

  • Widget IDs needed for focus tracking
  • Consider focus order (tab index)

Metadata

Metadata

Assignees

No one assigned

    Labels

    UIAll things user interface relatedenhancementNew feature or requestlambda-rsIssues pertaining to the core framework

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions