aboutsummaryrefslogtreecommitdiff
path: root/include/gui
diff options
context:
space:
mode:
Diffstat (limited to 'include/gui')
-rw-r--r--include/gui/Button.hpp13
-rw-r--r--include/gui/ComboBox.hpp4
-rw-r--r--include/gui/DropdownButton.hpp4
-rw-r--r--include/gui/Page.hpp16
-rw-r--r--include/gui/ScrollablePage.hpp21
-rw-r--r--include/gui/StaticPage.hpp15
-rw-r--r--include/gui/Widget.hpp7
7 files changed, 56 insertions, 24 deletions
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index 972e5c9..88399ae 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -1,25 +1,28 @@
#pragma once
#include "Widget.hpp"
-#include <string>
#include <functional>
+#include <mglpp/graphics/Color.hpp>
+#include <mglpp/graphics/Text.hpp>
+
namespace gsr {
class Button : public Widget {
public:
- Button(mgl::vec2f size);
+ Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color);
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;
+ 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() const { return size; }
std::function<void()> on_click;
private:
mgl::vec2f size;
+ mgl::Color bg_color;
bool mouse_inside = false;
- bool pressed_inside = false;
+ mgl::Text text;
};
} \ No newline at end of file
diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp
index 5c899a7..05bd236 100644
--- a/include/gui/ComboBox.hpp
+++ b/include/gui/ComboBox.hpp
@@ -12,8 +12,8 @@ namespace gsr {
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;
+ 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);
diff --git a/include/gui/DropdownButton.hpp b/include/gui/DropdownButton.hpp
index bcf769c..c967f58 100644
--- a/include/gui/DropdownButton.hpp
+++ b/include/gui/DropdownButton.hpp
@@ -14,8 +14,8 @@ namespace gsr {
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;
+ 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_item_label(const std::string &id, const std::string &new_label);
diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp
index 1435e68..a5cfaf9 100644
--- a/include/gui/Page.hpp
+++ b/include/gui/Page.hpp
@@ -1,27 +1,19 @@
#pragma once
+#include "Widget.hpp"
#include <vector>
#include <memory>
-namespace mgl {
- class Event;
- class Window;
-}
-
namespace gsr {
- class Widget;
-
- class Page {
+ class Page : public Widget {
public:
Page() = default;
Page(const Page&) = delete;
Page& operator=(const Page&) = delete;
+ virtual ~Page() = default;
void add_widget(std::unique_ptr<Widget> widget);
-
- void on_event(mgl::Event &event, mgl::Window &window);
- void draw(mgl::Window &window);
- private:
+ protected:
std::vector<std::unique_ptr<Widget>> widgets;
};
} \ No newline at end of file
diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp
new file mode 100644
index 0000000..8fab62f
--- /dev/null
+++ b/include/gui/ScrollablePage.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "Page.hpp"
+
+namespace gsr {
+ class ScrollablePage : public Page {
+ public:
+ ScrollablePage(mgl::vec2f size);
+ ScrollablePage(const ScrollablePage&) = delete;
+ ScrollablePage& operator=(const ScrollablePage&) = delete;
+
+ 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() const { return size; }
+ private:
+ float get_border_size(mgl::Window &window) const;
+ private:
+ mgl::vec2f size;
+ };
+} \ No newline at end of file
diff --git a/include/gui/StaticPage.hpp b/include/gui/StaticPage.hpp
new file mode 100644
index 0000000..cc15531
--- /dev/null
+++ b/include/gui/StaticPage.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "Page.hpp"
+
+namespace gsr {
+ class StaticPage : public Page {
+ public:
+ StaticPage() = default;
+ StaticPage(const StaticPage&) = delete;
+ StaticPage& operator=(const StaticPage&) = delete;
+
+ bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
+ void draw(mgl::Window &window, mgl::vec2f offset) override;
+ };
+} \ No newline at end of file
diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp
index 6324490..bd0d5d9 100644
--- a/include/gui/Widget.hpp
+++ b/include/gui/Widget.hpp
@@ -9,7 +9,8 @@ namespace mgl {
namespace gsr {
class Widget {
- friend class Page;
+ friend class StaticPage;
+ friend class ScrollablePage;
public:
Widget();
Widget(const Widget&) = delete;
@@ -17,8 +18,8 @@ namespace gsr {
virtual ~Widget();
// 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 bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) = 0;
+ virtual void draw(mgl::Window &window, mgl::vec2f offset) = 0;
virtual void set_position(mgl::vec2f position);
virtual mgl::vec2f get_position() const;