diff options
Diffstat (limited to 'pixel-client/src/ui.rs')
-rw-r--r-- | pixel-client/src/ui.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/pixel-client/src/ui.rs b/pixel-client/src/ui.rs new file mode 100644 index 00000000..557800aa --- /dev/null +++ b/pixel-client/src/ui.rs @@ -0,0 +1,50 @@ +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); + } + } +} |