aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src/ui.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-25 14:46:09 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-25 14:46:09 +0200
commit3c056d68fe9c28b0c867a8d8bb3d4394745296d0 (patch)
tree60e47ed4ee86ee044e4a14a7a4d2d008f76c6355 /pixel-client/src/ui.rs
parent16dbbba23e3534105707fbb861a1dce5d9ef2f0e (diff)
downloadhurrycurry-3c056d68fe9c28b0c867a8d8bb3d4394745296d0.tar
hurrycurry-3c056d68fe9c28b0c867a8d8bb3d4394745296d0.tar.bz2
hurrycurry-3c056d68fe9c28b0c867a8d8bb3d4394745296d0.tar.zst
main menu side column
Diffstat (limited to 'pixel-client/src/ui.rs')
-rw-r--r--pixel-client/src/ui.rs30
1 files changed, 26 insertions, 4 deletions
diff --git a/pixel-client/src/ui.rs b/pixel-client/src/ui.rs
index 5ac1a79f..9a04c5c0 100644
--- a/pixel-client/src/ui.rs
+++ b/pixel-client/src/ui.rs
@@ -25,6 +25,7 @@ pub struct UiState {
pub struct Ui<'a, 'b> {
cursor: Vec2,
+ size: Vec2,
cross_height: f32,
index: usize,
direction_horizontal: bool,
@@ -56,6 +57,7 @@ impl UiState {
let mut u = Ui {
cursor: Vec2::ZERO,
direction_horizontal: false,
+ size: renderer.ui_size,
renderer,
state: self,
cross_height: 0.,
@@ -91,13 +93,15 @@ impl FocusDevice {
impl<'a, 'b> Ui<'a, 'b> {
pub fn text(&mut self, text: &str) {
- let size = self.renderer.draw_text(self.cursor, text);
+ let margin = Vec2::splat(2.);
+ let size = margin + self.renderer.draw_text(self.cursor + margin, text) + margin;
self.advance(size);
}
- pub fn button(&mut self, label: &str) -> bool {
+ pub fn button(&mut self, w: f32, label: &str) -> bool {
let c = self.cursor;
- let margin = Vec2::splat(2.);
- let size = self.renderer.draw_text(self.cursor + margin, label) + margin + margin;
+ let margin = Vec2::splat(4.);
+ let text_size = self.renderer.draw_text(self.cursor + margin, label);
+ let size = margin + Vec2::new(w, text_size.y) + margin;
self.index += 1;
@@ -135,6 +139,24 @@ impl<'a, 'b> Ui<'a, 'b> {
released
}
+ pub fn fill(&mut self) {
+ self.renderer.draw_ui(SpriteDraw::screen(
+ self.renderer.misc_textures.solid,
+ i32::MAX - 1,
+ self.cursor,
+ self.get_remaining(),
+ Some([30, 30, 30, 200]),
+ ));
+ }
+
+ pub fn get_remaining(&self) -> Vec2 {
+ if self.direction_horizontal {
+ Vec2::new(self.size.x - self.cursor.x, self.cross_height)
+ } else {
+ Vec2::new(self.cross_height, self.size.y - self.cursor.y)
+ }
+ }
+
pub fn advance(&mut self, size: Vec2) {
if self.direction_horizontal {
self.cursor.x += size.x;