diff options
author | 3gg <3gg@shellblade.net> | 2024-06-22 13:23:42 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-06-22 13:23:42 -0700 |
commit | 2f2d42e28a14cdc856f8cf0c45cd572646be6750 (patch) | |
tree | 441d759cc8a34898aef2d33686b925c0ff27bd23 /include/ui.h | |
parent | af641426fad35cd857c1f14bda523db3d85a70cd (diff) |
Table user input.
Diffstat (limited to 'include/ui.h')
-rw-r--r-- | include/ui.h | 124 |
1 files changed, 116 insertions, 8 deletions
diff --git a/include/ui.h b/include/ui.h index 43bb2e7..8570552 100644 --- a/include/ui.h +++ b/include/ui.h | |||
@@ -36,6 +36,9 @@ typedef struct uiPoint { | |||
36 | int y; | 36 | int y; |
37 | } uiPoint; | 37 | } uiPoint; |
38 | 38 | ||
39 | /// Widget ID. | ||
40 | typedef int uiWidgetId; | ||
41 | |||
39 | /// Widget type. | 42 | /// Widget type. |
40 | typedef enum uiWidgetType { | 43 | typedef enum uiWidgetType { |
41 | uiTypeButton, | 44 | uiTypeButton, |
@@ -52,7 +55,7 @@ typedef struct uiTable uiTable; | |||
52 | typedef struct uiWidget uiWidget; | 55 | typedef struct uiWidget uiWidget; |
53 | 56 | ||
54 | /// Widget pointer. | 57 | /// Widget pointer. |
55 | typedef struct uiWidgetPtr { | 58 | typedef struct uiPtr { |
56 | uiWidgetType type; | 59 | uiWidgetType type; |
57 | union { | 60 | union { |
58 | uiButton* button; | 61 | uiButton* button; |
@@ -61,7 +64,77 @@ typedef struct uiWidgetPtr { | |||
61 | uiTable* table; | 64 | uiTable* table; |
62 | uiWidget* widget; | 65 | uiWidget* widget; |
63 | }; | 66 | }; |
64 | } uiWidgetPtr; | 67 | } uiPtr; |
68 | |||
69 | /// Mouse button. | ||
70 | typedef enum uiMouseButton { | ||
71 | uiLMB, | ||
72 | uiRMB, | ||
73 | uiMouseButtonMax, | ||
74 | } uiMouseButton; | ||
75 | |||
76 | /// Mouse button state. | ||
77 | typedef enum uiMouseButtonState { | ||
78 | uiMouseUp, | ||
79 | uiMouseDown, | ||
80 | } uiMouseButtonState; | ||
81 | |||
82 | /// Mouse button event. | ||
83 | typedef struct uiMouseButtonEvent { | ||
84 | uiMouseButton button; | ||
85 | uiMouseButtonState state; | ||
86 | uiPoint mouse_position; | ||
87 | } uiMouseButtonEvent; | ||
88 | |||
89 | /// Mouse click event. | ||
90 | typedef struct uiMouseClickEvent { | ||
91 | uiMouseButton button; | ||
92 | uiPoint mouse_position; | ||
93 | } uiMouseClickEvent; | ||
94 | |||
95 | /// Mouse scroll event. | ||
96 | typedef struct uiMouseScrollEvent { | ||
97 | uiPoint mouse_position; | ||
98 | int scroll_offset; /// Positive = down; negative = up. | ||
99 | } uiMouseScrollEvent; | ||
100 | |||
101 | /// Input event type. | ||
102 | typedef enum uiInputEventType { | ||
103 | uiEventMouseButton, | ||
104 | uiEventMouseClick, | ||
105 | uiEventMouseScroll, | ||
106 | } uiInputEventType; | ||
107 | |||
108 | /// Input event. | ||
109 | typedef struct uiInputEvent { | ||
110 | uiInputEventType type; | ||
111 | union { | ||
112 | uiMouseButtonEvent mouse_button; | ||
113 | uiMouseClickEvent mouse_click; | ||
114 | uiMouseScrollEvent mouse_scroll; | ||
115 | }; | ||
116 | } uiInputEvent; | ||
117 | |||
118 | /// Table click event. | ||
119 | typedef struct uiTableClickEvent { | ||
120 | int col; | ||
121 | int row; | ||
122 | } uiTableClickEvent; | ||
123 | |||
124 | /// UI event type. | ||
125 | typedef enum uiWidgetEventType { | ||
126 | uiWidgetEventClick, | ||
127 | } uiWidgetEventType; | ||
128 | |||
129 | /// UI event. | ||
130 | /// These are events from the UI widgets back to the client application. | ||
131 | typedef struct uiWidgetEvent { | ||
132 | uiWidgetEventType type; | ||
133 | uiPtr widget; | ||
134 | union { | ||
135 | uiTableClickEvent table_click; | ||
136 | }; | ||
137 | } uiWidgetEvent; | ||
65 | 138 | ||
66 | // ----------------------------------------------------------------------------- | 139 | // ----------------------------------------------------------------------------- |
67 | // Library. | 140 | // Library. |
@@ -75,14 +148,24 @@ bool uiInit(void); | |||
75 | void uiShutdown(void); | 148 | void uiShutdown(void); |
76 | 149 | ||
77 | // ----------------------------------------------------------------------------- | 150 | // ----------------------------------------------------------------------------- |
151 | // Widget pointers. | ||
152 | |||
153 | uiPtr uiMakeButtonPtr(uiButton*); | ||
154 | uiPtr uiMakeFramePtr(uiFrame*); | ||
155 | uiPtr uiMakeLabelPtr(uiLabel*); | ||
156 | uiPtr uiMakeTablePtr(uiTable*); | ||
157 | |||
158 | uiButton* uiGetButtonPtr(uiPtr ptr); | ||
159 | uiFrame* uiGetFramePtr(uiPtr ptr); | ||
160 | uiLabel* uiGetLabelPtr(uiPtr ptr); | ||
161 | uiTable* uiGetTablePtr(uiPtr ptr); | ||
162 | |||
163 | // ----------------------------------------------------------------------------- | ||
78 | // Widget. | 164 | // Widget. |
79 | 165 | ||
80 | uiWidgetPtr uiMakeButtonPtr(uiButton*); | 166 | uiWidgetType uiWidgetGetType(const uiWidget*); |
81 | uiWidgetPtr uiMakeFramePtr(uiFrame*); | ||
82 | uiWidgetPtr uiMakeLabelPtr(uiLabel*); | ||
83 | uiWidgetPtr uiMakeTablePtr(uiTable*); | ||
84 | 167 | ||
85 | void uiWidgetSetParent(uiWidgetPtr child, uiWidgetPtr parent); | 168 | void uiWidgetSetParent(uiPtr child, uiPtr parent); |
86 | 169 | ||
87 | // ----------------------------------------------------------------------------- | 170 | // ----------------------------------------------------------------------------- |
88 | // Button. | 171 | // Button. |
@@ -111,17 +194,24 @@ uiSize uiGetFrameSize(const uiFrame*); | |||
111 | /// Create a label. | 194 | /// Create a label. |
112 | uiLabel* uiMakeLabel(const char* text); | 195 | uiLabel* uiMakeLabel(const char* text); |
113 | 196 | ||
197 | /// Return the label's text. | ||
198 | const char* uiLabelGetText(const uiLabel*); | ||
199 | |||
114 | // ----------------------------------------------------------------------------- | 200 | // ----------------------------------------------------------------------------- |
115 | // Table. | 201 | // Table. |
116 | 202 | ||
117 | /// Create a table. | 203 | /// Create a table. |
118 | uiTable* uiMakeTable(int rows, int cols, const char** header); | 204 | uiTable* uiMakeTable(int rows, int cols, const char** header); |
119 | 205 | ||
206 | /// Clear the table. | ||
207 | /// This clears the contents, but not the header. | ||
208 | void uiTableClear(uiTable*); | ||
209 | |||
120 | /// Add a row. | 210 | /// Add a row. |
121 | void uiTableAddRow(uiTable*, const char** row); | 211 | void uiTableAddRow(uiTable*, const char** row); |
122 | 212 | ||
123 | /// Set the table's cell. | 213 | /// Set the table's cell. |
124 | void uiTableSet(uiTable*, int row, int col, uiWidgetPtr widget); | 214 | void uiTableSet(uiTable*, int row, int col, uiPtr widget); |
125 | 215 | ||
126 | /// Get the table's cell. | 216 | /// Get the table's cell. |
127 | const uiWidget* uiTableGet(const uiTable*, int row, int col); | 217 | const uiWidget* uiTableGet(const uiTable*, int row, int col); |
@@ -134,3 +224,21 @@ uiWidget* uiTableGetMut(uiTable*, int row, int col); | |||
134 | 224 | ||
135 | /// Render the frame. | 225 | /// Render the frame. |
136 | void uiRender(const uiFrame*, uiSurface*); | 226 | void uiRender(const uiFrame*, uiSurface*); |
227 | |||
228 | // ----------------------------------------------------------------------------- | ||
229 | // UI Events. | ||
230 | |||
231 | /// Get the widget events. | ||
232 | /// Return the number of events in the returned array. | ||
233 | /// | ||
234 | /// This function clears the events recorded by the UI library since the last | ||
235 | /// input event. Subsequent calls to this function, with no further user input, | ||
236 | /// therefore report zero widget events. | ||
237 | int uiGetEvents(uiWidgetEvent const**); | ||
238 | |||
239 | // ----------------------------------------------------------------------------- | ||
240 | // User input. | ||
241 | |||
242 | /// Send an input event to the UI. | ||
243 | /// Return true if the UI requires a redraw. | ||
244 | bool uiSendEvent(uiFrame*, const uiInputEvent*); | ||