aboutsummaryrefslogtreecommitdiff
path: root/include/mgui/widget.h
blob: 0e77fd2b4fcd523fbb16b06af10a77df0b82ed80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef MGUI_WIDGET_H
#define MGUI_WIDGET_H

#include <mgl/system/vec.h>
#include <stdint.h>
#include <stdbool.h>

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 */