diff options
Diffstat (limited to 'pixel-client/src/ui.rs')
-rw-r--r-- | pixel-client/src/ui.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/pixel-client/src/ui.rs b/pixel-client/src/ui.rs index 684fb5b3..9e3e1a3e 100644 --- a/pixel-client/src/ui.rs +++ b/pixel-client/src/ui.rs @@ -120,12 +120,38 @@ impl FocusDevice { } impl<'a, 'b> Ui<'a, 'b> { + pub fn vertical(&mut self, content: impl FnOnce(&mut Ui)) { + self.flow(false, content) + } + pub fn horizontal(&mut self, content: impl FnOnce(&mut Ui)) { + self.flow(true, content) + } + pub fn flow(&mut self, dir: bool, content: impl FnOnce(&mut Ui)) { + let d = self.direction_horizontal; + let ch = self.cross_height; + let c = self.cursor; + self.direction_horizontal = dir; + self.cross_height = 0.; + content(self); + let size = (self.cursor - c).max(if dir { Vec2::Y } else { Vec2::X } * self.cross_height); + self.direction_horizontal = d; + self.cross_height = ch; + self.cursor = c; + self.advance(size); + } + pub fn text(&mut self, text: &str) { + self.scaled_text(text, 1.) + } + pub fn small_text(&mut self, text: &str) { + self.scaled_text(text, 0.5) + } + pub fn scaled_text(&mut self, text: &str, scale: f32) { let margin = Vec2::splat(2.); let size = margin + self .renderer - .draw_text(self.cursor + margin, text, 1., None) + .draw_text(self.cursor + margin, text, scale, None) + margin; self.advance(size); } |