Skip to main content

bexa_ui_core/
framework.rs

1use taffy::prelude::*;
2use winit::event::WindowEvent;
3use winit::event::KeyEvent;
4use winit::keyboard::ModifiersState;
5
6pub struct DrawContext<'a> {
7    pub renderer: &'a mut crate::Renderer,
8    pub layout: &'a Layout,
9}
10
11pub struct EventContext<'a> {
12    pub event: &'a WindowEvent,
13    pub layout: &'a Layout,
14}
15
16pub trait Widget {
17    fn style(&self) -> Style {
18        Style::default()
19    }
20
21    fn draw(&self, _ctx: &mut DrawContext) {}
22
23    fn handle_event(&mut self, _ctx: &mut EventContext) -> bool {
24        false
25    }
26
27    /// Called when this widget has focus and a key is pressed.
28    /// Returns true if the event was consumed.
29    fn handle_key_event(&mut self, _event: &KeyEvent, _modifiers: ModifiersState) -> bool {
30        false
31    }
32
33    fn is_focusable(&self) -> bool {
34        false
35    }
36
37    fn set_focus(&mut self, _focused: bool) {}
38
39    fn activate(&mut self) {}
40
41    fn clear_active(&mut self) {}
42
43    fn is_scrollable(&self) -> bool {
44        false
45    }
46
47    /// Called after text rendering to feed back measured pixel widths.
48    fn update_measures(&mut self, _measures: &[Vec<f32>]) {}
49}