From 0417619b36dc7f4b004caa64a65570f1344d1c8d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 14 Dec 2021 23:48:34 +0100 Subject: Layout, expand, etc --- include/mgui/widget.h | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'include/mgui/widget.h') diff --git a/include/mgui/widget.h b/include/mgui/widget.h index 679e4ad..d425c11 100644 --- a/include/mgui/widget.h +++ b/include/mgui/widget.h @@ -2,6 +2,8 @@ #define MGUI_WIDGET_H #include +#include +#include typedef struct mgl_window mgl_window; typedef struct mgl_event mgl_event; @@ -16,27 +18,55 @@ typedef enum { MGUI_WIDGET_IMAGE } mgui_widget_type; +typedef enum { + MGUI_WIDGET_ALIGN_TOP_LEFT, + MGUI_WIDGET_ALIGN_TOP_CENTER, + MGUI_WIDGET_ALIGN_TOP_RIGHT, + + MGUI_WIDGET_ALIGN_CENTER_LEFT, + MGUI_WIDGET_ALIGN_CENTER_CENTER, + MGUI_WIDGET_ALIGN_CENTER_RIGHT, + + MGUI_WIDGET_ALIGN_BOTTOM_LEFT, + MGUI_WIDGET_ALIGN_BOTTOM_CENTER, + MGUI_WIDGET_ALIGN_BOTTOM_RIGHT, +} mgui_alignment; + +typedef enum { + MGUI_WIDGET_VISIBLE = 1 << 0, + MGUI_WIDGET_EXPAND_HORIZONTAL = 1 << 1, + MGUI_WIDGET_EXPAND_VERTICAL = 1 << 2, + MGUI_WIDGET_DEBUG_HAS_PARENT = 1 << 3 +} mgui_widget_flags; + typedef struct { int left; - int top; int right; + int top; int bottom; } mgui_margin; struct mgui_widget { - mgui_widget_type type; + uint8_t type; /* mgui_widget_type */ + uint8_t flags; /* mgui_widget_flags */ + uint8_t alignment; /* mgui_alignment, MGUI_WIDGET_ALIGN_TOP_LEFT by default */ mgui_margin margin; + mgl_vec2i size; }; void mgui_widget_init(mgui_widget *self, mgui_widget_type type); void mgui_widget_destroy(mgui_widget *widget); -void mgui_widget_set_margin(mgui_widget *self, int left, int top, int right, int bottom); +void mgui_widget_set_visible(mgui_widget *self, bool visible); +void mgui_widget_set_expand(mgui_widget *self, bool horizontal, bool vertical); +void mgui_widget_set_alignment(mgui_widget *self, mgui_alignment alignment); +void mgui_widget_set_margin(mgui_widget *self, mgui_margin margin); +void mgui_widget_set_size(mgui_widget *self, mgl_vec2i size); void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position); -void mgui_widget_set_width(mgui_widget *self, int width); +void mgui_widget_calculate_size(mgui_widget *self, mgl_vec2i max_size); +void mgui_widget_set_has_parent(mgui_widget *self); void mgui_widget_on_event(mgui_widget *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_widget_draw(mgui_widget *self, mgl_window *window); +void mgui_widget_draw(mgui_widget *self, mgl_window *window); #endif /* MGUI_WIDGET_H */ -- cgit v1.2.3