1pub mod component;
21pub mod event;
22pub mod image;
23pub mod layout;
24mod render;
25pub mod scroll;
26#[cfg(test)]
27mod state_tests;
28pub mod text;
29pub mod textbox;
30pub mod widget;
31
32pub use event::UiEvent;
33pub use layout::{hit_path, node_at, set_focus, Align, FlexDir, GridLines, LayoutNode, Rect};
34pub use scroll::ScrollState;
35pub use textbox::{TextBoxEvent, TextBoxState};
36pub use widget::{
37 Action, Cell, Dock, FocusStyle, GridLength, GridSpec, HAlign, StateFlags, StateStyles, Stretch,
38 StylePatch, Track, Units, VAlign, Widget,
39};
40
41use yog_gfx::GfxContext;
42
43pub struct UiRoot {
45 pub id: String,
46 pub root: Widget,
47 pub layout_root: LayoutNode,
48 pub needs_layout: bool,
49}
50
51impl UiRoot {
52 pub fn new(id: impl Into<String>, root: Widget) -> Self {
53 Self {
54 id: id.into(),
55 root,
56 layout_root: LayoutNode::default(),
57 needs_layout: true,
58 }
59 }
60
61 pub fn layout(&mut self, screen_w: f32, screen_h: f32) {
63 self.layout_root = layout::compute(&self.root, screen_w, screen_h);
64 self.needs_layout = false;
65 }
66
67 pub fn render(&self, ctx: &GfxContext) {
70 text::use_host_metrics(ctx);
71 image::use_host_images(ctx);
72 let d2d = ctx.draw2d();
73 render::render_node(&d2d, &self.root, &self.layout_root);
74 }
75
76 pub fn hit_test(&self, mx: f32, my: f32) -> Option<&LayoutNode> {
78 layout::hit_test(&self.layout_root, mx, my)
79 }
80
81 pub fn find_rect(&self, id: &str) -> Option<Rect> {
84 layout::find_by_id(&self.layout_root, id)
85 }
86
87 pub fn find_node(&self, id: &str) -> Option<&LayoutNode> {
90 layout::find_node(&self.layout_root, id)
91 }
92}