From b709805cfac4d1fe1bfe28e497a3e48e224372a8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Aug 2024 20:32:59 +0200 Subject: Move settings ui to SettingsPage class, show different widgets for different settings page, show different widgets depending on combobox selections --- include/gui/ComboBox.hpp | 6 +++++- include/gui/RadioButton.hpp | 2 +- include/gui/ScrollablePage.hpp | 1 + include/gui/Widget.hpp | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) (limited to 'include/gui') diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index b4e7b78..ac9d02b 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -3,6 +3,8 @@ #include "Widget.hpp" #include #include + +#include #include #include @@ -17,9 +19,11 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; void add_item(const std::string &text, const std::string &id); - void set_selected_item(const std::string &id); + void set_selected_item(const std::string &id, bool trigger_event = true); mgl::vec2f get_size() override; + + std::function on_selection_changed; private: void update_if_dirty(); float get_dropdown_arrow_height() const; diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp index d4b1103..60f3e82 100644 --- a/include/gui/RadioButton.hpp +++ b/include/gui/RadioButton.hpp @@ -17,7 +17,7 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; void add_item(const std::string &text, const std::string &id); - void set_selected_item(const std::string &id); + void set_selected_item(const std::string &id, bool trigger_event = true); mgl::vec2f get_size() override; diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 9d4623b..60d719f 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -13,6 +13,7 @@ namespace gsr { void draw(mgl::Window &window, mgl::vec2f offset) override; mgl::vec2f get_size() override; + mgl::vec2f get_inner_size() override; void set_margins(float top, float bottom, float left, float right); private: diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 5b582da..498ca05 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -34,6 +34,8 @@ namespace gsr { virtual mgl::vec2f get_position() const; virtual mgl::vec2f get_size() = 0; + // This can be different from get_size, for example with ScrollablePage this excludes the margins + virtual mgl::vec2f get_inner_size() { return get_size(); } void set_horizontal_alignment(Alignment alignment); void set_vertical_alignment(Alignment alignment); -- cgit v1.2.3