From 4ea5ada9050d22fcb7eed67a72358bce11c9b3df Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 10 Aug 2024 00:45:36 +0200 Subject: Settings page save settings, refactor --- include/gui/ComboBox.hpp | 1 + include/gui/Entry.hpp | 3 +- include/gui/List.hpp | 7 +++ include/gui/Page.hpp | 3 + include/gui/RadioButton.hpp | 1 + include/gui/SettingsPage.hpp | 128 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 include/gui/SettingsPage.hpp (limited to 'include/gui') diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index ac9d02b..e501132 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -20,6 +20,7 @@ namespace gsr { void add_item(const std::string &text, const std::string &id); void set_selected_item(const std::string &id, bool trigger_event = true); + const std::string& get_selected_id() const; mgl::vec2f get_size() override; diff --git a/include/gui/Entry.hpp b/include/gui/Entry.hpp index c2d59ac..b8ff37a 100644 --- a/include/gui/Entry.hpp +++ b/include/gui/Entry.hpp @@ -20,7 +20,8 @@ namespace gsr { mgl::vec2f get_size() override; - void set_string(std::string str); + void set_text(std::string str); + const std::string& get_text() const; // Return false to specify that the string should not be accepted. This reverts the string back to its previous value. // The input can be changed by changing the input parameter and returning true. diff --git a/include/gui/List.hpp b/include/gui/List.hpp index 0b1350c..426a66e 100644 --- a/include/gui/List.hpp +++ b/include/gui/List.hpp @@ -27,8 +27,14 @@ namespace gsr { //void remove_child_widget(Widget *widget) override; + // Might not take effect immediately but at the next draw iteration if inside an event loop void add_widget(std::unique_ptr widget); + // Might not take effect immediately but at the next draw iteration if inside an event loop void remove_widget(Widget *widget); + // Excludes widgets from queue + const std::vector>& get_child_widgets() const; + // Returns nullptr if index is invalid + Widget* get_child_widget_by_index(size_t index) const; mgl::vec2f get_size() override; private: @@ -40,5 +46,6 @@ namespace gsr { std::vector remove_queue; Orientation orientation; Alignment content_alignment; + bool inside_event_handler = false; }; } \ No newline at end of file diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp index 47aa02b..4c63702 100644 --- a/include/gui/Page.hpp +++ b/include/gui/Page.hpp @@ -12,6 +12,9 @@ namespace gsr { Page& operator=(const Page&) = delete; virtual ~Page() = default; + virtual void on_navigate_to_page() {} + virtual void on_navigate_away_from_page() {} + //void remove_child_widget(Widget *widget) override; void add_widget(std::unique_ptr widget); diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp index 60f3e82..7839c68 100644 --- a/include/gui/RadioButton.hpp +++ b/include/gui/RadioButton.hpp @@ -18,6 +18,7 @@ namespace gsr { void add_item(const std::string &text, const std::string &id); void set_selected_item(const std::string &id, bool trigger_event = true); + const std::string get_selected_id() const; mgl::vec2f get_size() override; diff --git a/include/gui/SettingsPage.hpp b/include/gui/SettingsPage.hpp new file mode 100644 index 0000000..28689a1 --- /dev/null +++ b/include/gui/SettingsPage.hpp @@ -0,0 +1,128 @@ +#pragma once + +#include "StaticPage.hpp" +#include "List.hpp" +#include "ComboBox.hpp" +#include "Entry.hpp" +#include "RadioButton.hpp" +#include "CheckBox.hpp" +#include "Button.hpp" +#include "CustomRendererWidget.hpp" +#include "../GsrInfo.hpp" +#include "../Config.hpp" + +#include + +namespace gsr { + class ScrollablePage; + + class SettingsPage : public StaticPage { + public: + enum class Type { + REPLAY, + RECORD, + STREAM + }; + + SettingsPage(Type type, const GsrInfo &gsr_info, const std::vector &audio_devices, std::optional &config); + SettingsPage(const SettingsPage&) = delete; + SettingsPage& operator=(const SettingsPage&) = delete; + + void save(); + void on_navigate_away_from_page() override; + + std::function on_back_button_handler; + private: + std::unique_ptr