aboutsummaryrefslogtreecommitdiff
path: root/src/mgui/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgui/list.c')
-rw-r--r--src/mgui/list.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/mgui/list.c b/src/mgui/list.c
index 9923c4f..a3a2422 100644
--- a/src/mgui/list.c
+++ b/src/mgui/list.c
@@ -1,17 +1,24 @@
#include "../../include/mgui/list.h"
#include "../../include/alloc.h"
#include <mgl/window/window.h>
+#include <mgl/graphics/rectangle.h>
+#include <mgl/mgl.h>
#include <assert.h>
-mgui_list* mgui_list_create(mgui_list_direction direction, mgl_vec2i size) {
+/*
+ TODO: Optimize for lists with 2 items or less by setting |items| and |items_capacity| to the first and second item
+ if num_items <= 2.
+*/
+
+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->position = (mgl_vec2i){ 0, 0 };
- list->size = size;
+ list->background_color = (mgl_color){ 0, 0, 0, 0 };
list->items = NULL;
- list->num_items = 0;
list->items_capacity = 0;
+ list->num_items = 0;
return list;
}
@@ -28,20 +35,19 @@ void mgui_list_set_position(mgui_list *self, mgl_vec2i position) {
self->position = position;
}
-void mgui_list_set_size(mgui_list *self, mgl_vec2i size) {
- self->size = size;
+void mgui_list_set_width(mgui_list *self, int width) {
/* TODO: if direction is horizontal then put the widget in the center of its area */
/* TODO: put the widget in the center for vertical as well, for items with a max size */
/* TODO: support max size for widgets */
if(self->direction == MGUI_LIST_VERTICAL) {
for(size_t i = 0; i < self->num_items; ++i) {
- mgui_widget_set_width(self->items[i], size.x);
+ mgui_widget_set_width(self->items[i], width);
}
}
}
-void mgui_list_set_width(mgui_list *self, int width) {
- mgui_list_set_size(self, (mgl_vec2i){ width, self->size.y });
+void mgui_list_set_background_color(mgui_list *self, mgl_color color) {
+ self->background_color = color;
}
static void mgui_list_ensure_capacity(mgui_list *self, size_t new_capacity) {
@@ -77,18 +83,33 @@ static int max_int(int a, int b) {
}
mgl_vec2i mgui_list_draw(mgui_list *self, mgl_window *window) {
- mgl_vec2i position = (mgl_vec2i){ 0, 0 };
+ mgl_vec2i position = self->position;
/* TODO: */
mgl_vec2i size = (mgl_vec2i){ 0, 0 };
- mgl_view prev_view;
- mgl_window_get_view(window, &prev_view);
+ /* TODO:
+ mgl_scissor prev_scissor;
+ mgl_window_get_scissor(window, &prev_scissor);
- mgl_view new_view = {
- .position = { self->position.x, self->position.y },
+ mgl_scissor new_scissor = {
+ .position = self->position,
.size = self->size
};
- mgl_window_set_view(window, &new_view);
+ mgl_window_set_scissor(window, &new_scissor);
+ */
+
+ /* TODO:
+ if(self->background_color.a > 0) {
+ mgl_rectangle rect = {
+ .position = { self->position.x, self->position.y },
+ .size = { self->size.x, self->size.y },
+ .color = self->background_color
+ };
+ mgl_rectangle_draw(mgl_get_context(), &rect);
+ }
+ */
+
+ /* TODO: Set scissor for each draw widget */
switch(self->direction) {
case MGUI_LIST_HORIZONITAL: {
@@ -113,6 +134,7 @@ mgl_vec2i mgui_list_draw(mgui_list *self, mgl_window *window) {
}
}
- mgl_window_set_view(window, &prev_view); /* TODO: Remove */
+ /* TODO: Remove */
+ /*mgl_window_set_scissor(window, &prev_scissor);*/
return size;
}