diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-07 00:21:32 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-07 00:21:35 +0200 |
commit | a3e479d5b289166ff651fac4ff046656cf78cda0 (patch) | |
tree | 2ba345228acfe45acf9863bb122e163ed38db7db /include/gui/RadioButton.hpp | |
parent | b229b060add5f66bd5532698c4a790285095e98a (diff) |
Add radio button with simple/advanced view, add widget visibility
Diffstat (limited to 'include/gui/RadioButton.hpp')
-rw-r--r-- | include/gui/RadioButton.hpp | 39 |
1 files changed, 39 insertions, 0 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 |