diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-12-14 23:48:34 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-12-15 10:30:34 +0100 |
commit | 0417619b36dc7f4b004caa64a65570f1344d1c8d (patch) | |
tree | 10c4b9bbe5bd7c16322495890c3324cd76d584c8 /include/mgui | |
parent | 396686a09ef471499c11256b8516c2702f761060 (diff) |
Layout, expand, etc
Diffstat (limited to 'include/mgui')
-rw-r--r-- | include/mgui/button.h | 5 | ||||
-rw-r--r-- | include/mgui/image.h | 5 | ||||
-rw-r--r-- | include/mgui/label.h | 7 | ||||
-rw-r--r-- | include/mgui/list.h | 14 | ||||
-rw-r--r-- | include/mgui/mgui.h | 2 | ||||
-rw-r--r-- | include/mgui/richtext.h | 5 | ||||
-rw-r--r-- | include/mgui/scrollview.h | 7 | ||||
-rw-r--r-- | include/mgui/widget.h | 42 |
8 files changed, 56 insertions, 31 deletions
diff --git a/include/mgui/button.h b/include/mgui/button.h index 986cb9c..f8e223c 100644 --- a/include/mgui/button.h +++ b/include/mgui/button.h @@ -20,9 +20,8 @@ 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_set_width(mgui_button *self, int width); +void mgui_button_calculate_size(mgui_button *self, mgl_vec2i max_size); void mgui_button_on_event(mgui_button *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_button_draw(mgui_button *self, mgl_window *window); +void mgui_button_draw(mgui_button *self, mgl_window *window); #endif /* MGUI_BUTTON_H */ diff --git a/include/mgui/image.h b/include/mgui/image.h index 8d34a7a..e6787f2 100644 --- a/include/mgui/image.h +++ b/include/mgui/image.h @@ -15,9 +15,8 @@ mgui_widget* mgui_image_to_widget(mgui_image *list); mgui_image* mgui_widget_to_image(mgui_widget *widget); void mgui_image_set_position(mgui_image *self, mgl_vec2i position); -void mgui_image_set_width(mgui_image *self, int width); +void mgui_image_calculate_size(mgui_image *self, mgl_vec2i max_size); void mgui_image_on_event(mgui_image *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_image_draw(mgui_image *self, mgl_window *window); +void mgui_image_draw(mgui_image *self, mgl_window *window); #endif /* MGUI_IMAGE_H */ diff --git a/include/mgui/label.h b/include/mgui/label.h index 4b66ef8..ef1369b 100644 --- a/include/mgui/label.h +++ b/include/mgui/label.h @@ -10,8 +10,6 @@ typedef struct { char *str; size_t str_size; mgl_text text; - mgl_vec2i position; - int width; } mgui_label; mgui_label* mgui_label_create(const char *str, size_t size, unsigned char character_size); @@ -20,9 +18,8 @@ mgui_widget* mgui_label_to_widget(mgui_label *list); mgui_label* mgui_widget_to_label(mgui_widget *widget); void mgui_label_set_position(mgui_label *self, mgl_vec2i position); -void mgui_label_set_width(mgui_label *self, int width); +void mgui_label_calculate_size(mgui_label *self, mgl_vec2i max_size); void mgui_label_on_event(mgui_label *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_label_draw(mgui_label *self, mgl_window *window); +void mgui_label_draw(mgui_label *self, mgl_window *window); #endif /* MGUI_LABEL_H */ diff --git a/include/mgui/list.h b/include/mgui/list.h index af1ceae..7769ab6 100644 --- a/include/mgui/list.h +++ b/include/mgui/list.h @@ -3,6 +3,7 @@ #include "widget.h" #include <stddef.h> +#include <stdint.h> #include <mgl/graphics/color.h> typedef struct mgl_window mgl_window; @@ -14,11 +15,14 @@ typedef enum { } mgui_list_direction; typedef struct { + mgui_widget *widget; +} mgui_list_item; + +typedef struct { mgui_widget widget; mgui_list_direction direction; mgl_vec2i position; - mgl_color background_color; - mgui_widget **items; + mgui_list_item *items; size_t items_capacity; size_t num_items; } mgui_list; @@ -29,11 +33,9 @@ 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_set_width(mgui_list *self, int width); -void mgui_list_set_background_color(mgui_list *self, mgl_color color); +void mgui_list_calculate_size(mgui_list *self, mgl_vec2i max_size); void mgui_list_append(mgui_list *self, mgui_widget *widget); void mgui_list_on_event(mgui_list *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_list_draw(mgui_list *self, mgl_window *window); +void mgui_list_draw(mgui_list *self, mgl_window *window); #endif /* MGUI_LIST_H */ diff --git a/include/mgui/mgui.h b/include/mgui/mgui.h index d76226f..15a2f73 100644 --- a/include/mgui/mgui.h +++ b/include/mgui/mgui.h @@ -2,9 +2,11 @@ #define MGUI_H typedef struct mgui_widget mgui_widget; +typedef struct mgl_event mgl_event; typedef struct mgl_window mgl_window; void mgui_init(); +void mgui_on_event(mgui_widget *root_widget, mgl_window *window, mgl_event *event); void mgui_draw(mgui_widget *root_widget, mgl_window *window); /* Clamped to 1.0 second */ double mgui_get_seconds_since_last_update(); diff --git a/include/mgui/richtext.h b/include/mgui/richtext.h index c0604c9..ff57271 100644 --- a/include/mgui/richtext.h +++ b/include/mgui/richtext.h @@ -31,9 +31,8 @@ mgui_widget* mgui_richtext_to_widget(mgui_richtext *list); mgui_richtext* mgui_widget_to_richtext(mgui_widget *widget); void mgui_richtext_set_position(mgui_richtext *self, mgl_vec2i position); -void mgui_richtext_set_width(mgui_richtext *self, int width); +void mgui_richtext_calculate_size(mgui_richtext *self, mgl_vec2i max_size); void mgui_richtext_on_event(mgui_richtext *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_richtext_draw(mgui_richtext *self, mgl_window *window); +void mgui_richtext_draw(mgui_richtext *self, mgl_window *window); #endif /* MGUI_RICHTEXT_H */ diff --git a/include/mgui/scrollview.h b/include/mgui/scrollview.h index 1b3d109..dded990 100644 --- a/include/mgui/scrollview.h +++ b/include/mgui/scrollview.h @@ -6,9 +6,7 @@ typedef struct { mgui_widget widget; mgui_widget *child; - mgl_vec2i child_size; mgl_vec2i position; - mgl_vec2i size; mgl_vec2i scroll; mgl_vec2f mouse_scroll; } mgui_scrollview; @@ -20,10 +18,9 @@ mgui_scrollview* mgui_widget_to_scrollview(mgui_widget *widget); void mgui_scrollview_set_child(mgui_scrollview *self, mgui_widget *child); void mgui_scrollview_set_position(mgui_scrollview *self, mgl_vec2i position); +void mgui_scrollview_calculate_size(mgui_scrollview *self, mgl_vec2i max_size); void mgui_scrollview_set_size(mgui_scrollview *self, mgl_vec2i size); -void mgui_scrollview_set_width(mgui_scrollview *self, int width); void mgui_scrollview_on_event(mgui_scrollview *self, mgl_window *window, mgl_event *event); -/* Returns the size of the widget */ -mgl_vec2i mgui_scrollview_draw(mgui_scrollview *self, mgl_window *window); +void mgui_scrollview_draw(mgui_scrollview *self, mgl_window *window); #endif /* MGUI_SCROLLVIEW_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 <mgl/system/vec.h> +#include <stdint.h> +#include <stdbool.h> 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 */ |