From 7324861472de45d7107886b0cee295de3395cbea Mon Sep 17 00:00:00 2001 From: polsevev Date: Sat, 4 Mar 2023 03:33:39 +0100 Subject: [PATCH] centered UI --- src/dropdown.rs | 15 +++++---------- src/main.rs | 13 ++++++++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/dropdown.rs b/src/dropdown.rs index faf0983..1880c6b 100644 --- a/src/dropdown.rs +++ b/src/dropdown.rs @@ -3,8 +3,6 @@ use macroquad::hash; use macroquad::{ui::root_ui, window::screen_width, prelude::Vec2}; - - enum Status{ Open, Closed @@ -24,14 +22,14 @@ impl ButtonDropDown{ status:Status::Closed } } - - pub fn render(&mut self, location:Vec2) -> String{ + + pub fn render(&mut self) -> String{ let mut algo = ""; - + let location = Vec2::new((screen_width() / 2.) - 150., 200.); match self.status{ Status::Open => { - let size = Vec2::new(250., (self.elements.len() as f32*25.0) + 20.0); + let size = Vec2::new(300., (self.elements.len() as f32*25.0) + 20.0); root_ui().window(hash!(), location, size, |ui|{ let mut position = Vec2::new(10.0, 10.); @@ -43,13 +41,10 @@ impl ButtonDropDown{ } position.y += 25.0; } - - - }); } Status::Closed => { - root_ui().window(hash!(), Vec2::new(screen_width()*0.01, 45.), Vec2::new(300., 50.), |ui|{ + root_ui().window(hash!(), location, Vec2::new(300., 50.), |ui|{ let uppercasedSelected = format!("{}{}", self.selected[0..1].to_string().to_uppercase(), self.selected[1..self.selected.len()].to_string()); ui.label(Vec2::new(10.0, 0.0), format!("Curent chosen algorithm: {}", uppercasedSelected).as_str()); if ui.button(Vec2::new(10.0, 20.0), "Open Menu!"){ diff --git a/src/main.rs b/src/main.rs index 2eb7728..00bb625 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,14 +28,17 @@ async fn main() { Err(_)=> {100} }; - draw_text("Sorting!", screen_width()*0.3, screen_height()*0.1, 100.0, GREEN); - draw_text(format!("Length: {}", length.to_string()).as_str(), screen_width()*0.83, 30., 20.0, BLACK); - draw_text(&get_fps().to_string(), screen_width()*0.7, 30.0, 20.0, BLACK); - root_ui().window(hash!(), Vec2::new(screen_width()*0.01, 45.), Vec2::new(250., 50.), |ui|{ + let mut centerX = screen_width()/2.0; + + + draw_text("Sorting!", centerX-170.0, screen_height()*0.1, 100.0, BLACK); + draw_text(&get_fps().to_string(), centerX + 300., 30.0, 20.0, BLACK); + root_ui().window(hash!(), Vec2::new(centerX - 150.0, 150.), Vec2::new(300., 45.), |ui|{ ui.input_text(hash!(), "Delay (ms)", &mut delayText); ui.input_text(hash!(), "Length Of Array!", &mut lengthString); }); - let mut algo = buttonDropDown.render(Vec2::new(screen_width()*0.01, 45.)); + + let mut algo = buttonDropDown.render(); if algo != ""{ algorithm::Algorithm::run(length, 1.0, algo.to_string()).await;