use crate::render::Renderer; use hurrycurry_protocol::glam::Vec2; #[derive(Default, Debug)] pub struct UiState { focus: usize, } pub struct Ui<'a, 'b> { cursor: Vec2, cross_height: f32, direction_horizontal: bool, renderer: &'a mut Renderer<'b>, state: &'a mut UiState, } impl UiState { pub fn draw(&mut self, renderer: &mut Renderer, ui: impl FnOnce(&mut Ui)) { let mut u = Ui { cursor: Vec2::ZERO, direction_horizontal: false, renderer, state: self, cross_height: 0., }; ui(&mut u); } } impl<'a, 'b> Ui<'a, 'b> { pub fn text(&mut self, text: &str) { let size = self.renderer.draw_text(self.cursor, text); self.advance(size); } pub fn button(&mut self, label: &str) -> bool { let size = self.renderer.draw_text(self.cursor, label); self.advance(size); false } pub fn advance(&mut self, size: Vec2) { if self.direction_horizontal { self.cursor.x += size.x; self.cross_height = self.cross_height.max(size.y); } else { self.cursor.y += size.y; self.cross_height = self.cross_height.max(size.x); } } }