aboutsummaryrefslogtreecommitdiff
path: root/include/gui
diff options
context:
space:
mode:
Diffstat (limited to 'include/gui')
-rw-r--r--include/gui/Button.hpp7
-rw-r--r--include/gui/ComboBox.hpp36
-rw-r--r--include/gui/Widget.hpp12
-rw-r--r--include/gui/WidgetContainer.hpp30
4 files changed, 82 insertions, 3 deletions
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index 84098b2..972e5c9 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -8,9 +8,14 @@ namespace gsr {
class Button : public Widget {
public:
Button(mgl::vec2f size);
- void on_event(mgl::Event &event, mgl::Window &window) override;
+ Button(const Button&) = delete;
+ Button& operator=(const Button&) = delete;
+
+ bool on_event(mgl::Event &event, mgl::Window &window) override;
void draw(mgl::Window &window) override;
+ mgl::vec2f get_size() const { return size; }
+
std::function<void()> on_click;
private:
mgl::vec2f size;
diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp
new file mode 100644
index 0000000..5c899a7
--- /dev/null
+++ b/include/gui/ComboBox.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Widget.hpp"
+#include <mglpp/graphics/Text.hpp>
+#include <string>
+#include <vector>
+
+namespace gsr {
+ class ComboBox : public Widget {
+ public:
+ ComboBox(mgl::Font *font);
+ ComboBox(const ComboBox&) = delete;
+ ComboBox& operator=(const ComboBox&) = 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);
+
+ mgl::vec2f get_size();
+ private:
+ void update_if_dirty();
+ private:
+ struct Item {
+ mgl::Text text;
+ std::string id;
+ };
+
+ mgl::vec2f max_size;
+ mgl::Font *font;
+ std::vector<Item> items;
+ bool dirty = true;
+ bool show_dropdown = false;
+ size_t selected_item = 0;
+ };
+} \ No newline at end of file
diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp
index cf81d69..81f47b5 100644
--- a/include/gui/Widget.hpp
+++ b/include/gui/Widget.hpp
@@ -9,13 +9,21 @@ namespace mgl {
namespace gsr {
class Widget {
+ friend class WidgetContainer;
public:
- virtual ~Widget() = default;
+ Widget();
+ Widget(const Widget&) = delete;
+ Widget& operator=(const Widget&) = delete;
+ virtual ~Widget();
- virtual void on_event(mgl::Event &event, mgl::Window &window) = 0;
+ // Return true to allow other widgets to also process the event
+ virtual bool on_event(mgl::Event &event, mgl::Window &window) = 0;
virtual void draw(mgl::Window &window) = 0;
virtual void set_position(mgl::vec2f position);
+
+ virtual mgl::vec2f get_position() const;
protected:
mgl::vec2f position;
+ bool move_to_top = false;
};
} \ No newline at end of file
diff --git a/include/gui/WidgetContainer.hpp b/include/gui/WidgetContainer.hpp
new file mode 100644
index 0000000..e40ffb9
--- /dev/null
+++ b/include/gui/WidgetContainer.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <vector>
+#include <memory>
+
+namespace mgl {
+ class Event;
+ class Window;
+}
+
+namespace gsr {
+ class Widget;
+
+ class WidgetContainer {
+ public:
+ static WidgetContainer& get_instance();
+
+ void add_widget(Widget *widget);
+ void remove_widget(Widget *widget);
+
+ void on_event(mgl::Event &event, mgl::Window &window);
+ void draw(mgl::Window &window);
+ private:
+ WidgetContainer() = default;
+ WidgetContainer& operator=(const WidgetContainer&) = delete;
+ WidgetContainer(const WidgetContainer&) = delete;
+ private:
+ std::vector<Widget*> widgets;
+ };
+} \ No newline at end of file