centered UI

This commit is contained in:
Rolf Martin Glomsrud 2023-03-04 03:33:39 +01:00
parent caf515b14f
commit 7324861472
2 changed files with 13 additions and 15 deletions

View file

@ -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!"){

View file

@ -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;