pub mod layout;
mod render;
pub mod widget;
pub use layout::{Align, FlexDir, LayoutNode, Rect, Size};
pub use widget::Widget;
use yog_gfx::GfxContext;
pub struct UiRoot {
pub id: String,
pub root: Widget,
pub(crate) layout_root: LayoutNode,
pub needs_layout: bool,
}
impl UiRoot {
pub fn new(id: impl Into<String>, root: Widget) -> Self {
Self { id: id.into(), root, layout_root: LayoutNode::default(), needs_layout: true }
}
pub fn layout(&mut self, screen_w: f32, screen_h: f32) {
self.layout_root = layout::compute(&self.root, screen_w, screen_h);
self.needs_layout = false;
}
pub fn render(&self, ctx: &GfxContext) {
let d2d = ctx.draw2d();
render::render_node(&d2d, &self.root, &self.layout_root);
}
pub fn hit_test(&self, mx: f32, my: f32) -> Option<&LayoutNode> {
layout::hit_test(&self.layout_root, mx, my)
}
}