-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.h
More file actions
705 lines (582 loc) · 23.4 KB
/
Copy pathgui.h
File metadata and controls
705 lines (582 loc) · 23.4 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#pragma once
#include "poglib/basic/arena.h"
#include "poglib/basic/common.h"
#include "poglib/basic/ds/list.h"
#include "poglib/font/glfreetypefont.h"
#include "poglib/gfx/gl/shader.h"
#include "poglib/gfx/gl/types.h"
#include "poglib/gfx/gl/vbo_stream_types.h"
#include "poglib/gfx/glrenderer3d.h"
#include <poglib/basic.h>
#include <poglib/math.h>
//INFO: This uses a stack based layout system -
//Cursor starts from top left with (vec2f_t){0}
//Each cursor update is pushed to the stack
//TODO:
//1.Scroll
//2.Text wrapping
//3.Way to have composition ui placed at the right end of the screen from the start
//4.Text truncate
//BUG:
//1. WDC coordinates text are not wrapping around to next line of NDC coordinates text while enclosed in the same composition
#define GUI_ZORDER_LIMIT 1000000
#define UI_ZORDER_RESERVE 200
typedef enum {
UI_BEHAVIOR_NONE = 0,
UI_BEHAVIOR_HOVERABLE = 1 << 0,
UI_BEHAVIOR_CLICKABLE = 1 << 1,
UI_BEHAVIOR_TRACK_STATE_TOGGLE = 1 << 2,
UI_BEHAVIOR_TRACK_STATE_LOCK_MOUSE_ON_DRAG = 1 << 3,
} ui_trait_type;
typedef enum {
UI_STYLE_NONE = 0,
UI_STYLE_ROUNDED_CORNERS = 1 << 0,
UI_STYLE_ONLY_TEXT = 1 << 1,
} ui_style_config;
typedef enum {
UI_TEXT_ALIGN_LEFT = 0,
UI_TEXT_ALIGN_CENTER = 1,
UI_TEXT_ALIGN_RIGHT = 2,
} ui_text_align;
typedef enum {
UI_SIZE_WRAP = 0,
UI_SIZE_FILL = 1,
} ui_size_mode;
typedef struct {
vec2f_t cursor;
f32 width;
f32 height;
} ui_region_t;
typedef enum {
UI_LAYOUT_HORIZONTAL = 0,
UI_LAYOUT_VERTICAL = 1
} ui_layout_t;
typedef struct {
void *ref;
u32 size;
//NOTE: i dont know what to call this, brought to invert how the offset it applied to the `ref` binding
bool invert;
} ui_valuebinding_t;
typedef struct {
ui_layout_t layout;
struct {
u32 traits;
u32 styles;
} composition;
struct {
u32 top;
u32 right;
u32 bottom;
u32 left;
} padding, margin, border;
u32 corner_radius;
struct {
u32 min_width;
u32 min_height;
} dim;
str_t text;
struct {
vec4f_t base;
vec4f_t highlight;
} color;
//WARN: AI introduced this, use with care - not tested!
ui_text_align text_align;
ui_size_mode size_mode;
ui_valuebinding_t binding;
struct {
u32 id;
} internal;
} ui_config_t;
typedef ui_config_t ui_t;
typedef struct {
ui_region_t position;
box_t uv;
vec4f_t color;
f32 corner_radius;
f32 zorder;
f32 is_text;
} ui_attr_t;
#define MAX_UI_NESTING_ALLOWED 16
typedef struct gui_t gui_t;
typedef void (*ui_composition)(gui_t *gui, ...);
typedef struct {
ui_region_t region;
u32 max_row_height;
u32 max_col_width;
ui_region_t starting_region;
ui_layout_t layout;
} cursor_ctx_t;
struct gui_t {
arena_t arena;
glfreetypefont_t freetypefont;
glshader_t shader;
struct {
list_t instanced_attrs;
} gfx;
struct {
struct {
i8 top;
cursor_ctx_t buffer[MAX_UI_NESTING_ALLOWED];
} layout_cursor_stack;
struct {
u32 ui_id;
u32 last_mouseclick_released_ui_id;
} mouse_lock_on_ui;
//NOTE: `is_mouse_on_ui` is to track whether mouse is on ui during the immediate mode rendering
bool is_mouse_on_ui;
u32 ui_id_generator;
} internal;
struct {
u32 hovered_ui_id;
} state;
ui_composition callback;
};
gui_t gui_init(arena_t *const arena, const ui_region_t starting_region);
//INFO: define this in a function
u32 gui_ui_compose_begin(gui_t * const gui, const ui_config_t config);
void gui_ui_compose_end(gui_t *gui);
//INFO: pass above declared function that includes the gui compisition into here
void gui_set_composition(gui_t * const self, ui_composition callback);
bool gui_ui_ishovered(gui_t *const self, const u32 id);
bool gui_ui_isclicked(gui_t *const self, const u32 id);
bool gui_is_mouse_captured(const gui_t *const gui);
void gui_render(gui_t *const self, const bool render_as_wireframe);
void gui_destroy(gui_t *const self);
#ifndef IGNORE_GUI_IMPLEMENTATION
gui_t gui_init(arena_t *const arena, const ui_region_t starting_region)
{
gui_t o = {0};
o.shader = glshader_init(
str(POGLIB_ROOT_DIR"/gui/uishader-vtx.glsl"),
str(POGLIB_ROOT_DIR"/gui/uishader-frag.glsl"),
(gluniform_registry_t) {
.count = 1,
.data = {
[0] = {
.name = str_lit("projection"),
.type = GL_UNIFORM_TYPE_MATRIX4F
}
}
},
arena
);
o.freetypefont = glfreetypefont_init(DEFAULT_FONT_ROBOTO_MEDIUM_FILEPATH, 14, true);
o.gfx.instanced_attrs = list_init(ui_attr_t, arena);
o.internal.layout_cursor_stack.top = 0;
o.internal.layout_cursor_stack.buffer[0] = (cursor_ctx_t){
.max_row_height = 0,
.region = starting_region,
.starting_region = starting_region,
.max_col_width = 0
};
return o;
}
void gui_destroy(gui_t *self)
{
glshader_destroy(&self->shader);
list_destroy(&self->gfx.instanced_attrs);
}
void gui__internal_update_state(gui_t *gui, const ui_config_t config)
{
window_t *win = window_get_current_active_window();
const vec2i_t mouse_pos = window_mouse_get_position(win);
if (!(config.composition.traits & UI_BEHAVIOR_HOVERABLE)) return;
const ui_region_t region = gui->internal
.layout_cursor_stack
.buffer[gui->internal.layout_cursor_stack.top]
.region;
const bool is_cursor_on_ui = ((f32)mouse_pos.x > region.cursor.x)
&& ((f32)mouse_pos.x < region.cursor.x + region.width)
&& ((f32)mouse_pos.y > region.cursor.y)
&& ((f32)mouse_pos.y < region.cursor.y + region.height);
const bool is_ui_clicked = is_cursor_on_ui && window_mouse_button_just_pressed(global_window, SDL_MOUSEBUTTON_LEFT);
gui->state.hovered_ui_id = is_cursor_on_ui
? config.internal.id
: gui->state.hovered_ui_id;
gui->internal.is_mouse_on_ui = is_cursor_on_ui;
if ((config.composition.traits & UI_BEHAVIOR_TRACK_STATE_TOGGLE) && is_ui_clicked) {
ASSERT(config.binding.size == sizeof(bool));
*(bool *)config.binding.ref = !*(bool *)config.binding.ref;
}
if (config.composition.traits & UI_BEHAVIOR_TRACK_STATE_LOCK_MOUSE_ON_DRAG) {
if (is_ui_clicked) {
gui->internal.mouse_lock_on_ui.ui_id = config.internal.id;
}
if (gui->internal.mouse_lock_on_ui.ui_id == config.internal.id) {
i32 rel = global_window->mouse.rel.x;
const f32 prev_val = *(f32 *)config.binding.ref;
{
if (config.binding.invert) *((f32 *)config.binding.ref) -= (rel / 10.f);
else *((f32 *)config.binding.ref) += (rel / 10.f);
}
const f32 new_val = *(f32 *)config.binding.ref;
}
if (gui->internal.mouse_lock_on_ui.ui_id && window_mouse_button_is_released(global_window, SDL_MOUSEBUTTON_LEFT)) {
gui->internal.mouse_lock_on_ui.last_mouseclick_released_ui_id = gui->internal.mouse_lock_on_ui.ui_id;
gui->internal.mouse_lock_on_ui.ui_id = 0;
}
}
}
vec4f_t gui__internal_get_color(const gui_t *gui, const ui_config_t config)
{
if ((config.composition.traits & UI_BEHAVIOR_HOVERABLE) == 0) {
return config.color.base;
}
if ((config.composition.traits & UI_BEHAVIOR_CLICKABLE) == 0) {
return config.color.base;
}
if ((config.composition.traits & UI_BEHAVIOR_TRACK_STATE_LOCK_MOUSE_ON_DRAG) && config.internal.id == gui->internal.mouse_lock_on_ui.ui_id) {
return config.color.highlight;
}
if (config.composition.traits & UI_BEHAVIOR_TRACK_STATE_TOGGLE) {
ASSERT(config.binding.ref);
return (*(bool *)config.binding.ref || gui->internal.is_mouse_on_ui) ? config.color.highlight : config.color.base;
}
return gui->internal.is_mouse_on_ui ? config.color.highlight : config.color.base;
}
void gui__internal_ui_push_cursor_layout(gui_t *gui, const cursor_ctx_t old_cursor__updated, const cursor_ctx_t new_cursor)
{
const u8 new_top = ++gui->internal.layout_cursor_stack.top;
ASSERT(new_top < MAX_UI_NESTING_ALLOWED);
gui->internal.layout_cursor_stack.buffer[new_top] = new_cursor;
gui->internal.layout_cursor_stack.buffer[new_top - 1] = old_cursor__updated;
}
void gui__internal_ui_pop_cursor_layout(gui_t *gui)
{
ASSERT(gui->internal.layout_cursor_stack.top > -1);
--gui->internal.layout_cursor_stack.top;
}
void gui_ui_compose_end(gui_t *gui)
{
gui__internal_ui_pop_cursor_layout(gui);
}
void gui__internal_ui_validate_config(const ui_config_t config)
{
ASSERT(config.dim.min_height);
ASSERT(config.dim.min_width);
if (config.composition.traits & UI_BEHAVIOR_TRACK_STATE_TOGGLE) {
ASSERT(config.binding.ref);
ASSERT(config.binding.size == sizeof(bool));
ASSERT((config.composition.traits & UI_BEHAVIOR_TRACK_STATE_LOCK_MOUSE_ON_DRAG) == 0);
}
if (config.composition.traits & UI_BEHAVIOR_TRACK_STATE_LOCK_MOUSE_ON_DRAG) {
ASSERT(config.binding.ref);
ASSERT(config.binding.size > sizeof(bool));
ASSERT((config.composition.traits & UI_BEHAVIOR_TRACK_STATE_TOGGLE) == 0);
}
if (config.composition.styles & UI_STYLE_ONLY_TEXT) {
ASSERT(config.text.len > 0);
}
}
ui_region_t gui__internal_ui_add_child(gui_t *gui, const ui_config_t config)
{
const cursor_ctx_t parent_layout = gui->internal
.layout_cursor_stack
.buffer[gui->internal.layout_cursor_stack.top];
const ui_region_t parent_region = parent_layout.region;
vec2f_t parents_current_cursor = parent_layout.region.cursor;
const f32 child_height = (f32)config.dim.min_height;
f32 child_width = (f32)config.dim.min_width;
if (config.size_mode == UI_SIZE_FILL) {
child_width = parent_region.width - (f32)(config.margin.left + config.margin.right);
}
const u32 child_region_width = config.margin.left + child_width + config.margin.right;
const u32 child_region_height = config.margin.top + config.margin.bottom + child_height;
//NOTE: handle cases where the generated current cursor is outside the containing region
{
const vec2f_t current_cursor = (vec2f_t ){
.x = parents_current_cursor.x + config.margin.left,
.y = parents_current_cursor.y + config.margin.top,
};
const bool is_next_cursor_outside_parent_region_horizontal = (current_cursor.x > (parent_layout.starting_region.cursor.x + parent_region.width));
const bool is_next_cursor_outside_parent_region_vertical = (current_cursor.y > (parent_layout.starting_region.cursor.y + parent_region.height));
if (is_next_cursor_outside_parent_region_horizontal && parent_layout.layout == UI_LAYOUT_HORIZONTAL) {
parents_current_cursor.x = parent_layout.starting_region.cursor.x;
parents_current_cursor.y = parent_layout.starting_region.cursor.y + parent_layout.max_row_height;
}
if (is_next_cursor_outside_parent_region_vertical && parent_layout.layout == UI_LAYOUT_VERTICAL) {
parents_current_cursor.x = parent_layout.starting_region.cursor.x + parent_layout.max_col_width;
parents_current_cursor.y = parent_layout.starting_region.cursor.y;
}
}
const ui_region_t child_region = {
.cursor = (vec2f_t){
.x = parents_current_cursor.x + config.margin.left,
.y = parents_current_cursor.y + config.margin.top,
},
.width = child_width,
.height = child_height
};
const vec2f_t next_parent_cursor = parent_layout.layout == UI_LAYOUT_HORIZONTAL
? (vec2f_t ){
.x = parents_current_cursor.x + child_region_width,
.y = parents_current_cursor.y
} : (vec2f_t ){
.x = parents_current_cursor.x,
.y = parents_current_cursor.y + child_region_height
};
gui__internal_ui_push_cursor_layout(
gui,
(cursor_ctx_t) {
.layout = parent_layout.layout,
.region = (ui_region_t) {
.cursor = next_parent_cursor,
.width = parent_region.width,
.height = parent_region.height
},
.max_row_height = MAX(parent_layout.max_row_height, child_region_height),
.starting_region = parent_layout.starting_region,
.max_col_width = MAX(parent_layout.max_col_width, child_region_width),
},
(cursor_ctx_t) {
.layout = config.layout,
.region = {
.cursor = (vec2f_t){
.x = child_region.cursor.x + (f32)config.padding.left,
.y = child_region.cursor.y + (f32)config.padding.top
},
.height = child_region.height - (f32)(config.padding.top + config.padding.bottom),
.width = child_region.width - (f32)(config.padding.left + config.padding.right),
},
.max_row_height = child_region.height,
.starting_region = child_region,
.max_col_width = child_region.width
}
);
return child_region;
}
void gui__internal_ui_create_text_internal(gui_t * const gui, const ui_region_t child_region, const ui_config_t config)
{
vec2f_t starting_pos = child_region.cursor;
f32 total_text_width = 0.0f;
for (u32 i = 0; i < config.text.len; i++)
total_text_width += gui->freetypefont.fontatlas[(u8)config.text.data[i]].ax;
if (config.text_align == UI_TEXT_ALIGN_CENTER)
starting_pos.x = child_region.cursor.x + (child_region.width - total_text_width) / 2.0f;
else if (config.text_align == UI_TEXT_ALIGN_RIGHT)
starting_pos.x = child_region.cursor.x + child_region.width - total_text_width;
for (u32 i = 0; i < config.text.len; i++)
{
const box_t quad = glfreetypefont_generate_uv_for_char(
&gui->freetypefont,
config.text.data[i]);
const u8 character = config.text.data[i];
const f32 glyph_w = gui->freetypefont.fontatlas[character].bw;
const f32 glyph_h = gui->freetypefont.fontatlas[character].bh;
const f32 bearing_x = gui->freetypefont.fontatlas[character].bl;
const f32 bearing_y = gui->freetypefont.fontatlas[character].bt;
const f32 advance_x = gui->freetypefont.fontatlas[character].ax;
const ui_attr_t attr = {
.position = {
.cursor = {
floorf(starting_pos.x + bearing_x),
floorf(starting_pos.y + (gui->freetypefont.fontsize - bearing_y))
},
.height = glyph_h,
.width = glyph_w,
},
.color = config.color.base,
.zorder = GUI_ZORDER_LIMIT - UI_ZORDER_RESERVE + gui->internal.layout_cursor_stack.top - 1,
.uv = quad,
.is_text = true,
};
list_append(&gui->gfx.instanced_attrs, attr);
starting_pos.x += advance_x;
}
}
u32 gui_ui_compose_begin(gui_t *const gui, ui_config_t config)
{
config.internal.id = ++gui->internal.ui_id_generator;
gui__internal_ui_validate_config(config);
const ui_region_t child_region = gui__internal_ui_add_child(gui, config);
gui__internal_update_state(gui, config);
const vec4f_t computed_color = gui__internal_get_color(gui, config);
if (config.composition.styles & UI_STYLE_ONLY_TEXT) {
gui__internal_ui_create_text_internal(gui, child_region, config);
return config.internal.id;
}
const ui_attr_t attr = {
.position = child_region,
.color = computed_color,
.zorder = GUI_ZORDER_LIMIT - UI_ZORDER_RESERVE + gui->internal.layout_cursor_stack.top - 1,
.uv = {0},
.corner_radius = (config.composition.styles & UI_STYLE_ROUNDED_CORNERS)
? (f32)config.corner_radius
: 0.0f,
.is_text = false,
};
list_append(&gui->gfx.instanced_attrs, attr);
if (config.text.len > 0) {
ui_config_t text_cfg = config;
text_cfg.color.base = (vec4f_t){1.0f, 1.0f, 1.0f, 1.0f};
gui__internal_ui_create_text_internal(gui, child_region, text_cfg);
}
return config.internal.id;
}
void gui__internal_reset_layout_cursor(gui_t *self)
{
const ui_region_t starting_region = self->internal.layout_cursor_stack.buffer[0].starting_region;
self->internal.layout_cursor_stack.top = 0;
self->internal.layout_cursor_stack.buffer[0] = (cursor_ctx_t){
.region = starting_region,
.max_row_height = 0,
.max_col_width = 0,
.starting_region = starting_region
};
}
void gui__internal_reset_internals(gui_t *self)
{
gui__internal_reset_layout_cursor(self);
memset(&self->state, 0, sizeof(self->state));
self->internal.is_mouse_on_ui = false;
self->internal.ui_id_generator = 0;
self->internal.mouse_lock_on_ui.last_mouseclick_released_ui_id = 0;
}
void gui_render(gui_t *const self, const bool render_as_wireframe)
{
ASSERT(self);
//NOTE: render starts here
glrenderer3d_draw((glrendererconfig_t) {
.calls = {
.count = 1,
.call = {
[0] = {
.is_wireframe = render_as_wireframe,
.disable_depth_buffer = true,
.instancing = {
.enable = true,
.count = self->gfx.instanced_attrs.len
},
.vtx = {
[VBO_STREAM_TYPE_GEOMETRY] = {
.raw_data = (u8 *)DEFAULT_QUAD__4TH_QUADRANT_VTX,
.size = sizeof(DEFAULT_QUAD__4TH_QUADRANT_VTX)
},
[VBO_STREAM_TYPE_INSTANCE] = {
.raw_data = self->gfx.instanced_attrs.data,
.size = list_get_size(&self->gfx.instanced_attrs),
},
},
.idx = {
.data = (u8 *)DEFAULT_QUAD_INDICES,
.nmemb = ARRAY_LEN(DEFAULT_QUAD_INDICES)
},
.shader_config = {
.shader = &self->shader,
.uniforms = {
.count = 1,
.data = {
[0] = {
.name = str_lit("projection"),
.value.mat4 = glms_ortho(0.0f, global_window->width, global_window->height, 0.0f, -1.f * GUI_ZORDER_LIMIT, GUI_ZORDER_LIMIT)
},
}
}
},
.textures = {
.count = 1,
.items = {
[0] = {
.type = GL_TEXTURE_TYPE_NORMAL,
.source = &self->freetypefont.texture
}
}
},
.attrs = {
.count = 7,
.attr = {
[0] = {
.ncmp = 2,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_GEOMETRY,
.interleaved = {0},
},
[1] = {
.ncmp = 4,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, position),
.stride = sizeof(ui_attr_t)
},
},
[2] = {
.ncmp = 4,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, color),
.stride = sizeof(ui_attr_t)
},
},
[3] = {
.ncmp = 1,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, zorder),
.stride = sizeof(ui_attr_t)
},
},
[4] = {
.ncmp = 4,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, uv),
.stride = sizeof(ui_attr_t)
},
},
[5] = {
.ncmp = 1,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, is_text),
.stride = sizeof(ui_attr_t)
}
},
[6] = {
.ncmp = 1,
.type = GL_FLOAT,
.vbo_chunk_index = VBO_STREAM_TYPE_INSTANCE,
.interleaved = {
.offset = offsetof(ui_attr_t, corner_radius),
.stride = sizeof(ui_attr_t)
}
}
}
}
},
}
}
});
list_clear(&self->gfx.instanced_attrs);
gui__internal_reset_internals(self);
}
void gui_set_composition(gui_t * const self, ui_composition callback)
{
self->callback = callback;
}
bool gui_ui_mouse_lock_release(gui_t *const self, const u32 id)
{
return self->internal.mouse_lock_on_ui.last_mouseclick_released_ui_id == id;
}
bool gui_ui_mouse_on_drag_release(gui_t *const self)
{
return self->internal.mouse_lock_on_ui.last_mouseclick_released_ui_id > 0;
}
bool gui_is_mouse_captured(const gui_t *const gui)
{
return gui->state.hovered_ui_id != 0 || gui->internal.mouse_lock_on_ui.ui_id != 0;
}
bool gui_ui_ishovered(gui_t *const self, const u32 id)
{
return self->state.hovered_ui_id != 0 && self->state.hovered_ui_id == id;
}
bool gui_ui_isclicked(gui_t *const self, const u32 id)
{
ASSERT(global_window);
return gui_ui_ishovered(self, id) && window_mouse_button_just_pressed(global_window, SDL_MOUSEBUTTON_LEFT);
}
#endif