blob: ef79ac42fca47a384913e9078047d520be58c733 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include "widget.h"
#include <cassert.h>
// -----------------------------------------------------------------------------
// Widget.
#define UI_DEL(ppWidget) \
{ \
assert(ppWidget); \
void* widget_ = *ppWidget; \
if (widget_) { \
free(widget_); \
*ppWidget = 0; \
} \
}
uiWidgetType uiWidgetGetType(const uiWidget* widget) {
assert(widget);
return widget->type;
}
void DestroyWidget(uiWidget** ppWidget) {
assert(ppWidget);
uiWidget* widget = *ppWidget;
if (widget) {
list_foreach_mut(widget->children, child, { DestroyWidget(&child); });
}
UI_DEL(ppWidget);
}
void uiWidgetSetParent(uiPtr child_, uiPtr parent_) {
uiWidget* child = child_.widget;
uiWidget* parent = parent_.widget;
assert(child);
assert(parent);
list_add(parent->children, child);
}
// -----------------------------------------------------------------------------
// Widget pointers.
uiPtr uiMakeButtonPtr(uiButton* button) {
assert(button);
return (uiPtr){.type = uiTypeButton, .button = button};
}
uiPtr uiMakeFramePtr(uiFrame* frame) {
assert(frame);
return (uiPtr){.type = uiTypeFrame, .frame = frame};
}
uiPtr uiMakeLabelPtr(uiLabel* label) {
assert(label);
return (uiPtr){.type = uiTypeLabel, .label = label};
}
uiPtr uiMakeTablePtr(uiTable* table) {
assert(table);
return (uiPtr){.type = uiTypeTable, .table = table};
}
static uiPtr uiMakeWidgetPtr(uiWidget* widget) {
assert(widget);
return (uiPtr){.type = widget->type, .widget = widget};
}
uiButton* uiGetButtonPtr(uiPtr ptr) {
assert(ptr.type == uiTypeButton);
assert(ptr.button);
return ptr.button;
}
uiFrame* uiGetFramePtr(uiPtr ptr) {
assert(ptr.type == uiTypeFrame);
assert(ptr.frame);
return ptr.frame;
}
uiLabel* uiGetLabelPtr(uiPtr ptr) {
assert(ptr.type == uiTypeLabel);
assert(ptr.label);
return ptr.label;
}
uiTable* uiGetTablePtr(uiPtr ptr) {
assert(ptr.type == uiTypeTable);
assert(ptr.table);
return ptr.table;
}
|