diff options
Diffstat (limited to 'src/mgui/widget.c')
-rw-r--r-- | src/mgui/widget.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/mgui/widget.c b/src/mgui/widget.c new file mode 100644 index 0000000..242174d --- /dev/null +++ b/src/mgui/widget.c @@ -0,0 +1,48 @@ +#include "../../include/mgui/widget.h" +#include "../../include/mgui/list.h" +#include "../../include/mgui/button.h" + +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; + } +} + +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; + } +} + +void mgui_widget_draw(mgui_widget *self, mgl_window *window) { + switch(self->type) { + case MGUI_WIDGET_LIST: + mgui_list_draw(mgui_widget_to_list(self), window); + break; + case MGUI_WIDGET_BUTTON: + mgui_button_draw(mgui_widget_to_button(self), window); + break; + } +} |