diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ui.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/include/ui.h b/include/ui.h new file mode 100644 index 0000000..43bb2e7 --- /dev/null +++ b/include/ui.h | |||
@@ -0,0 +1,136 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <stdbool.h> | ||
4 | #include <stdint.h> | ||
5 | |||
6 | typedef uint8_t uiChannel; | ||
7 | |||
8 | typedef struct uiPixel { | ||
9 | uiChannel r, g, b, a; | ||
10 | } uiPixel; | ||
11 | |||
12 | typedef struct uiSize { | ||
13 | int width; | ||
14 | int height; | ||
15 | } uiSize; | ||
16 | |||
17 | /// A UI surface to which widgets are rendered. | ||
18 | typedef struct uiSurface { | ||
19 | int width; | ||
20 | int height; | ||
21 | uiPixel* pixels; | ||
22 | } uiSurface; | ||
23 | |||
24 | /// Rectangle. | ||
25 | /// (x,y) is the top-left corner. | ||
26 | typedef struct uiRect { | ||
27 | int x; | ||
28 | int y; | ||
29 | int width; | ||
30 | int height; | ||
31 | } uiRect; | ||
32 | |||
33 | /// Point. | ||
34 | typedef struct uiPoint { | ||
35 | int x; | ||
36 | int y; | ||
37 | } uiPoint; | ||
38 | |||
39 | /// Widget type. | ||
40 | typedef enum uiWidgetType { | ||
41 | uiTypeButton, | ||
42 | uiTypeFrame, | ||
43 | uiTypeLabel, | ||
44 | uiTypeTable, | ||
45 | uiTypeMax, | ||
46 | } uiWidgetType; | ||
47 | |||
48 | typedef struct uiButton uiButton; | ||
49 | typedef struct uiFrame uiFrame; | ||
50 | typedef struct uiLabel uiLabel; | ||
51 | typedef struct uiTable uiTable; | ||
52 | typedef struct uiWidget uiWidget; | ||
53 | |||
54 | /// Widget pointer. | ||
55 | typedef struct uiWidgetPtr { | ||
56 | uiWidgetType type; | ||
57 | union { | ||
58 | uiButton* button; | ||
59 | uiFrame* frame; | ||
60 | uiLabel* label; | ||
61 | uiTable* table; | ||
62 | uiWidget* widget; | ||
63 | }; | ||
64 | } uiWidgetPtr; | ||
65 | |||
66 | // ----------------------------------------------------------------------------- | ||
67 | // Library. | ||
68 | |||
69 | /// Initialize the UI library. | ||
70 | /// This should be called once during application startup. | ||
71 | bool uiInit(void); | ||
72 | |||
73 | /// Shutdown the UI library. | ||
74 | /// This should be called once during application shutdown. | ||
75 | void uiShutdown(void); | ||
76 | |||
77 | // ----------------------------------------------------------------------------- | ||
78 | // Widget. | ||
79 | |||
80 | uiWidgetPtr uiMakeButtonPtr(uiButton*); | ||
81 | uiWidgetPtr uiMakeFramePtr(uiFrame*); | ||
82 | uiWidgetPtr uiMakeLabelPtr(uiLabel*); | ||
83 | uiWidgetPtr uiMakeTablePtr(uiTable*); | ||
84 | |||
85 | void uiWidgetSetParent(uiWidgetPtr child, uiWidgetPtr parent); | ||
86 | |||
87 | // ----------------------------------------------------------------------------- | ||
88 | // Button. | ||
89 | |||
90 | /// Create a button. | ||
91 | uiButton* uiMakeButton(const char* text); | ||
92 | |||
93 | // ----------------------------------------------------------------------------- | ||
94 | // Frame. | ||
95 | |||
96 | /// Create a frame. | ||
97 | uiFrame* uiMakeFrame(void); | ||
98 | |||
99 | /// Destroy the frame. | ||
100 | void uiDestroyFrame(uiFrame**); | ||
101 | |||
102 | /// Resize the frame. | ||
103 | void uiResizeFrame(uiFrame*, int width, int height); | ||
104 | |||
105 | /// Get the frame's dimensions. | ||
106 | uiSize uiGetFrameSize(const uiFrame*); | ||
107 | |||
108 | // ----------------------------------------------------------------------------- | ||
109 | // Label. | ||
110 | |||
111 | /// Create a label. | ||
112 | uiLabel* uiMakeLabel(const char* text); | ||
113 | |||
114 | // ----------------------------------------------------------------------------- | ||
115 | // Table. | ||
116 | |||
117 | /// Create a table. | ||
118 | uiTable* uiMakeTable(int rows, int cols, const char** header); | ||
119 | |||
120 | /// Add a row. | ||
121 | void uiTableAddRow(uiTable*, const char** row); | ||
122 | |||
123 | /// Set the table's cell. | ||
124 | void uiTableSet(uiTable*, int row, int col, uiWidgetPtr widget); | ||
125 | |||
126 | /// Get the table's cell. | ||
127 | const uiWidget* uiTableGet(const uiTable*, int row, int col); | ||
128 | |||
129 | /// Get the table's cell. | ||
130 | uiWidget* uiTableGetMut(uiTable*, int row, int col); | ||
131 | |||
132 | // ----------------------------------------------------------------------------- | ||
133 | // Rendering. | ||
134 | |||
135 | /// Render the frame. | ||
136 | void uiRender(const uiFrame*, uiSurface*); | ||