summaryrefslogtreecommitdiff
path: root/src/widget/widget.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/widget/widget.h')
-rw-r--r--src/widget/widget.h66
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
10DEF_LIST(Widget, uiWidget*)
11
12#define UI_NEW(TYPE) (TYPE*)uiAlloc(1, sizeof(TYPE))
13
14static 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.
24typedef struct uiWidget {
25 uiWidgetType type;
26 uiRect rect;
27 Widget_list children;
28} uiWidget;
29
30/// Button.
31typedef struct uiButton {
32 uiWidget widget;
33 string text;
34} uiButton;
35
36/// Frame.
37typedef struct uiFrame {
38 uiWidget widget;
39} uiFrame;
40
41/// Label.
42typedef struct uiLabel {
43 uiWidget widget;
44 string text;
45} uiLabel;
46
47/// Table cell.
48typedef struct uiCell {
49 uiWidget* child;
50} uiCell;
51
52/// Table.
53typedef 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
66void DestroyWidget(uiWidget** ppWidget);