aboutsummaryrefslogtreecommitdiff
path: root/include/mgui
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-12-02 14:20:48 +0100
committerdec05eba <dec05eba@protonmail.com>2021-12-02 14:29:13 +0100
commit14770f42df291753a240def91fb488a904a909c1 (patch)
treec1ef52c408cb365890da4aeb5536256040bb96fd /include/mgui
Initial commit, set up skeleton with list and button
Diffstat (limited to 'include/mgui')
-rw-r--r--include/mgui/button.h22
-rw-r--r--include/mgui/list.h33
-rw-r--r--include/mgui/widget.h33
3 files changed, 88 insertions, 0 deletions
diff --git a/include/mgui/button.h b/include/mgui/button.h
new file mode 100644
index 0000000..8f9a2db
--- /dev/null
+++ b/include/mgui/button.h
@@ -0,0 +1,22 @@
+#ifndef MGUI_BUTTON_H
+#define MGUI_BUTTON_H
+
+#include <mgl/graphics/rectangle.h>
+#include <mgl/graphics/text.h>
+#include "widget.h"
+
+typedef struct {
+ mgui_widget widget;
+ mgl_rectangle background;
+ mgl_text label;
+} mgui_button;
+
+mgui_button* mgui_button_create();
+mgui_widget* mgui_button_to_widget(mgui_button *list);
+mgui_button* mgui_widget_to_button(mgui_widget *widget);
+
+void mgui_button_set_position(mgui_button *self, mgl_vec2i position);
+void mgui_button_on_event(mgui_button *self, mgl_window *window, mgl_event *event);
+void mgui_button_draw(mgui_button *self, mgl_window *window);
+
+#endif /* MGUI_BUTTON_H */
diff --git a/include/mgui/list.h b/include/mgui/list.h
new file mode 100644
index 0000000..1da326d
--- /dev/null
+++ b/include/mgui/list.h
@@ -0,0 +1,33 @@
+#ifndef MGUI_LIST_H
+#define MGUI_LIST_H
+
+#include "widget.h"
+#include <stddef.h>
+
+typedef struct mgl_window mgl_window;
+typedef struct mgl_event mgl_event;
+
+typedef enum {
+ MGUI_LIST_HORIZONITAL,
+ MGUI_LIST_VERTICAL
+} mgui_list_direction;
+
+typedef struct {
+ mgui_widget widget;
+ mgui_list_direction direction;
+ mgl_vec2i position;
+ mgui_widget **items;
+ size_t num_items;
+ size_t items_capacity;
+} mgui_list;
+
+mgui_list* mgui_list_create(mgui_list_direction direction);
+mgui_widget* mgui_list_to_widget(mgui_list *list);
+mgui_list* mgui_widget_to_list(mgui_widget *widget);
+
+void mgui_list_set_position(mgui_list *self, mgl_vec2i position);
+void mgui_list_append(mgui_list *self, mgui_widget *widget);
+void mgui_list_on_event(mgui_list *self, mgl_window *window, mgl_event *event);
+void mgui_list_draw(mgui_list *self, mgl_window *window);
+
+#endif /* MGUI_LIST_H */
diff --git a/include/mgui/widget.h b/include/mgui/widget.h
new file mode 100644
index 0000000..60f850c
--- /dev/null
+++ b/include/mgui/widget.h
@@ -0,0 +1,33 @@
+#ifndef MGUI_WIDGET_H
+#define MGUI_WIDGET_H
+
+#include <mgl/system/vec.h>
+
+typedef struct mgl_window mgl_window;
+typedef struct mgl_event mgl_event;
+typedef struct mgui_widget mgui_widget;
+
+typedef enum {
+ MGUI_WIDGET_LIST,
+ MGUI_WIDGET_BUTTON
+} mgui_widget_type;
+
+typedef struct {
+ int left;
+ int top;
+ int right;
+ int bottom;
+} mgui_margin;
+
+struct mgui_widget {
+ mgui_widget_type type;
+ mgui_margin margin;
+};
+
+void mgui_widget_init(mgui_widget *self, mgui_widget_type type);
+void mgui_widget_set_margin(mgui_widget *self, int left, int top, int right, int bottom);
+void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position);
+void mgui_widget_on_event(mgui_widget *self, mgl_window *window, mgl_event *event);
+void mgui_widget_draw(mgui_widget *self, mgl_window *window);
+
+#endif /* MGUI_WIDGET_H */