diff options
Diffstat (limited to 'src/widget/widget.c')
-rw-r--r-- | src/widget/widget.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/widget/widget.c b/src/widget/widget.c new file mode 100644 index 0000000..ef79ac4 --- /dev/null +++ b/src/widget/widget.c | |||
@@ -0,0 +1,93 @@ | |||
1 | #include "widget.h" | ||
2 | |||
3 | #include <cassert.h> | ||
4 | |||
5 | // ----------------------------------------------------------------------------- | ||
6 | // Widget. | ||
7 | |||
8 | #define UI_DEL(ppWidget) \ | ||
9 | { \ | ||
10 | assert(ppWidget); \ | ||
11 | void* widget_ = *ppWidget; \ | ||
12 | if (widget_) { \ | ||
13 | free(widget_); \ | ||
14 | *ppWidget = 0; \ | ||
15 | } \ | ||
16 | } | ||
17 | |||
18 | uiWidgetType uiWidgetGetType(const uiWidget* widget) { | ||
19 | assert(widget); | ||
20 | return widget->type; | ||
21 | } | ||
22 | |||
23 | void DestroyWidget(uiWidget** ppWidget) { | ||
24 | assert(ppWidget); | ||
25 | |||
26 | uiWidget* widget = *ppWidget; | ||
27 | if (widget) { | ||
28 | list_foreach_mut(widget->children, child, { DestroyWidget(&child); }); | ||
29 | } | ||
30 | UI_DEL(ppWidget); | ||
31 | } | ||
32 | |||
33 | void uiWidgetSetParent(uiPtr child_, uiPtr parent_) { | ||
34 | uiWidget* child = child_.widget; | ||
35 | uiWidget* parent = parent_.widget; | ||
36 | |||
37 | assert(child); | ||
38 | assert(parent); | ||
39 | |||
40 | list_add(parent->children, child); | ||
41 | } | ||
42 | |||
43 | // ----------------------------------------------------------------------------- | ||
44 | // Widget pointers. | ||
45 | |||
46 | uiPtr uiMakeButtonPtr(uiButton* button) { | ||
47 | assert(button); | ||
48 | return (uiPtr){.type = uiTypeButton, .button = button}; | ||
49 | } | ||
50 | |||
51 | uiPtr uiMakeFramePtr(uiFrame* frame) { | ||
52 | assert(frame); | ||
53 | return (uiPtr){.type = uiTypeFrame, .frame = frame}; | ||
54 | } | ||
55 | |||
56 | uiPtr uiMakeLabelPtr(uiLabel* label) { | ||
57 | assert(label); | ||
58 | return (uiPtr){.type = uiTypeLabel, .label = label}; | ||
59 | } | ||
60 | |||
61 | uiPtr uiMakeTablePtr(uiTable* table) { | ||
62 | assert(table); | ||
63 | return (uiPtr){.type = uiTypeTable, .table = table}; | ||
64 | } | ||
65 | |||
66 | static uiPtr uiMakeWidgetPtr(uiWidget* widget) { | ||
67 | assert(widget); | ||
68 | return (uiPtr){.type = widget->type, .widget = widget}; | ||
69 | } | ||
70 | |||
71 | uiButton* uiGetButtonPtr(uiPtr ptr) { | ||
72 | assert(ptr.type == uiTypeButton); | ||
73 | assert(ptr.button); | ||
74 | return ptr.button; | ||
75 | } | ||
76 | |||
77 | uiFrame* uiGetFramePtr(uiPtr ptr) { | ||
78 | assert(ptr.type == uiTypeFrame); | ||
79 | assert(ptr.frame); | ||
80 | return ptr.frame; | ||
81 | } | ||
82 | |||
83 | uiLabel* uiGetLabelPtr(uiPtr ptr) { | ||
84 | assert(ptr.type == uiTypeLabel); | ||
85 | assert(ptr.label); | ||
86 | return ptr.label; | ||
87 | } | ||
88 | |||
89 | uiTable* uiGetTablePtr(uiPtr ptr) { | ||
90 | assert(ptr.type == uiTypeTable); | ||
91 | assert(ptr.table); | ||
92 | return ptr.table; | ||
93 | } | ||