summaryrefslogtreecommitdiff
path: root/src/widget/widget.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-07-13 10:52:24 -0700
committer3gg <3gg@shellblade.net>2024-07-13 10:52:24 -0700
commita4294e4a94189dffb1fdf99c9a60d87d77272926 (patch)
tree2e92f7c95116861bc39f4dae1d0ab5d388550000 /src/widget/widget.c
parentcf9579d7546c04dbc708bd8719e3f935a28088bd (diff)
Restructure project.
Diffstat (limited to 'src/widget/widget.c')
-rw-r--r--src/widget/widget.c93
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
18uiWidgetType uiWidgetGetType(const uiWidget* widget) {
19 assert(widget);
20 return widget->type;
21}
22
23void 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
33void 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
46uiPtr uiMakeButtonPtr(uiButton* button) {
47 assert(button);
48 return (uiPtr){.type = uiTypeButton, .button = button};
49}
50
51uiPtr uiMakeFramePtr(uiFrame* frame) {
52 assert(frame);
53 return (uiPtr){.type = uiTypeFrame, .frame = frame};
54}
55
56uiPtr uiMakeLabelPtr(uiLabel* label) {
57 assert(label);
58 return (uiPtr){.type = uiTypeLabel, .label = label};
59}
60
61uiPtr uiMakeTablePtr(uiTable* table) {
62 assert(table);
63 return (uiPtr){.type = uiTypeTable, .table = table};
64}
65
66static uiPtr uiMakeWidgetPtr(uiWidget* widget) {
67 assert(widget);
68 return (uiPtr){.type = widget->type, .widget = widget};
69}
70
71uiButton* uiGetButtonPtr(uiPtr ptr) {
72 assert(ptr.type == uiTypeButton);
73 assert(ptr.button);
74 return ptr.button;
75}
76
77uiFrame* uiGetFramePtr(uiPtr ptr) {
78 assert(ptr.type == uiTypeFrame);
79 assert(ptr.frame);
80 return ptr.frame;
81}
82
83uiLabel* uiGetLabelPtr(uiPtr ptr) {
84 assert(ptr.type == uiTypeLabel);
85 assert(ptr.label);
86 return ptr.label;
87}
88
89uiTable* uiGetTablePtr(uiPtr ptr) {
90 assert(ptr.type == uiTypeTable);
91 assert(ptr.table);
92 return ptr.table;
93}