summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-06-22 13:23:42 -0700
committer3gg <3gg@shellblade.net>2024-06-22 13:23:42 -0700
commit2f2d42e28a14cdc856f8cf0c45cd572646be6750 (patch)
tree441d759cc8a34898aef2d33686b925c0ff27bd23 /include
parentaf641426fad35cd857c1f14bda523db3d85a70cd (diff)
Table user input.
Diffstat (limited to 'include')
-rw-r--r--include/ui.h124
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.
40typedef int uiWidgetId;
41
39/// Widget type. 42/// Widget type.
40typedef enum uiWidgetType { 43typedef enum uiWidgetType {
41 uiTypeButton, 44 uiTypeButton,
@@ -52,7 +55,7 @@ typedef struct uiTable uiTable;
52typedef struct uiWidget uiWidget; 55typedef struct uiWidget uiWidget;
53 56
54/// Widget pointer. 57/// Widget pointer.
55typedef struct uiWidgetPtr { 58typedef 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.
70typedef enum uiMouseButton {
71 uiLMB,
72 uiRMB,
73 uiMouseButtonMax,
74} uiMouseButton;
75
76/// Mouse button state.
77typedef enum uiMouseButtonState {
78 uiMouseUp,
79 uiMouseDown,
80} uiMouseButtonState;
81
82/// Mouse button event.
83typedef struct uiMouseButtonEvent {
84 uiMouseButton button;
85 uiMouseButtonState state;
86 uiPoint mouse_position;
87} uiMouseButtonEvent;
88
89/// Mouse click event.
90typedef struct uiMouseClickEvent {
91 uiMouseButton button;
92 uiPoint mouse_position;
93} uiMouseClickEvent;
94
95/// Mouse scroll event.
96typedef struct uiMouseScrollEvent {
97 uiPoint mouse_position;
98 int scroll_offset; /// Positive = down; negative = up.
99} uiMouseScrollEvent;
100
101/// Input event type.
102typedef enum uiInputEventType {
103 uiEventMouseButton,
104 uiEventMouseClick,
105 uiEventMouseScroll,
106} uiInputEventType;
107
108/// Input event.
109typedef 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.
119typedef struct uiTableClickEvent {
120 int col;
121 int row;
122} uiTableClickEvent;
123
124/// UI event type.
125typedef enum uiWidgetEventType {
126 uiWidgetEventClick,
127} uiWidgetEventType;
128
129/// UI event.
130/// These are events from the UI widgets back to the client application.
131typedef 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);
75void uiShutdown(void); 148void uiShutdown(void);
76 149
77// ----------------------------------------------------------------------------- 150// -----------------------------------------------------------------------------
151// Widget pointers.
152
153uiPtr uiMakeButtonPtr(uiButton*);
154uiPtr uiMakeFramePtr(uiFrame*);
155uiPtr uiMakeLabelPtr(uiLabel*);
156uiPtr uiMakeTablePtr(uiTable*);
157
158uiButton* uiGetButtonPtr(uiPtr ptr);
159uiFrame* uiGetFramePtr(uiPtr ptr);
160uiLabel* uiGetLabelPtr(uiPtr ptr);
161uiTable* uiGetTablePtr(uiPtr ptr);
162
163// -----------------------------------------------------------------------------
78// Widget. 164// Widget.
79 165
80uiWidgetPtr uiMakeButtonPtr(uiButton*); 166uiWidgetType uiWidgetGetType(const uiWidget*);
81uiWidgetPtr uiMakeFramePtr(uiFrame*);
82uiWidgetPtr uiMakeLabelPtr(uiLabel*);
83uiWidgetPtr uiMakeTablePtr(uiTable*);
84 167
85void uiWidgetSetParent(uiWidgetPtr child, uiWidgetPtr parent); 168void 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.
112uiLabel* uiMakeLabel(const char* text); 195uiLabel* uiMakeLabel(const char* text);
113 196
197/// Return the label's text.
198const char* uiLabelGetText(const uiLabel*);
199
114// ----------------------------------------------------------------------------- 200// -----------------------------------------------------------------------------
115// Table. 201// Table.
116 202
117/// Create a table. 203/// Create a table.
118uiTable* uiMakeTable(int rows, int cols, const char** header); 204uiTable* uiMakeTable(int rows, int cols, const char** header);
119 205
206/// Clear the table.
207/// This clears the contents, but not the header.
208void uiTableClear(uiTable*);
209
120/// Add a row. 210/// Add a row.
121void uiTableAddRow(uiTable*, const char** row); 211void uiTableAddRow(uiTable*, const char** row);
122 212
123/// Set the table's cell. 213/// Set the table's cell.
124void uiTableSet(uiTable*, int row, int col, uiWidgetPtr widget); 214void uiTableSet(uiTable*, int row, int col, uiPtr widget);
125 215
126/// Get the table's cell. 216/// Get the table's cell.
127const uiWidget* uiTableGet(const uiTable*, int row, int col); 217const 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.
136void uiRender(const uiFrame*, uiSurface*); 226void 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.
237int 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.
244bool uiSendEvent(uiFrame*, const uiInputEvent*);