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