aboutsummaryrefslogtreecommitdiff
path: root/pixel-client
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client')
-rw-r--r--pixel-client/src/main.rs2
-rw-r--r--pixel-client/src/menu.rs7
-rw-r--r--pixel-client/src/render/font.rs2
-rw-r--r--pixel-client/src/ui.rs30
4 files changed, 32 insertions, 9 deletions
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index 247cd636..fb98d12f 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -117,7 +117,7 @@ fn main() {
last_tick += dt;
- renderer.set_ui_view(5.);
+ renderer.set_ui_view(4.);
match &mut state {
State::Ingame(x) => x.draw(&mut renderer),
State::Menu(x) => x.draw(&mut renderer),
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs
index 6c382331..bce5198b 100644
--- a/pixel-client/src/menu.rs
+++ b/pixel-client/src/menu.rs
@@ -98,15 +98,16 @@ impl Menu {
self.map.draw(ctx);
self.ui_state.draw(ctx, |ui| {
- if ui.button("Join") {
+ if ui.button(80., "Join") {
eprintln!("join button")
}
- if ui.button("Settings") {
+ if ui.button(80., "Settings") {
eprintln!("settings button")
}
- if ui.button("Quit") {
+ if ui.button(80., "Quit") {
eprintln!("quit button")
}
+ ui.fill();
});
ctx.draw_ui(SpriteDraw::overlay(
diff --git a/pixel-client/src/render/font.rs b/pixel-client/src/render/font.rs
index 392c1d66..38ebe711 100644
--- a/pixel-client/src/render/font.rs
+++ b/pixel-client/src/render/font.rs
@@ -41,6 +41,6 @@ impl<'a> Renderer<'a> {
line_height = line_height.max(r.height() as f32)
}
}
- cursor + Vec2::Y * line_height
+ (cursor - position.y) + Vec2::Y * line_height
}
}
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;