summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2026-03-25 19:59:14 -0700
committer3gg <3gg@shellblade.net>2026-03-25 19:59:14 -0700
commit4152fbecb6ee8360575aa4c24e9cedf822f159dc (patch)
tree9e9b9db0216a37c5867d472a65289502c459691f /include
parent7778755c20e779554cd654ecdf7404d37b723fcc (diff)
Implement vertical and horizontal layouts. Use widget position properly when rendering. Toolbar, buttons and edit bars WIPmain
Diffstat (limited to 'include')
-rw-r--r--include/ui.h81
1 files changed, 60 insertions, 21 deletions
diff --git a/include/ui.h b/include/ui.h
index baaa550..b70df59 100644
--- a/include/ui.h
+++ b/include/ui.h
@@ -42,15 +42,19 @@ typedef int uiWidgetId;
42/// Widget type. 42/// Widget type.
43typedef enum uiWidgetType { 43typedef enum uiWidgetType {
44 uiTypeButton, 44 uiTypeButton,
45 uiTypeEdit,
45 uiTypeFrame, 46 uiTypeFrame,
46 uiTypeLabel, 47 uiTypeLabel,
48 uiTypeLayout,
47 uiTypeTable, 49 uiTypeTable,
48 uiTypeMax, 50 uiTypeMax,
49} uiWidgetType; 51} uiWidgetType;
50 52
51typedef struct uiButton uiButton; 53typedef struct uiButton uiButton;
54typedef struct uiEdit uiEdit;
52typedef struct uiFrame uiFrame; 55typedef struct uiFrame uiFrame;
53typedef struct uiLabel uiLabel; 56typedef struct uiLabel uiLabel;
57typedef struct uiLayout uiLayout;
54typedef struct uiTable uiTable; 58typedef struct uiTable uiTable;
55typedef struct uiWidget uiWidget; 59typedef struct uiWidget uiWidget;
56 60
@@ -59,13 +63,33 @@ typedef struct uiPtr {
59 uiWidgetType type; 63 uiWidgetType type;
60 union { 64 union {
61 uiButton* button; 65 uiButton* button;
66 uiEdit* edit;
62 uiFrame* frame; 67 uiFrame* frame;
63 uiLabel* label; 68 uiLabel* label;
69 uiLayout* layout;
64 uiTable* table; 70 uiTable* table;
65 uiWidget* widget; 71 uiWidget* widget;
66 }; 72 };
67} uiPtr; 73} uiPtr;
68 74
75/// Direction in which a layout widget lays out its children.
76typedef enum uiLayoutDirection {
77 uiVertical,
78 uiHorizontal,
79} uiLayoutDirection;
80
81/// Directions in which a widget stretches.
82///
83/// Stretch determines how the widget occupies the area of its parent widget.
84///
85/// uiStretchNone - the widget has a fixed size.
86/// uiStretchX/Y - the widget stretches in the X/Y direction.
87typedef enum uiStretch {
88 uiStretchNone = 0,
89 uiStretchX = 1,
90 uiStretchY = 2,
91} uiStretch;
92
69/// Mouse button. 93/// Mouse button.
70typedef enum uiMouseButton { 94typedef enum uiMouseButton {
71 uiLMB, 95 uiLMB,
@@ -145,6 +169,11 @@ typedef struct uiWidgetEvent {
145 }; 169 };
146} uiWidgetEvent; 170} uiWidgetEvent;
147 171
172/// Common construction parameters for widgets.
173typedef struct uiParams {
174 uiStretch stretch;
175} uiParams;
176
148// ----------------------------------------------------------------------------- 177// -----------------------------------------------------------------------------
149// Library. 178// Library.
150 179
@@ -152,50 +181,55 @@ bool uiInit(void);
152void uiShutdown(void); 181void uiShutdown(void);
153 182
154// ----------------------------------------------------------------------------- 183// -----------------------------------------------------------------------------
155// Widget pointers. 184// Widget.
156 185
157uiPtr uiMakeButtonPtr(uiButton*); 186uiPtr uiMakeButtonPtr(uiButton*);
187uiPtr uiMakeEditPtr(uiEdit*);
158uiPtr uiMakeFramePtr(uiFrame*); 188uiPtr uiMakeFramePtr(uiFrame*);
159uiPtr uiMakeLabelPtr(uiLabel*); 189uiPtr uiMakeLabelPtr(uiLabel*);
190uiPtr uiMakeLayoutPtr(uiLayout*);
160uiPtr uiMakeTablePtr(uiTable*); 191uiPtr uiMakeTablePtr(uiTable*);
161uiPtr uiMakeWidgetPtr(uiWidget*); 192uiPtr uiMakeWidgetPtr(uiWidget*);
162uiPtr uiNullptr(void); 193uiPtr uiNullptr(void);
163bool uiIsNullptr(uiPtr ptr); 194bool uiIsNullptr(uiPtr);
164 195
165uiButton* uiGetButtonPtr(uiPtr ptr); 196uiButton* uiGetButtonPtr(uiPtr);
166uiFrame* uiGetFramePtr(uiPtr ptr); 197uiEdit* uiGetEditPtr(uiPtr);
167uiLabel* uiGetLabelPtr(uiPtr ptr); 198uiFrame* uiGetFramePtr(uiPtr);
168uiTable* uiGetTablePtr(uiPtr ptr); 199uiLabel* uiGetLabelPtr(uiPtr);
169 200uiLayout* uiGetLayoutPtr(uiPtr);
170// ----------------------------------------------------------------------------- 201uiTable* uiGetTablePtr(uiPtr);
171// Widget.
172 202
173uiWidgetType uiWidgetGetType(const uiWidget*); 203uiWidgetType uiWidgetGetType(const uiWidget*);
174void uiWidgetSetParent(uiPtr child, uiPtr parent);
175
176// -----------------------------------------------------------------------------
177// Button.
178 204
179uiButton* uiMakeButton(const char* text); 205void uiPrint(uiPtr);
180 206
181// ----------------------------------------------------------------------------- 207// -----------------------------------------------------------------------------
182// Frame. 208// Frame.
183 209
184uiFrame* uiMakeFrame(void); 210uiFrame* uiMakeFrame(void);
185void uiDestroyFrame(uiFrame**); 211void uiDestroyFrame(uiFrame**);
186void uiResizeFrame(uiFrame*, int width, int height);
187uiSize uiGetFrameSize(const uiFrame*); 212uiSize uiGetFrameSize(const uiFrame*);
188 213
189// ----------------------------------------------------------------------------- 214// -----------------------------------------------------------------------------
215// Layout.
216uiLayout* uiMakeLayout(uiPtr parent, uiLayoutDirection);
217
218// -----------------------------------------------------------------------------
219// Button.
220
221uiButton* uiMakeButton(uiPtr parent, const char* text, const uiParams*);
222
223// -----------------------------------------------------------------------------
190// Label. 224// Label.
191 225
192uiLabel* uiMakeLabel(const char* text); 226uiLabel* uiMakeLabel(uiPtr parent, const char* text);
193const char* uiLabelGetText(const uiLabel*); 227const char* uiLabelGetText(const uiLabel*);
194 228
195// ----------------------------------------------------------------------------- 229// -----------------------------------------------------------------------------
196// Table. 230// Table.
197 231
198uiTable* uiMakeTable(int rows, int cols, const char** header); 232uiTable* uiMakeTable(uiPtr parent, int rows, int cols, const char** header);
199void uiTableClear(uiTable*); 233void uiTableClear(uiTable*);
200void uiTableAddRow(uiTable*, const char** row); 234void uiTableAddRow(uiTable*, const char** row);
201void uiTableSet(uiTable*, int row, int col, const char* text); 235void uiTableSet(uiTable*, int row, int col, const char* text);
@@ -203,12 +237,20 @@ const char* uiTableGet(const uiTable*, int row, int col);
203void uiTableScroll(uiTable*, int row); 237void uiTableScroll(uiTable*, int row);
204 238
205// ----------------------------------------------------------------------------- 239// -----------------------------------------------------------------------------
240// Layout.
241
242/// Lay out the widgets in the frame given the frame's new width and height.
243///
244/// This should typically be called whenever the window is resized.
245void uiLayOut(uiFrame*, int width, int height);
246
247// -----------------------------------------------------------------------------
206// Rendering. 248// Rendering.
207 249
208void uiRender(const uiFrame*, uiSurface*); 250void uiRender(const uiFrame*, uiSurface*);
209 251
210// ----------------------------------------------------------------------------- 252// -----------------------------------------------------------------------------
211// UI Events. 253// UI and user events.
212 254
213/// Get the widget events. 255/// Get the widget events.
214/// Return the number of events in the returned array. 256/// Return the number of events in the returned array.
@@ -218,9 +260,6 @@ void uiRender(const uiFrame*, uiSurface*);
218/// therefore report zero widget events. 260/// therefore report zero widget events.
219int uiGetEvents(uiWidgetEvent const**); 261int uiGetEvents(uiWidgetEvent const**);
220 262
221// -----------------------------------------------------------------------------
222// User input.
223
224/// Send an input event to the UI. 263/// Send an input event to the UI.
225/// Return true if the UI requires a redraw. 264/// Return true if the UI requires a redraw.
226bool uiSendEvent(uiFrame*, const uiInputEvent*); 265bool uiSendEvent(uiFrame*, const uiInputEvent*);