diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-12-20 10:26:12 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-12-21 20:22:33 +0100 |
commit | 44e987c8521a99519350a42292bcfcd28451dcbd (patch) | |
tree | 699015a5dd459e96e0b19f4836f7dcffc1e347de /src/mgui/list.c | |
parent | 6bb40bf0c5cd8ee8fb87640fd04b2c595f84c1d3 (diff) |
Async load images
Diffstat (limited to 'src/mgui/list.c')
-rw-r--r-- | src/mgui/list.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/mgui/list.c b/src/mgui/list.c index 687906d..ee58616 100644 --- a/src/mgui/list.c +++ b/src/mgui/list.c @@ -16,6 +16,7 @@ mgui_list* mgui_list_create(mgui_list_direction direction) { mgui_list *list = mgui_alloc(sizeof(mgui_list)); mgui_widget_init(&list->widget, MGUI_WIDGET_LIST); list->direction = direction; + list->spacing = 0; list->position = (mgl_vec2i){ 0, 0 }; list->items = NULL; list->items_capacity = 0; @@ -40,14 +41,25 @@ mgui_list* mgui_widget_to_list(mgui_widget *widget) { return (mgui_list*)widget; } +void mgui_list_set_spacing(mgui_list *self, int spacing) { + /* TODO: Multiply by scaling */ + self->spacing = spacing; + /* TODO: mgui_list_calculate_size */ +} + void mgui_list_set_position(mgui_list *self, mgl_vec2i position) { self->position = position; } void mgui_list_calculate_size(mgui_list *self, mgl_vec2i max_size) { + const int total_spacing = max_int(0, self->num_items - 1) * self->spacing; + mgl_vec2i size = (mgl_vec2i){ 0, 0 }; switch(self->direction) { case MGUI_LIST_HORIZONITAL: { + size.x = total_spacing; + max_size.x = max_int(0, max_size.x - total_spacing); + int num_expanded_widgets = 0; for(size_t i = 0; i < self->num_items; ++i) { mgui_widget *widget = self->items[i].widget; @@ -78,6 +90,9 @@ void mgui_list_calculate_size(mgui_list *self, mgl_vec2i max_size) { break; } case MGUI_LIST_VERTICAL: { + size.y = total_spacing; + max_size.y = max_int(0, max_size.y - total_spacing); + int num_expanded_widgets = 0; for(size_t i = 0; i < self->num_items; ++i) { mgui_widget *widget = self->items[i].widget; @@ -150,22 +165,31 @@ void mgui_list_draw(mgui_list *self, mgl_window *window) { /* TODO: Only do this when a direct child widget is dirty */ //mgui_list_calculate_size(self); + mgl_scissor scissor; + mgl_window_get_scissor(window, &scissor); + switch(self->direction) { case MGUI_LIST_HORIZONITAL: { for(size_t i = 0; i < self->num_items; ++i) { mgui_widget *widget = self->items[i].widget; - mgui_widget_set_position(widget, position); + mgui_widget_set_position(widget, (mgl_vec2i){ position.x + widget->margin.left, position.y + widget->margin.top }); mgui_widget_draw(widget, window); - position.x += widget->size.x; + position.x += widget->size.x + self->spacing; + + // if(position.x >= scissor.position.x + scissor.size.x) + // break; } break; } case MGUI_LIST_VERTICAL: { for(size_t i = 0; i < self->num_items; ++i) { mgui_widget *widget = self->items[i].widget; - mgui_widget_set_position(widget, position); + mgui_widget_set_position(widget, (mgl_vec2i){ position.x + widget->margin.left, position.y + widget->margin.top }); mgui_widget_draw(widget, window); - position.y += widget->size.y; + position.y += widget->size.y + self->spacing; + + // if(position.y >= scissor.position.y + scissor.size.y) + // break; } break; } |