#ifndef MGUI_WIDGET_H #define MGUI_WIDGET_H #include #include #include typedef struct mgl_window mgl_window; typedef struct mgl_event mgl_event; typedef struct mgui_widget mgui_widget; typedef enum { MGUI_WIDGET_LIST, MGUI_WIDGET_SCROLLVIEW, MGUI_WIDGET_BUTTON, MGUI_WIDGET_LABEL, MGUI_WIDGET_RICHTEXT, MGUI_WIDGET_IMAGE } mgui_widget_type; typedef enum { MGUI_WIDGET_ALIGN_TOP_LEFT, MGUI_WIDGET_ALIGN_TOP_CENTER, MGUI_WIDGET_ALIGN_TOP_RIGHT, MGUI_WIDGET_ALIGN_CENTER_LEFT, MGUI_WIDGET_ALIGN_CENTER_CENTER, MGUI_WIDGET_ALIGN_CENTER_RIGHT, MGUI_WIDGET_ALIGN_BOTTOM_LEFT, MGUI_WIDGET_ALIGN_BOTTOM_CENTER, MGUI_WIDGET_ALIGN_BOTTOM_RIGHT, } mgui_alignment; typedef enum { MGUI_WIDGET_VISIBLE = 1 << 0, MGUI_WIDGET_EXPAND_HORIZONTAL = 1 << 1, MGUI_WIDGET_EXPAND_VERTICAL = 1 << 2, MGUI_WIDGET_DEBUG_HAS_PARENT = 1 << 3 } mgui_widget_flags; typedef struct { uint16_t left; uint16_t right; uint16_t top; uint16_t bottom; } mgui_margin; struct mgui_widget { uint8_t type; /* mgui_widget_type */ uint8_t flags; /* mgui_widget_flags */ uint8_t alignment; /* mgui_alignment, MGUI_WIDGET_ALIGN_TOP_LEFT by default */ mgui_margin margin; mgl_vec2i size; void *userdata; }; void mgui_widget_init(mgui_widget *self, mgui_widget_type type); void mgui_widget_destroy(mgui_widget *widget); void mgui_widget_set_visible(mgui_widget *self, bool visible); void mgui_widget_set_expand(mgui_widget *self, bool horizontal, bool vertical); void mgui_widget_set_alignment(mgui_widget *self, mgui_alignment alignment); void mgui_widget_set_margin(mgui_widget *self, mgui_margin margin); void mgui_widget_set_size(mgui_widget *self, mgl_vec2i size); void mgui_widget_set_position(mgui_widget *self, mgl_vec2i position); void mgui_widget_calculate_size(mgui_widget *self, mgl_vec2i max_size); void mgui_widget_set_has_parent(mgui_widget *self); void mgui_widget_on_event(mgui_widget *self, mgl_window *window, mgl_event *event); void mgui_widget_draw(mgui_widget *self, mgl_window *window); #endif /* MGUI_WIDGET_H */