diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-07-27 15:23:11 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-07-27 15:44:33 +0200 | 
| commit | 810f1ae9ee89ae0f49601e156bff4c2f5c1aad32 (patch) | |
| tree | 8f0fefceb7de7976aa6eb1f87e6c675d434a9ed7 /pixel-client/src/ui.rs | |
| parent | cdea92a85fd20fdf9de771ec6fe852a1a3ee0a5a (diff) | |
| download | hurrycurry-810f1ae9ee89ae0f49601e156bff4c2f5c1aad32.tar hurrycurry-810f1ae9ee89ae0f49601e156bff4c2f5c1aad32.tar.bz2 hurrycurry-810f1ae9ee89ae0f49601e156bff4c2f5c1aad32.tar.zst | |
add credits menu and ui flow
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);      } | 
