add text button ui helper

This commit is contained in:
Crispy 2024-12-23 23:58:09 +01:00
parent cfadd8a0b6
commit 2ecb86d283
3 changed files with 23 additions and 17 deletions

View file

@ -18,7 +18,7 @@ use editor::{Editor, ExitState};
use level::{Chapter, Level};
use solution::Solution;
use theme::*;
use ui::{simple_button, simple_option_button, text_input, ShapedText};
use ui::{simple_option_button, text_button, text_input, ShapedText};
use util::*;
const TITLE_TEXT: &str = concat!("Marble Machinations v", env!("CARGO_PKG_VERSION"));
@ -240,24 +240,17 @@ impl Game {
}
let next_id = get_free_id(solutions, Solution::id);
if simple_button(
if text_button(
d,
&mouse,
level_list_width + 10,
solution_y,
entry_width,
30,
"new solution",
) {
self.selected_solution = solutions.len();
solutions.push(Solution::new(level, next_id));
}
d.draw_text(
"new solution",
level_list_width + 15,
solution_y + 5,
20,
Color::WHITE,
);
if let Some(solution) = solutions.get_mut(self.selected_solution) {
let column_x = level_list_width + entry_width + 20;
@ -276,20 +269,18 @@ impl Game {
let id_text = format!("{}", solution.id());
d.draw_text(&id_text, column_x, y + 35, 10, Color::GRAY);
if simple_button(d, &mouse, column_x, y + 50, 220, 30) {
if text_button(d, &mouse, column_x, y + 50, 220, "clone") {
let cloned = solution.new_copy(next_id);
self.selected_solution = solutions.len();
solutions.push(cloned);
return;
}
d.draw_text("clone", column_x + 5, y + 55, 20, Color::WHITE);
if simple_button(d, &mouse, column_x, y + 85, 220, 30) {
if text_button(d, &mouse, column_x, y + 85, 220, "edit") {
let mut editor = Editor::new(solution.clone(), level.clone());
editor.center_view(d);
self.open_editor = Some(editor);
}
d.draw_text("edit", column_x + 5, y + 90, 20, Color::WHITE);
}
} else {
self.solutions.insert(level.id().to_owned(), Vec::new());