diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-01 18:38:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-01 18:38:06 +0200 |
commit | 6624db873c91087bc1805b9d018c92c455b85190 (patch) | |
tree | 169010942015f1ff209cd56600f4de433c8792ef /include/gui | |
parent | 5d40409fc6e54af4c4dccdab11f03bce21c5a9a2 (diff) |
Move dropdown button text and icon code to dropdown button class
Diffstat (limited to 'include/gui')
-rw-r--r-- | include/gui/DropdownButton.hpp | 54 | ||||
-rw-r--r-- | include/gui/Utils.hpp | 13 |
2 files changed, 67 insertions, 0 deletions
diff --git a/include/gui/DropdownButton.hpp b/include/gui/DropdownButton.hpp new file mode 100644 index 0000000..bcf769c --- /dev/null +++ b/include/gui/DropdownButton.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include "Widget.hpp" +#include <string> +#include <functional> +#include <vector> +#include <mglpp/graphics/Text.hpp> +#include <mglpp/graphics/Sprite.hpp> + +namespace gsr { + class DropdownButton : public Widget { + public: + DropdownButton(mgl::Font *title_font, mgl::Font *description_font, const char *title, const char *description_activated, const char *description_deactivated, mgl::Texture *icon_texture, mgl::vec2f size); + DropdownButton(const DropdownButton&) = delete; + DropdownButton& operator=(const DropdownButton&) = delete; + + bool on_event(mgl::Event &event, mgl::Window &window) override; + void draw(mgl::Window &window) override; + + void add_item(const std::string &text, const std::string &id); + void set_item_label(const std::string &id, const std::string &new_label); + + void set_activated(bool activated); + + mgl::vec2f get_size(); + + std::function<void(const std::string &id)> on_click; + private: + void update_if_dirty(); + private: + struct Item { + mgl::Text text; + std::string id; + }; + + std::vector<Item> items; + mgl::Font *title_font; + mgl::Font *description_font; + mgl::vec2f size; + bool mouse_inside = false; + bool show_dropdown = false; + bool dirty = true; + mgl::vec2f max_size; + int mouse_inside_item = -1; + + mgl::Text title; + mgl::Text description; + mgl::Sprite icon_sprite; + + std::string description_activated; + std::string description_deactivated; + bool activated = false; + }; +}
\ No newline at end of file diff --git a/include/gui/Utils.hpp b/include/gui/Utils.hpp new file mode 100644 index 0000000..fe5ee49 --- /dev/null +++ b/include/gui/Utils.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include <mglpp/system/vec.hpp> +#include <mglpp/graphics/Color.hpp> + +namespace mgl { + class Window; +} + +namespace gsr { + // Inner border + void draw_rectangle_outline(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::Color color, float border_size); +}
\ No newline at end of file |