aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-07 00:21:32 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-07 00:21:35 +0200
commita3e479d5b289166ff651fac4ff046656cf78cda0 (patch)
tree2ba345228acfe45acf9863bb122e163ed38db7db /include
parentb229b060add5f66bd5532698c4a790285095e98a (diff)
Add radio button with simple/advanced view, add widget visibility
Diffstat (limited to 'include')
-rw-r--r--include/gui/RadioButton.hpp39
-rw-r--r--include/gui/ScrollablePage.hpp10
-rw-r--r--include/gui/StaticPage.hpp2
-rw-r--r--include/gui/Widget.hpp20
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