diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-02 23:38:23 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-02 23:53:28 +0200 |
commit | 2869ef7cec7de6bc744cdba9e753dbd0df4ab65b (patch) | |
tree | 1d15c5679197b38d42cabb3e74143ef63a930d84 /include/gui | |
parent | 7c4af06d953ad439906f85ec996ad00dd38d2302 (diff) |
Add widgets for settings page, add list to auto position widgets
Diffstat (limited to 'include/gui')
-rw-r--r-- | include/gui/Button.hpp | 2 | ||||
-rw-r--r-- | include/gui/ComboBox.hpp | 2 | ||||
-rw-r--r-- | include/gui/DropdownButton.hpp | 2 | ||||
-rw-r--r-- | include/gui/Label.hpp | 2 | ||||
-rw-r--r-- | include/gui/List.hpp | 28 | ||||
-rw-r--r-- | include/gui/ScrollablePage.hpp | 2 | ||||
-rw-r--r-- | include/gui/StaticPage.hpp | 2 | ||||
-rw-r--r-- | include/gui/Widget.hpp | 9 |
8 files changed, 42 insertions, 7 deletions
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp index 88399ae..c9a933b 100644 --- a/include/gui/Button.hpp +++ b/include/gui/Button.hpp @@ -16,7 +16,7 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - mgl::vec2f get_size() const { return size; } + mgl::vec2f get_size() override { return size; } std::function<void()> on_click; private: diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index 05bd236..591901c 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -17,7 +17,7 @@ namespace gsr { void add_item(const std::string &text, const std::string &id); - mgl::vec2f get_size(); + mgl::vec2f get_size() override; private: void update_if_dirty(); private: diff --git a/include/gui/DropdownButton.hpp b/include/gui/DropdownButton.hpp index c967f58..306a327 100644 --- a/include/gui/DropdownButton.hpp +++ b/include/gui/DropdownButton.hpp @@ -22,7 +22,7 @@ namespace gsr { void set_activated(bool activated); - mgl::vec2f get_size(); + mgl::vec2f get_size() override; std::function<void(const std::string &id)> on_click; private: diff --git a/include/gui/Label.hpp b/include/gui/Label.hpp index a94ff96..3cb91de 100644 --- a/include/gui/Label.hpp +++ b/include/gui/Label.hpp @@ -16,7 +16,7 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - mgl::vec2f get_size(); + mgl::vec2f get_size() override; private: mgl::Text text; }; diff --git a/include/gui/List.hpp b/include/gui/List.hpp new file mode 100644 index 0000000..23bf5ea --- /dev/null +++ b/include/gui/List.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include "Widget.hpp" +#include <vector> +#include <memory> + +namespace gsr { + class List : public Widget { + public: + enum class Orientation { + VERTICAL, + HORIZONTAL + }; + + List(Orientation orientation); + List(const List&) = delete; + List& operator=(const List&) = delete; + + bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; + void draw(mgl::Window &window, mgl::vec2f offset) override; + + void add_widget(std::unique_ptr<Widget> widget); + mgl::vec2f get_size() override; + protected: + std::vector<std::unique_ptr<Widget>> widgets; + Orientation orientation; + }; +}
\ No newline at end of file diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 8fab62f..2ad3c92 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -12,7 +12,7 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - mgl::vec2f get_size() const { return size; } + mgl::vec2f get_size() override { return size; } private: float get_border_size(mgl::Window &window) const; private: diff --git a/include/gui/StaticPage.hpp b/include/gui/StaticPage.hpp index 4280684..8b64ba6 100644 --- a/include/gui/StaticPage.hpp +++ b/include/gui/StaticPage.hpp @@ -12,7 +12,7 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; - mgl::vec2f get_size() const { return size; } + mgl::vec2f get_size() override { return size; } private: mgl::vec2f size; }; diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index bd0d5d9..1d52033 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -11,6 +11,8 @@ namespace gsr { class Widget { friend class StaticPage; friend class ScrollablePage; + friend class List; + friend class Page; public: Widget(); Widget(const Widget&) = delete; @@ -23,8 +25,13 @@ namespace gsr { virtual void set_position(mgl::vec2f position); virtual mgl::vec2f get_position() const; + virtual mgl::vec2f get_size() = 0; + protected: + void set_widget_as_selected_in_parent(); + void remove_widget_as_selected_in_parent(); protected: mgl::vec2f position; - bool move_to_top = false; + Widget *parent_widget = nullptr; + Widget *selected_child_widget = nullptr; }; }
\ No newline at end of file |