improve gui elements styling when disabled

This commit is contained in:
2026-02-27 14:27:33 +01:00
parent b01cfdecfe
commit 3f71603961
3 changed files with 53 additions and 48 deletions

View File

@ -46,8 +46,8 @@ constexpr float SPRING_CONSTANT = 5.0; // Mass spring system
constexpr float DAMPENING_CONSTANT = 1.0; // Mass spring system constexpr float DAMPENING_CONSTANT = 1.0; // Mass spring system
constexpr float REST_LENGTH = 3.0; // Mass spring system constexpr float REST_LENGTH = 3.0; // Mass spring system
constexpr float VERLET_DAMPENING = 0.05; // [0, 1] constexpr float VERLET_DAMPENING = 0.05; // [0, 1]
constexpr float BH_FORCE = 2.0; // Barnes-Hut [1.0, 3.0] constexpr float BH_FORCE = 2.5; // Barnes-Hut [1.0, 3.0]
constexpr float THETA = 0.9; // Barnes-Hut [0.5, 1.0] constexpr float THETA = 0.8; // Barnes-Hut [0.5, 1.0]
constexpr float SOFTENING = 0.01; // Barnes-Hut [0.01, 1.0] constexpr float SOFTENING = 0.01; // Barnes-Hut [0.01, 1.0]
// Graph Drawing // Graph Drawing

View File

@ -103,59 +103,59 @@ auto Gui::Init() const -> void {
} }
auto Gui::ApplyColor(Style &style, Color color) 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_focused = ColorToInt(Fade(color, 0.3));
style.base_color_pressed = ColorToInt(Fade(color, 0.8)); 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_normal = ColorToInt(Fade(color, 1.0));
style.border_color_focused = ColorToInt(Fade(color, 0.7)); style.border_color_focused = ColorToInt(Fade(color, 0.7));
style.border_color_pressed = ColorToInt(Fade(color, 1.0)); 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_normal = ColorToInt(Fade(BLACK, 1.0));
style.text_color_focused = ColorToInt(Fade(BLACK, 0.7)); style.text_color_focused = ColorToInt(Fade(BLACK, 1.0));
style.text_color_pressed = ColorToInt(Fade(BLACK, 0.7)); style.text_color_pressed = ColorToInt(Fade(BLACK, 1.0));
style.text_color_disabled = style.text_color_normal; style.text_color_disabled = ColorToInt(Fade(BLACK, 0.5));
} }
auto Gui::ApplyBlockColor(Style &style, Color color) const -> void { auto Gui::ApplyBlockColor(Style &style, Color color) const -> void {
style.base_color_normal = ColorToInt(Fade(color, 0.5)); style.base_color_normal = ColorToInt(Fade(color, 0.5));
style.base_color_focused = ColorToInt(Fade(color, 0.3)); style.base_color_focused = ColorToInt(Fade(color, 0.3));
style.base_color_pressed = ColorToInt(Fade(color, 0.8)); 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_normal = ColorToInt(Fade(color, 1.0));
style.border_color_focused = ColorToInt(Fade(color, 0.7)); style.border_color_focused = ColorToInt(Fade(color, 0.7));
style.border_color_pressed = ColorToInt(Fade(color, 1.0)); 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 { auto Gui::ApplyTextColor(Style &style, Color color) const -> void {
style.text_color_normal = ColorToInt(Fade(color, 1.0)); style.text_color_normal = ColorToInt(Fade(color, 1.0));
style.text_color_focused = 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_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 { auto Gui::GetDefaultStyle() const -> DefaultStyle {
// Could've iterated over the values but then it wouldn't be as nice to // Could've iterated over the values but then it wouldn't be as nice to
// access... // access...
return {GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL), return {{GuiGetStyle(DEFAULT, BORDER_COLOR_NORMAL),
GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL), GuiGetStyle(DEFAULT, BASE_COLOR_NORMAL),
GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL), GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL),
GuiGetStyle(DEFAULT, BORDER_COLOR_FOCUSED), GuiGetStyle(DEFAULT, BORDER_COLOR_FOCUSED),
GuiGetStyle(DEFAULT, BASE_COLOR_FOCUSED), GuiGetStyle(DEFAULT, BASE_COLOR_FOCUSED),
GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED), GuiGetStyle(DEFAULT, TEXT_COLOR_FOCUSED),
GuiGetStyle(DEFAULT, BORDER_COLOR_PRESSED), GuiGetStyle(DEFAULT, BORDER_COLOR_PRESSED),
GuiGetStyle(DEFAULT, BASE_COLOR_PRESSED), GuiGetStyle(DEFAULT, BASE_COLOR_PRESSED),
GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED), GuiGetStyle(DEFAULT, TEXT_COLOR_PRESSED),
GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED), GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED),
GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED), GuiGetStyle(DEFAULT, BASE_COLOR_DISABLED),
GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED), GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED)},
GuiGetStyle(DEFAULT, BACKGROUND_COLOR), GuiGetStyle(DEFAULT, BACKGROUND_COLOR),
GuiGetStyle(DEFAULT, LINE_COLOR), GuiGetStyle(DEFAULT, LINE_COLOR),
@ -195,21 +195,21 @@ auto Gui::SetDefaultStyle(const DefaultStyle &style) const -> void {
} }
auto Gui::GetComponentStyle(int component) const -> ComponentStyle { auto Gui::GetComponentStyle(int component) const -> ComponentStyle {
return {GuiGetStyle(component, BORDER_COLOR_NORMAL), return {{GuiGetStyle(component, BORDER_COLOR_NORMAL),
GuiGetStyle(component, BASE_COLOR_NORMAL), GuiGetStyle(component, BASE_COLOR_NORMAL),
GuiGetStyle(component, TEXT_COLOR_NORMAL), GuiGetStyle(component, TEXT_COLOR_NORMAL),
GuiGetStyle(component, BORDER_COLOR_FOCUSED), GuiGetStyle(component, BORDER_COLOR_FOCUSED),
GuiGetStyle(component, BASE_COLOR_FOCUSED), GuiGetStyle(component, BASE_COLOR_FOCUSED),
GuiGetStyle(component, TEXT_COLOR_FOCUSED), GuiGetStyle(component, TEXT_COLOR_FOCUSED),
GuiGetStyle(component, BORDER_COLOR_PRESSED), GuiGetStyle(component, BORDER_COLOR_PRESSED),
GuiGetStyle(component, BASE_COLOR_PRESSED), GuiGetStyle(component, BASE_COLOR_PRESSED),
GuiGetStyle(component, TEXT_COLOR_PRESSED), GuiGetStyle(component, TEXT_COLOR_PRESSED),
GuiGetStyle(component, BORDER_COLOR_DISABLED), GuiGetStyle(component, BORDER_COLOR_DISABLED),
GuiGetStyle(component, BASE_COLOR_DISABLED), GuiGetStyle(component, BASE_COLOR_DISABLED),
GuiGetStyle(component, TEXT_COLOR_DISABLED), GuiGetStyle(component, TEXT_COLOR_DISABLED)},
GuiGetStyle(component, BORDER_WIDTH), GuiGetStyle(component, BORDER_WIDTH),
GuiGetStyle(component, TEXT_PADDING), GuiGetStyle(component, TEXT_PADDING),
@ -453,7 +453,7 @@ auto Gui::DrawMenuHeader(Color color) const -> void {
DrawMenuButton(1, 0, 1, 1, DrawMenuButton(1, 0, 1, 1,
std::format("Puzzle: \"{}\"", std::format("Puzzle: \"{}\"",
state.comments.at(state.current_preset).substr(2)), state.comments.at(state.current_preset).substr(2)),
color, false); color);
int editing = input.editing; int editing = input.editing;
DrawMenuToggleSlider(2, 0, 1, 1, "Puzzle Mode (Tab)", "Edit Mode (Tab)", 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, DrawMenuButton(0, 1, 1, 1,
std::format("Found {} States ({} Winning)", std::format("Found {} States ({} Winning)",
state.states.size(), state.winning_states.size()), state.states.size(), state.winning_states.size()),
color, false); color);
DrawMenuButton(1, 1, 1, 1, DrawMenuButton(1, 1, 1, 1,
std::format("Found {} Transitions", state.springs.size()), std::format("Found {} Transitions", state.springs.size()),
color, false); color);
DrawMenuButton(2, 1, 1, 1, DrawMenuButton(2, 1, 1, 1,
std::format("{} Moves to Nearest Solution", std::format("{} Moves to Nearest Solution",
state.winning_path.size() > 0 state.winning_path.size() > 0
? state.winning_path.size() - 1 ? state.winning_path.size() - 1
: 0), : 0),
color, false); color);
} }
auto Gui::DrawGraphControls(Color color) const -> void { auto Gui::DrawGraphControls(Color color) const -> void {
@ -545,21 +545,25 @@ auto Gui::DrawPuzzleControls(Color color) const -> void {
DrawMenuButton(0, 4, 1, 1, DrawMenuButton(0, 4, 1, 1,
std::format("{} Moves ({}{} Time at this State)", std::format("{} Moves ({}{} Time at this State)",
state.total_moves, visits, nth(visits)), 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(); 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(); 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(); 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(); input.GoToWorstState();
} }
@ -611,8 +615,8 @@ auto Gui::DrawEditControls(Color color) const -> void {
auto Gui::DrawMenuFooter(Color color) -> void { auto Gui::DrawMenuFooter(Color color) -> void {
DrawMenuButton(0, 6, 2, 1, DrawMenuButton(0, 6, 2, 1,
std::format("State: \"{}\"", state.current_state.state), color, std::format("State: \"{}\"", state.current_state.state),
false); color);
if (DrawMenuButton(2, 6, 1, 1, "Save as Preset", color)) { if (DrawMenuButton(2, 6, 1, 1, "Save as Preset", color)) {
save_window = true; save_window = true;

View File

@ -88,6 +88,7 @@ auto StateManager::ResetState() -> void {
visits = 0; visits = 0;
} }
visited_states[current_state]++; visited_states[current_state]++;
history = std::stack<State>();
total_moves = 0; total_moves = 0;
if (edited || !states.contains(current_state)) { if (edited || !states.contains(current_state)) {
// We also need to clear the graph in case the state has been edited // We also need to clear the graph in case the state has been edited
@ -193,7 +194,7 @@ auto StateManager::ClearGraph() -> void {
masses.clear(); masses.clear();
winning_path.clear(); winning_path.clear();
springs.clear(); springs.clear();
history = std::stack<State>(); // history = std::stack<State>();
target_distances.Clear(); target_distances.Clear();
physics.ClearCmd(); physics.ClearCmd();