diff options
Diffstat (limited to 'src/mgui/widget.c')
-rw-r--r-- | src/mgui/widget.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/mgui/widget.c b/src/mgui/widget.c index ed50154..4e93b8a 100644 --- a/src/mgui/widget.c +++ b/src/mgui/widget.c @@ -9,7 +9,6 @@ #include <stdio.h> #include <stdlib.h> -/* TODO: Use margin */ /* TODO: Use alignment */ /* TODO: Use visible flag */ @@ -34,6 +33,7 @@ void mgui_widget_init(mgui_widget *self, mgui_widget_type type) { self->alignment = MGUI_WIDGET_ALIGN_TOP_LEFT; mgui_widget_set_margin(self, (mgui_margin){ 0, 0, 0, 0 }); self->size = (mgl_vec2i){ 0, 0 }; + self->userdata = NULL; } void mgui_widget_destroy(mgui_widget *widget) { @@ -104,26 +104,33 @@ void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position) { } void mgui_widget_calculate_size(mgui_widget *self, mgl_vec2i max_size) { + const int margin_width = self->margin.left + self->margin.right; + const int margin_height = self->margin.top + self->margin.bottom; + const mgl_vec2i max_size_result = (mgl_vec2i){ max_size.x - margin_width, max_size.y - margin_height }; + switch(self->type) { case MGUI_WIDGET_LIST: - mgui_list_calculate_size(mgui_widget_to_list(self), max_size); + mgui_list_calculate_size(mgui_widget_to_list(self), max_size_result); break; case MGUI_WIDGET_SCROLLVIEW: - mgui_scrollview_calculate_size(mgui_widget_to_scrollview(self), max_size); + mgui_scrollview_calculate_size(mgui_widget_to_scrollview(self), max_size_result); break; case MGUI_WIDGET_BUTTON: - mgui_button_calculate_size(mgui_widget_to_button(self), max_size); + mgui_button_calculate_size(mgui_widget_to_button(self), max_size_result); break; case MGUI_WIDGET_LABEL: - mgui_label_calculate_size(mgui_widget_to_label(self), max_size); + mgui_label_calculate_size(mgui_widget_to_label(self), max_size_result); break; case MGUI_WIDGET_RICHTEXT: - mgui_richtext_calculate_size(mgui_widget_to_richtext(self), max_size); + mgui_richtext_calculate_size(mgui_widget_to_richtext(self), max_size_result); break; case MGUI_WIDGET_IMAGE: - mgui_image_calculate_size(mgui_widget_to_image(self), max_size); + mgui_image_calculate_size(mgui_widget_to_image(self), max_size_result); break; } + + self->size.x += margin_width; + self->size.y += margin_height; } void mgui_widget_set_has_parent(mgui_widget *self) { |