diff options
Diffstat (limited to 'include/gui')
-rw-r--r-- | include/gui/RadioButton.hpp | 39 | ||||
-rw-r--r-- | include/gui/ScrollablePage.hpp | 10 | ||||
-rw-r--r-- | include/gui/StaticPage.hpp | 2 | ||||
-rw-r--r-- | include/gui/Widget.hpp | 20 |
4 files changed, 68 insertions, 3 deletions
diff --git a/include/gui/RadioButton.hpp b/include/gui/RadioButton.hpp new file mode 100644 index 0000000..d4b1103 --- /dev/null +++ b/include/gui/RadioButton.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "Widget.hpp" + +#include <mglpp/graphics/Text.hpp> +#include <vector> +#include <functional> + +namespace gsr { + class RadioButton : public Widget { + public: + RadioButton(mgl::Font *font); + RadioButton(const RadioButton&) = delete; + RadioButton& operator=(const RadioButton&) = 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_item(const std::string &text, const std::string &id); + void set_selected_item(const std::string &id); + + mgl::vec2f get_size() override; + + std::function<void(const std::string &text, const std::string &id)> on_selection_changed; + private: + void update_if_dirty(); + private: + struct Item { + mgl::Text text; + std::string id; + }; + + mgl::Font *font; + std::vector<Item> items; + size_t selected_item = 0; + bool dirty = true; + mgl::vec2f size; + }; +}
\ No newline at end of file diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 2ad3c92..9d4623b 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -12,10 +12,16 @@ 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() override { return size; } + mgl::vec2f get_size() override; + + void set_margins(float top, float bottom, float left, float right); private: - float get_border_size(mgl::Window &window) const; + float get_border_size() const; private: mgl::vec2f size; + float margin_top_scale = 0.0f; + float margin_bottom_scale = 0.0f; + float margin_left_scale = 0.0f; + float margin_right_scale = 0.0f; }; }
\ No newline at end of file diff --git a/include/gui/StaticPage.hpp b/include/gui/StaticPage.hpp index 8b64ba6..e73083c 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() override { return size; } + mgl::vec2f get_size() override; private: mgl::vec2f size; }; diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 6c4a1cb..7a04338 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -14,6 +14,12 @@ namespace gsr { friend class List; friend class Page; public: + enum class Alignment { + START, + CENTER, + END + }; + Widget(); Widget(const Widget&) = delete; Widget& operator=(const Widget&) = delete; @@ -28,12 +34,26 @@ namespace gsr { virtual mgl::vec2f get_position() const; virtual mgl::vec2f get_size() = 0; + + void set_horizontal_alignment(Alignment alignment); + void set_vertical_alignment(Alignment alignment); + + Alignment get_horizontal_alignment() const; + Alignment get_vertical_alignment() const; + + void set_visible(bool visible); protected: void set_widget_as_selected_in_parent(); void remove_widget_as_selected_in_parent(); + bool has_parent_with_selected_child_widget() const; protected: mgl::vec2f position; Widget *parent_widget = nullptr; Widget *selected_child_widget = nullptr; + + Alignment horizontal_aligment; + Alignment vertical_aligment; + + bool visible = true; }; }
\ No newline at end of file |