#include "../../include/mgui/widget.h" #include "../../include/mgui/list.h" #include "../../include/mgui/button.h" #include "../../include/mgui/label.h" #include "../../include/mgui/image.h" /* TODO: Use margin */ void mgui_widget_init(mgui_widget *self, mgui_widget_type type) { self->type = type; mgui_widget_set_margin(self, 0, 0, 0, 0); } void mgui_widget_set_margin(mgui_widget *self, int left, int top, int right, int bottom) { self->margin.left = left; self->margin.top = top; self->margin.right = right; self->margin.bottom = bottom; } void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position) { switch(self->type) { case MGUI_WIDGET_LIST: mgui_list_set_position(mgui_widget_to_list(self), position); break; case MGUI_WIDGET_BUTTON: mgui_button_set_position(mgui_widget_to_button(self), position); break; case MGUI_WIDGET_LABEL: mgui_label_set_position(mgui_widget_to_label(self), position); break; case MGUI_WIDGET_IMAGE: mgui_image_set_position(mgui_widget_to_image(self), position); break; } } void mgui_widget_set_width(mgui_widget *self, int width) { switch(self->type) { case MGUI_WIDGET_LIST: mgui_list_set_width(mgui_widget_to_list(self), width); break; case MGUI_WIDGET_BUTTON: mgui_button_set_width(mgui_widget_to_button(self), width); break; case MGUI_WIDGET_LABEL: mgui_label_set_width(mgui_widget_to_label(self), width); break; case MGUI_WIDGET_IMAGE: mgui_image_set_width(mgui_widget_to_image(self), width); break; } } void mgui_widget_on_event(mgui_widget *self, mgl_window *window, mgl_event *event) { switch(self->type) { case MGUI_WIDGET_LIST: mgui_list_on_event(mgui_widget_to_list(self), window, event); break; case MGUI_WIDGET_BUTTON: mgui_button_on_event(mgui_widget_to_button(self), window, event); break; case MGUI_WIDGET_LABEL: mgui_label_on_event(mgui_widget_to_label(self), window, event); break; case MGUI_WIDGET_IMAGE: mgui_image_on_event(mgui_widget_to_image(self), window, event); break; } } mgl_vec2i mgui_widget_draw(mgui_widget *self, mgl_window *window) { switch(self->type) { case MGUI_WIDGET_LIST: return mgui_list_draw(mgui_widget_to_list(self), window); case MGUI_WIDGET_BUTTON: return mgui_button_draw(mgui_widget_to_button(self), window); case MGUI_WIDGET_LABEL: return mgui_label_draw(mgui_widget_to_label(self), window); case MGUI_WIDGET_IMAGE: return mgui_image_draw(mgui_widget_to_image(self), window); } return (mgl_vec2i){ 0, 0 }; }