From b778fd7cc654f28a2bfe0ff74537f120241b289c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2024 03:11:43 +0200 Subject: Change fonts, nicer combobox, add/remove audio track button --- include/gui/Button.hpp | 4 +++- include/gui/ComboBox.hpp | 3 +++ include/gui/List.hpp | 9 +++++++++ include/gui/Page.hpp | 2 ++ include/gui/Widget.hpp | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-) (limited to 'include/gui') diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp index c9a933b..0a07423 100644 --- a/include/gui/Button.hpp +++ b/include/gui/Button.hpp @@ -9,6 +9,8 @@ namespace gsr { class Button : public Widget { public: + // If width is 0 then the width of the text is used instead (with padding). + // If height is 0 then the height of the text is used instead (with padding). Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color); Button(const Button&) = delete; Button& operator=(const Button&) = delete; @@ -16,7 +18,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; std::function on_click; private: diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp index 70a79a7..b4e7b78 100644 --- a/include/gui/ComboBox.hpp +++ b/include/gui/ComboBox.hpp @@ -2,6 +2,7 @@ #include "Widget.hpp" #include +#include #include #include @@ -21,6 +22,7 @@ namespace gsr { mgl::vec2f get_size() override; private: void update_if_dirty(); + float get_dropdown_arrow_height() const; private: struct Item { mgl::Text text; @@ -30,6 +32,7 @@ namespace gsr { mgl::vec2f max_size; mgl::Font *font; std::vector items; + mgl::Sprite dropdown_arrow; bool dirty = true; bool show_dropdown = false; size_t selected_item = 0; diff --git a/include/gui/List.hpp b/include/gui/List.hpp index 8c4e1fc..0b1350c 100644 --- a/include/gui/List.hpp +++ b/include/gui/List.hpp @@ -25,10 +25,19 @@ namespace gsr { bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override; void draw(mgl::Window &window, mgl::vec2f offset) override; + //void remove_child_widget(Widget *widget) override; + void add_widget(std::unique_ptr widget); + void remove_widget(Widget *widget); + mgl::vec2f get_size() override; + private: + void update(); + void remove_widget_immediate(Widget *widget); protected: std::vector> widgets; + std::vector> add_queue; + std::vector remove_queue; Orientation orientation; Alignment content_alignment; }; diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp index a5cfaf9..47aa02b 100644 --- a/include/gui/Page.hpp +++ b/include/gui/Page.hpp @@ -12,6 +12,8 @@ namespace gsr { Page& operator=(const Page&) = delete; virtual ~Page() = default; + //void remove_child_widget(Widget *widget) override; + void add_widget(std::unique_ptr widget); protected: std::vector> widgets; diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp index 1d52033..6c4a1cb 100644 --- a/include/gui/Widget.hpp +++ b/include/gui/Widget.hpp @@ -24,6 +24,8 @@ namespace gsr { virtual void draw(mgl::Window &window, mgl::vec2f offset) = 0; virtual void set_position(mgl::vec2f position); + //virtual void remove_child_widget(Widget *widget) { (void)widget; } + virtual mgl::vec2f get_position() const; virtual mgl::vec2f get_size() = 0; protected: -- cgit v1.2.3