diff options
| author | 3gg <3gg@shellblade.net> | 2026-03-25 19:59:14 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-03-25 19:59:14 -0700 |
| commit | 4152fbecb6ee8360575aa4c24e9cedf822f159dc (patch) | |
| tree | 9e9b9db0216a37c5867d472a65289502c459691f /include | |
| parent | 7778755c20e779554cd654ecdf7404d37b723fcc (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.h | 81 |
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. |
| 43 | typedef enum uiWidgetType { | 43 | typedef 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 | ||
| 51 | typedef struct uiButton uiButton; | 53 | typedef struct uiButton uiButton; |
| 54 | typedef struct uiEdit uiEdit; | ||
| 52 | typedef struct uiFrame uiFrame; | 55 | typedef struct uiFrame uiFrame; |
| 53 | typedef struct uiLabel uiLabel; | 56 | typedef struct uiLabel uiLabel; |
| 57 | typedef struct uiLayout uiLayout; | ||
| 54 | typedef struct uiTable uiTable; | 58 | typedef struct uiTable uiTable; |
| 55 | typedef struct uiWidget uiWidget; | 59 | typedef 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. | ||
| 76 | typedef 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. | ||
| 87 | typedef enum uiStretch { | ||
| 88 | uiStretchNone = 0, | ||
| 89 | uiStretchX = 1, | ||
| 90 | uiStretchY = 2, | ||
| 91 | } uiStretch; | ||
| 92 | |||
| 69 | /// Mouse button. | 93 | /// Mouse button. |
| 70 | typedef enum uiMouseButton { | 94 | typedef 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. | ||
| 173 | typedef struct uiParams { | ||
| 174 | uiStretch stretch; | ||
| 175 | } uiParams; | ||
| 176 | |||
| 148 | // ----------------------------------------------------------------------------- | 177 | // ----------------------------------------------------------------------------- |
| 149 | // Library. | 178 | // Library. |
| 150 | 179 | ||
| @@ -152,50 +181,55 @@ bool uiInit(void); | |||
| 152 | void uiShutdown(void); | 181 | void uiShutdown(void); |
| 153 | 182 | ||
| 154 | // ----------------------------------------------------------------------------- | 183 | // ----------------------------------------------------------------------------- |
| 155 | // Widget pointers. | 184 | // Widget. |
| 156 | 185 | ||
| 157 | uiPtr uiMakeButtonPtr(uiButton*); | 186 | uiPtr uiMakeButtonPtr(uiButton*); |
| 187 | uiPtr uiMakeEditPtr(uiEdit*); | ||
| 158 | uiPtr uiMakeFramePtr(uiFrame*); | 188 | uiPtr uiMakeFramePtr(uiFrame*); |
| 159 | uiPtr uiMakeLabelPtr(uiLabel*); | 189 | uiPtr uiMakeLabelPtr(uiLabel*); |
| 190 | uiPtr uiMakeLayoutPtr(uiLayout*); | ||
| 160 | uiPtr uiMakeTablePtr(uiTable*); | 191 | uiPtr uiMakeTablePtr(uiTable*); |
| 161 | uiPtr uiMakeWidgetPtr(uiWidget*); | 192 | uiPtr uiMakeWidgetPtr(uiWidget*); |
| 162 | uiPtr uiNullptr(void); | 193 | uiPtr uiNullptr(void); |
| 163 | bool uiIsNullptr(uiPtr ptr); | 194 | bool uiIsNullptr(uiPtr); |
| 164 | 195 | ||
| 165 | uiButton* uiGetButtonPtr(uiPtr ptr); | 196 | uiButton* uiGetButtonPtr(uiPtr); |
| 166 | uiFrame* uiGetFramePtr(uiPtr ptr); | 197 | uiEdit* uiGetEditPtr(uiPtr); |
| 167 | uiLabel* uiGetLabelPtr(uiPtr ptr); | 198 | uiFrame* uiGetFramePtr(uiPtr); |
| 168 | uiTable* uiGetTablePtr(uiPtr ptr); | 199 | uiLabel* uiGetLabelPtr(uiPtr); |
| 169 | 200 | uiLayout* uiGetLayoutPtr(uiPtr); | |
| 170 | // ----------------------------------------------------------------------------- | 201 | uiTable* uiGetTablePtr(uiPtr); |
| 171 | // Widget. | ||
| 172 | 202 | ||
| 173 | uiWidgetType uiWidgetGetType(const uiWidget*); | 203 | uiWidgetType uiWidgetGetType(const uiWidget*); |
| 174 | void uiWidgetSetParent(uiPtr child, uiPtr parent); | ||
| 175 | |||
| 176 | // ----------------------------------------------------------------------------- | ||
| 177 | // Button. | ||
| 178 | 204 | ||
| 179 | uiButton* uiMakeButton(const char* text); | 205 | void uiPrint(uiPtr); |
| 180 | 206 | ||
| 181 | // ----------------------------------------------------------------------------- | 207 | // ----------------------------------------------------------------------------- |
| 182 | // Frame. | 208 | // Frame. |
| 183 | 209 | ||
| 184 | uiFrame* uiMakeFrame(void); | 210 | uiFrame* uiMakeFrame(void); |
| 185 | void uiDestroyFrame(uiFrame**); | 211 | void uiDestroyFrame(uiFrame**); |
| 186 | void uiResizeFrame(uiFrame*, int width, int height); | ||
| 187 | uiSize uiGetFrameSize(const uiFrame*); | 212 | uiSize uiGetFrameSize(const uiFrame*); |
| 188 | 213 | ||
| 189 | // ----------------------------------------------------------------------------- | 214 | // ----------------------------------------------------------------------------- |
| 215 | // Layout. | ||
| 216 | uiLayout* uiMakeLayout(uiPtr parent, uiLayoutDirection); | ||
| 217 | |||
| 218 | // ----------------------------------------------------------------------------- | ||
| 219 | // Button. | ||
| 220 | |||
| 221 | uiButton* uiMakeButton(uiPtr parent, const char* text, const uiParams*); | ||
| 222 | |||
| 223 | // ----------------------------------------------------------------------------- | ||
| 190 | // Label. | 224 | // Label. |
| 191 | 225 | ||
| 192 | uiLabel* uiMakeLabel(const char* text); | 226 | uiLabel* uiMakeLabel(uiPtr parent, const char* text); |
| 193 | const char* uiLabelGetText(const uiLabel*); | 227 | const char* uiLabelGetText(const uiLabel*); |
| 194 | 228 | ||
| 195 | // ----------------------------------------------------------------------------- | 229 | // ----------------------------------------------------------------------------- |
| 196 | // Table. | 230 | // Table. |
| 197 | 231 | ||
| 198 | uiTable* uiMakeTable(int rows, int cols, const char** header); | 232 | uiTable* uiMakeTable(uiPtr parent, int rows, int cols, const char** header); |
| 199 | void uiTableClear(uiTable*); | 233 | void uiTableClear(uiTable*); |
| 200 | void uiTableAddRow(uiTable*, const char** row); | 234 | void uiTableAddRow(uiTable*, const char** row); |
| 201 | void uiTableSet(uiTable*, int row, int col, const char* text); | 235 | void uiTableSet(uiTable*, int row, int col, const char* text); |
| @@ -203,12 +237,20 @@ const char* uiTableGet(const uiTable*, int row, int col); | |||
| 203 | void uiTableScroll(uiTable*, int row); | 237 | void 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. | ||
| 245 | void uiLayOut(uiFrame*, int width, int height); | ||
| 246 | |||
| 247 | // ----------------------------------------------------------------------------- | ||
| 206 | // Rendering. | 248 | // Rendering. |
| 207 | 249 | ||
| 208 | void uiRender(const uiFrame*, uiSurface*); | 250 | void 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. |
| 219 | int uiGetEvents(uiWidgetEvent const**); | 261 | int 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. |
| 226 | bool uiSendEvent(uiFrame*, const uiInputEvent*); | 265 | bool uiSendEvent(uiFrame*, const uiInputEvent*); |
