From 3f71603961860e683f799e8705760998036aab27 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Fri, 27 Feb 2026 14:27:33 +0100 Subject: [PATCH] improve gui elements styling when disabled --- include/config.hpp | 4 +- src/gui.cpp | 94 ++++++++++++++++++++++++---------------------- src/state.cpp | 3 +- 3 files changed, 53 insertions(+), 48 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 1970fff..d5614b0 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -46,8 +46,8 @@ constexpr float SPRING_CONSTANT = 5.0; // Mass spring system constexpr float DAMPENING_CONSTANT = 1.0; // Mass spring system constexpr float REST_LENGTH = 3.0; // Mass spring system constexpr float VERLET_DAMPENING = 0.05; // [0, 1] -constexpr float BH_FORCE = 2.0; // Barnes-Hut [1.0, 3.0] -constexpr float THETA = 0.9; // Barnes-Hut [0.5, 1.0] +constexpr float BH_FORCE = 2.5; // Barnes-Hut [1.0, 3.0] +constexpr float THETA = 0.8; // Barnes-Hut [0.5, 1.0] constexpr float SOFTENING = 0.01; // Barnes-Hut [0.01, 1.0] // Graph Drawing diff --git a/src/gui.cpp b/src/gui.cpp index 273fa57..b07fbed 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -103,59 +103,59 @@ auto Gui::Init() const -> void { } auto Gui::ApplyColor(Style &style, Color color) const -> void { - style.base_color_normal = ColorToInt(Fade(color, 0.5)); + style.base_color_normal = ColorToInt(Fade(color, 0.8)); style.base_color_focused = ColorToInt(Fade(color, 0.3)); style.base_color_pressed = ColorToInt(Fade(color, 0.8)); - style.base_color_disabled = style.base_color_normal; + style.base_color_disabled = ColorToInt(Fade(color, 0.5)); style.border_color_normal = ColorToInt(Fade(color, 1.0)); style.border_color_focused = ColorToInt(Fade(color, 0.7)); style.border_color_pressed = ColorToInt(Fade(color, 1.0)); - style.border_color_disabled = style.base_color_normal; + style.border_color_disabled = ColorToInt(Fade(GRAY, 0.5)); - style.text_color_normal = ColorToInt(Fade(BLACK, 0.7)); - style.text_color_focused = ColorToInt(Fade(BLACK, 0.7)); - style.text_color_pressed = ColorToInt(Fade(BLACK, 0.7)); - style.text_color_disabled = style.text_color_normal; + style.text_color_normal = ColorToInt(Fade(BLACK, 1.0)); + style.text_color_focused = ColorToInt(Fade(BLACK, 1.0)); + style.text_color_pressed = ColorToInt(Fade(BLACK, 1.0)); + style.text_color_disabled = ColorToInt(Fade(BLACK, 0.5)); } auto Gui::ApplyBlockColor(Style &style, Color color) const -> void { style.base_color_normal = ColorToInt(Fade(color, 0.5)); style.base_color_focused = ColorToInt(Fade(color, 0.3)); style.base_color_pressed = ColorToInt(Fade(color, 0.8)); - style.base_color_disabled = style.base_color_normal; + style.base_color_disabled = ColorToInt(Fade(color, 0.5)); style.border_color_normal = ColorToInt(Fade(color, 1.0)); style.border_color_focused = ColorToInt(Fade(color, 0.7)); style.border_color_pressed = ColorToInt(Fade(color, 1.0)); - style.border_color_disabled = style.base_color_normal; + style.border_color_disabled = ColorToInt(Fade(GRAY, 0.5)); } auto Gui::ApplyTextColor(Style &style, Color color) const -> void { style.text_color_normal = ColorToInt(Fade(color, 1.0)); style.text_color_focused = ColorToInt(Fade(color, 1.0)); style.text_color_pressed = ColorToInt(Fade(color, 1.0)); - style.text_color_disabled = ColorToInt(Fade(BLACK, 0.7)); + style.text_color_disabled = ColorToInt(Fade(BLACK, 0.5)); } auto Gui::GetDefaultStyle() const -> DefaultStyle { // Could've iterated over the values but then it wouldn't be as nice to // access... - return {GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL), - GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL), - GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL), + return {{GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL), + GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL), + GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL), - GuiGetStyle(DEFAULT, BORDER_COLOR_FOCUSED), - GuiGetStyle(DEFAULT, BASE_COLOR_FOCUSED), - GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED), + GuiGetStyle(DEFAULT, BORDER_COLOR_FOCUSED), + GuiGetStyle(DEFAULT, BASE_COLOR_FOCUSED), + GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED), - GuiGetStyle(DEFAULT, BORDER_COLOR_PRESSED), - GuiGetStyle(DEFAULT, BASE_COLOR_PRESSED), - GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED), + GuiGetStyle(DEFAULT, BORDER_COLOR_PRESSED), + GuiGetStyle(DEFAULT, BASE_COLOR_PRESSED), + GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED), - GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED), - GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED), - GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED), + GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED), + GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED), + GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)}, GuiGetStyle(DEFAULT, BACKGROUND_COLOR), GuiGetStyle(DEFAULT, LINE_COLOR), @@ -195,21 +195,21 @@ auto Gui::SetDefaultStyle(const DefaultStyle &style) const -> void { } auto Gui::GetComponentStyle(int component) const -> ComponentStyle { - return {GuiGetStyle(component, BORDER_COLOR_NORMAL), - GuiGetStyle(component, BASE_COLOR_NORMAL), - GuiGetStyle(component, TEXT_COLOR_NORMAL), + return {{GuiGetStyle(component, BORDER_COLOR_NORMAL), + GuiGetStyle(component, BASE_COLOR_NORMAL), + GuiGetStyle(component, TEXT_COLOR_NORMAL), - GuiGetStyle(component, BORDER_COLOR_FOCUSED), - GuiGetStyle(component, BASE_COLOR_FOCUSED), - GuiGetStyle(component, TEXT_COLOR_FOCUSED), + GuiGetStyle(component, BORDER_COLOR_FOCUSED), + GuiGetStyle(component, BASE_COLOR_FOCUSED), + GuiGetStyle(component, TEXT_COLOR_FOCUSED), - GuiGetStyle(component, BORDER_COLOR_PRESSED), - GuiGetStyle(component, BASE_COLOR_PRESSED), - GuiGetStyle(component, TEXT_COLOR_PRESSED), + GuiGetStyle(component, BORDER_COLOR_PRESSED), + GuiGetStyle(component, BASE_COLOR_PRESSED), + GuiGetStyle(component, TEXT_COLOR_PRESSED), - GuiGetStyle(component, BORDER_COLOR_DISABLED), - GuiGetStyle(component, BASE_COLOR_DISABLED), - GuiGetStyle(component, TEXT_COLOR_DISABLED), + GuiGetStyle(component, BORDER_COLOR_DISABLED), + GuiGetStyle(component, BASE_COLOR_DISABLED), + GuiGetStyle(component, TEXT_COLOR_DISABLED)}, GuiGetStyle(component, BORDER_WIDTH), GuiGetStyle(component, TEXT_PADDING), @@ -453,7 +453,7 @@ auto Gui::DrawMenuHeader(Color color) const -> void { DrawMenuButton(1, 0, 1, 1, std::format("Puzzle: \"{}\"", state.comments.at(state.current_preset).substr(2)), - color, false); + color); int editing = input.editing; DrawMenuToggleSlider(2, 0, 1, 1, "Puzzle Mode (Tab)", "Edit Mode (Tab)", @@ -467,18 +467,18 @@ auto Gui::DrawGraphInfo(Color color) const -> void { DrawMenuButton(0, 1, 1, 1, std::format("Found {} States ({} Winning)", state.states.size(), state.winning_states.size()), - color, false); + color); DrawMenuButton(1, 1, 1, 1, std::format("Found {} Transitions", state.springs.size()), - color, false); + color); DrawMenuButton(2, 1, 1, 1, std::format("{} Moves to Nearest Solution", state.winning_path.size() > 0 ? state.winning_path.size() - 1 : 0), - color, false); + color); } auto Gui::DrawGraphControls(Color color) const -> void { @@ -545,21 +545,25 @@ auto Gui::DrawPuzzleControls(Color color) const -> void { DrawMenuButton(0, 4, 1, 1, std::format("{} Moves ({}{} Time at this State)", state.total_moves, visits, nth(visits)), - color, false); + color); - if (DrawMenuButton(1, 4, 1, 1, "Make Optimal Move (Space)", color)) { + if (DrawMenuButton(1, 4, 1, 1, "Make Optimal Move (Space)", color, + !state.target_distances.Empty())) { input.MakeOptimalMove(); } - if (DrawMenuButton(2, 4, 1, 1, "Undo Last Move (Backspace)", color)) { + if (DrawMenuButton(2, 4, 1, 1, "Undo Last Move (Backspace)", color, + state.history.size() > 0)) { input.UndoLastMove(); } - if (DrawMenuButton(0, 5, 1, 1, "Go to Nearest Solution (B)", color)) { + if (DrawMenuButton(0, 5, 1, 1, "Go to Nearest Solution (B)", color, + !state.target_distances.Empty())) { input.GoToNearestTarget(); } - if (DrawMenuButton(1, 5, 1, 1, "Go to Worst State (V)", color)) { + if (DrawMenuButton(1, 5, 1, 1, "Go to Worst State (V)", color, + !state.target_distances.Empty())) { input.GoToWorstState(); } @@ -611,8 +615,8 @@ auto Gui::DrawEditControls(Color color) const -> void { auto Gui::DrawMenuFooter(Color color) -> void { DrawMenuButton(0, 6, 2, 1, - std::format("State: \"{}\"", state.current_state.state), color, - false); + std::format("State: \"{}\"", state.current_state.state), + color); if (DrawMenuButton(2, 6, 1, 1, "Save as Preset", color)) { save_window = true; diff --git a/src/state.cpp b/src/state.cpp index 5ca7c5a..aa4e320 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -88,6 +88,7 @@ auto StateManager::ResetState() -> void { visits = 0; } visited_states[current_state]++; + history = std::stack(); total_moves = 0; if (edited || !states.contains(current_state)) { // We also need to clear the graph in case the state has been edited @@ -193,7 +194,7 @@ auto StateManager::ClearGraph() -> void { masses.clear(); winning_path.clear(); springs.clear(); - history = std::stack(); + // history = std::stack(); target_distances.Clear(); physics.ClearCmd();