diff options
author | 3gg <3gg@shellblade.net> | 2024-07-13 10:52:24 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-07-13 10:52:24 -0700 |
commit | a4294e4a94189dffb1fdf99c9a60d87d77272926 (patch) | |
tree | 2e92f7c95116861bc39f4dae1d0ab5d388550000 /src/widget/widget.h | |
parent | cf9579d7546c04dbc708bd8719e3f935a28088bd (diff) |
Restructure project.
Diffstat (limited to 'src/widget/widget.h')
-rw-r--r-- | src/widget/widget.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/widget/widget.h b/src/widget/widget.h new file mode 100644 index 0000000..a2c96bc --- /dev/null +++ b/src/widget/widget.h | |||
@@ -0,0 +1,66 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <ui.h> | ||
4 | |||
5 | #include <cstring.h> | ||
6 | #include <list.h> | ||
7 | |||
8 | #include <stdbool.h> | ||
9 | |||
10 | DEF_LIST(Widget, uiWidget*) | ||
11 | |||
12 | #define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE)) | ||
13 | |||
14 | static inline void* uiAlloc(size_t count, size_t size) { | ||
15 | void* mem = calloc(count, size); | ||
16 | ASSERT(mem); | ||
17 | return mem; | ||
18 | } | ||
19 | |||
20 | // ----------------------------------------------------------------------------- | ||
21 | // Widgets. | ||
22 | |||
23 | /// Base widget type. | ||
24 | typedef struct uiWidget { | ||
25 | uiWidgetType type; | ||
26 | uiRect rect; | ||
27 | Widget_list children; | ||
28 | } uiWidget; | ||
29 | |||
30 | /// Button. | ||
31 | typedef struct uiButton { | ||
32 | uiWidget widget; | ||
33 | string text; | ||
34 | } uiButton; | ||
35 | |||
36 | /// Frame. | ||
37 | typedef struct uiFrame { | ||
38 | uiWidget widget; | ||
39 | } uiFrame; | ||
40 | |||
41 | /// Label. | ||
42 | typedef struct uiLabel { | ||
43 | uiWidget widget; | ||
44 | string text; | ||
45 | } uiLabel; | ||
46 | |||
47 | /// Table cell. | ||
48 | typedef struct uiCell { | ||
49 | uiWidget* child; | ||
50 | } uiCell; | ||
51 | |||
52 | /// Table. | ||
53 | typedef struct uiTable { | ||
54 | uiWidget widget; | ||
55 | int rows; | ||
56 | int cols; | ||
57 | int* widths; // Width, in pixels, for each column. | ||
58 | uiCell* header; // If non-null, row of 'cols' header cells. | ||
59 | uiCell** cells; // Array of 'rows' rows, each of 'cols' cells. | ||
60 | int offset; // Offset into the rows of the table. Units: rows. | ||
61 | struct { | ||
62 | bool vertical_overflow : 1; // True if contents overflow vertically. | ||
63 | } flags; | ||
64 | } uiTable; | ||
65 | |||
66 | void DestroyWidget(uiWidget** ppWidget); | ||