-
Notifications
You must be signed in to change notification settings - Fork 0
/
microui.sunder
231 lines (210 loc) · 8.05 KB
/
microui.sunder
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import "c";
let MU_COMMANDLIST_SIZE = 256u * 1024u;
let MU_ROOTLIST_SIZE = 32u;
let MU_CONTAINERSTACK_SIZE = 32u;
let MU_CLIPSTACK_SIZE = 32u;
let MU_IDSTACK_SIZE = 32u;
let MU_LAYOUTSTACK_SIZE = 16u;
let MU_CONTAINERPOOL_SIZE = 48u;
let MU_TREENODEPOOL_SIZE = 48u;
let MU_MAX_WIDTHS = 16u;
alias MU_REAL = float;
let MU_REAL_FMT = startof("%.3g");
let MU_SLIDER_FMT = startof("%.2f");
let MU_MAX_FMT = 127u;
alias MU_CLIP = enum {
MU_CLIP_PART = 1;
MU_CLIP_ALL;
};
alias MU_COMMAND = enum {
MU_COMMAND_JUMP = 1;
MU_COMMAND_CLIP;
MU_COMMAND_RECT;
MU_COMMAND_TEXT;
MU_COMMAND_ICON;
MU_COMMAND_MAX;
};
alias MU_COLOR = enum {
MU_COLOR_TEXT;
MU_COLOR_BORDER;
MU_COLOR_WINDOWBG;
MU_COLOR_TITLEBG;
MU_COLOR_TITLETEXT;
MU_COLOR_PANELBG;
MU_COLOR_BUTTON;
MU_COLOR_BUTTONHOVER;
MU_COLOR_BUTTONFOCUS;
MU_COLOR_BASE;
MU_COLOR_BASEHOVER;
MU_COLOR_BASEFOCUS;
MU_COLOR_SCROLLBASE;
MU_COLOR_SCROLLTHUMB;
MU_COLOR_MAX;
};
alias MU_ICON = enum {
MU_ICON_CLOSE = 1;
MU_ICON_CHECK;
MU_ICON_COLLAPSED;
MU_ICON_EXPANDED;
MU_ICON_MAX;
};
alias MU_RES = enum {
MU_RES_ACTIVE = (1u << 0);
MU_RES_SUBMIT = (1u << 1);
MU_RES_CHANGE = (1u << 2);
};
alias MU_OPT = enum {
MU_OPT_ALIGNCENTER = (1u << 0);
MU_OPT_ALIGNRIGHT = (1u << 1);
MU_OPT_NOINTERACT = (1u << 2);
MU_OPT_NOFRAME = (1u << 3);
MU_OPT_NORESIZE = (1u << 4);
MU_OPT_NOSCROLL = (1u << 5);
MU_OPT_NOCLOSE = (1u << 6);
MU_OPT_NOTITLE = (1u << 7);
MU_OPT_HOLDFOCUS = (1u << 8);
MU_OPT_AUTOSIZE = (1u << 9);
MU_OPT_POPUP = (1u << 10);
MU_OPT_CLOSED = (1u << 11);
MU_OPT_EXPANDED = (1u << 12);
};
alias MU_MOUSE = enum {
MU_MOUSE_LEFT = (1u << 0);
MU_MOUSE_RIGHT = (1u << 1);
MU_MOUSE_MIDDLE = (1u << 2);
};
alias MU_KEY = enum {
MU_KEY_SHIFT = (1u << 0);
MU_KEY_CTRL = (1u << 1);
MU_KEY_ALT = (1u << 2);
MU_KEY_BACKSPACE = (1u << 3);
MU_KEY_RETURN = (1u << 4);
};
alias mu_Id = uint;
alias mu_Real = MU_REAL;
alias mu_Font = *any;
struct mu_Vec2 { var x: sint; var y: sint; }
struct mu_Rect { var x: sint; var y: sint; var w: sint; var h: sint; }
struct mu_Color { var r: u8; var g: u8; var b: u8; var a: u8; }
struct mu_PoolItem { var id: mu_Id; var last_update: sint; }
struct mu_BaseCommand { var type: sint; var size: sint; }
struct mu_JumpCommand { var base: mu_BaseCommand; var dst: *any; }
struct mu_ClipCommand { var base: mu_BaseCommand; var rect: mu_Rect; }
struct mu_RectCommand { var base: mu_BaseCommand; var rect: mu_Rect; var color: mu_Color; }
struct mu_TextCommand { var base: mu_BaseCommand; var font: mu_Font; var pos: mu_Vec2; var color: mu_Color; var str: [1]char; }
struct mu_IconCommand { var base: mu_BaseCommand; var rect: mu_Rect; var id: sint; var color: mu_Color; }
union mu_Command {
var type: sint;
var base: mu_BaseCommand;
var jump: mu_JumpCommand;
var clip: mu_ClipCommand;
var rect: mu_RectCommand;
var text: mu_TextCommand;
var icon: mu_IconCommand;
}
struct mu_Layout {
var body: mu_Rect;
var next: mu_Rect;
var position: mu_Vec2;
var size: mu_Vec2;
var max: mu_Vec2;
var widths: [MU_MAX_WIDTHS]sint;
var items: sint;
var item_index: sint;
var next_row: sint;
var next_type: sint;
var indent: sint;
}
struct mu_Container {
var head: *mu_Command;
var tail: *mu_Command;
var rect: mu_Rect;
var body: mu_Rect;
var content_size: mu_Vec2;
var scroll: mu_Vec2;
var zindex: sint;
var open: sint;
}
struct mu_Style {
var font: mu_Font;
var size: mu_Vec2;
var padding: sint;
var spacing: sint;
var indent: sint;
var title_height: sint;
var scrollbar_size: sint;
var thumb_size: sint;
var colors: [(:usize)MU_COLOR_MAX]mu_Color;
}
struct mu_Context {
# callbacks
var text_width: func(mu_Font, *char, sint) sint;
var text_height: func(mu_Font) sint;
var draw_frame: func(mu_Context, mu_Rect, sint) void;
# core state
var _style: mu_Style;
var style: *mu_Style;
var hover: mu_Id;
var focus: mu_Id;
var last_id: mu_Id;
var last_rect: mu_Rect;
var last_zindex: sint;
var updated_focus: sint;
var frame: sint;
var hover_root: *mu_Container;
var next_hover_root: *mu_Container;
var scroll_target: *mu_Container;
var number_edit_buf: [MU_MAX_FMT]char;
var number_edit: mu_Id;
# stacks
var command_list: struct { var idx: sint; var items: [MU_COMMANDLIST_SIZE]char; };
var root_list: struct { var idx: sint; var items: [MU_ROOTLIST_SIZE]*mu_Container; };
var container_stack: struct { var idx: sint; var items: [MU_CONTAINERSTACK_SIZE]*mu_Container; };
var clip_stack: struct { var idx: sint; var items: [MU_CLIPSTACK_SIZE]mu_Rect; };
var id_stack: struct { var idx: sint; var items: [MU_IDSTACK_SIZE]mu_Id; };
var layout_stack: struct { var idx: sint; var items: [MU_LAYOUTSTACK_SIZE]mu_Layout; };
# retained state pools
var container_pool: [MU_CONTAINERPOOL_SIZE]mu_PoolItem;
var containers: [MU_CONTAINERPOOL_SIZE]mu_Container;
var treenode_pool: [MU_TREENODEPOOL_SIZE]mu_PoolItem;
# input state
var mouse_pos: mu_Vec2;
var last_mouse_pos: mu_Vec2;
var mouse_delta: mu_Vec2;
var scroll_delta: mu_Vec2;
var mouse_down: sint;
var mouse_pressed: sint;
var key_down: sint;
var key_pressed: sint;
var input_text: [32]char;
}
extern func mu_init(ctx: *mu_Context) void;
extern func mu_begin(ctx: *mu_Context) void;
extern func mu_end(ctx: *mu_Context) void;
extern func mu_layout_next(ctx: *mu_Context) mu_Rect;
func mu_button(ctx: *mu_Context, label: *char) sint { return mu_button_ex(ctx, label, 0, (:sint)MU_OPT_ALIGNCENTER); }
func mu_textbox(ctx: *mu_Context, buf: *char, bufsz: sint) sint { return mu_textbox_ex(ctx, buf, bufsz, 0); }
func mu_slider(ctx: *mu_Context, value: *mu_Real, lo: mu_Real, hi: mu_Real) sint { return mu_slider_ex(ctx, value, lo, hi, 0.0, MU_SLIDER_FMT, (:sint)MU_OPT_ALIGNCENTER); }
func mu_number(ctx: *mu_Context, value: *mu_Real, step: mu_Real) sint { return mu_number_ex(ctx, value, step, MU_SLIDER_FMT, (:sint)MU_OPT_ALIGNCENTER); }
func mu_header(ctx: *mu_Context, label: *char) sint { return mu_header_ex(ctx, label, 0); }
func mu_begin_treenode(ctx: *mu_Context, label: *char) sint { return mu_begin_treenode_ex(ctx, label, 0); }
func mu_begin_window(ctx: *mu_Context, title: *char, rect: mu_Rect) sint { return mu_begin_window_ex(ctx, title, rect, 0); }
func mu_begin_panel(ctx: *mu_Context, name: *char) void { mu_begin_panel_ex(ctx, name, 0); }
extern func mu_text(ctx: *mu_Context, text: *char) void;
extern func mu_label(ctx: *mu_Context, text: *char) void;
extern func mu_button_ex(ctx: *mu_Context, label: *char, icon: sint, opt: sint) sint;
extern func mu_checkbox(ctx: *mu_Context, label: *char, state: *sint) sint;
extern func mu_textbox_raw(ctx: *mu_Context, buf: *char, bufsz: sint, id: mu_Id, r: mu_Rect, opt: sint) sint;
extern func mu_textbox_ex(ctx: *mu_Context, buf: *char, bufsz: sint, opt: sint) sint;
extern func mu_slider_ex(ctx: *mu_Context, value: *mu_Real, low: mu_Real, high: mu_Real, step: mu_Real, fmt: *char, opt: sint) sint;
extern func mu_number_ex(ctx: *mu_Context, value: *mu_Real, step: mu_Real, fmt: *char, opt: sint) sint;
extern func mu_begin_treenode_ex(ctx: *mu_Context, label: *char, opt: sint) sint;
extern func mu_end_treenode(ctx: *mu_Context) void;
extern func mu_header_ex(ctx: *mu_Context, label: *char, opt: sint) sint;
extern func mu_begin_window_ex(ctx: *mu_Context, title: *char, rect: mu_Rect, opt: sint) sint;
extern func mu_end_window(ctx: *mu_Context) void;
extern func mu_open_popup(ctx: *mu_Context, name: *char) void;
extern func mu_begin_popup(ctx: *mu_Context, name: *char) sint;
extern func mu_end_popup(ctx: *mu_Context) void;
extern func mu_begin_panel_ex(ctx: *mu_Context, name: *char, opt: sint) void;
extern func mu_end_panel(ctx: *mu_Context) void;