-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsxui.h
More file actions
324 lines (279 loc) · 12.6 KB
/
sxui.h
File metadata and controls
324 lines (279 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#ifndef SXUI_H
#define SXUI_H
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "dynamic_list.h"
// ============================================================================
// CORE TYPES & ENUMS
// ============================================================================
typedef enum { THEME_DARK, THEME_LIGHT } UIThemeMode;
typedef enum {
UI_FLAG_NONE = 0,
UI_FLAG_HIDDEN = 1 << 0,
UI_FLAG_PASSWORD = 1 << 1,
UI_FLAG_DRAGGABLE = 1 << 2,
UI_FLAG_CLIP = 1 << 3,
UI_LAYOUT_HORIZONTAL = 1 << 4,
UI_LAYOUT_GRID = 1 << 5,
UI_SCROLLABLE = 1 << 6,
UI_LAYOUT_VERTICAL = 1 << 7
} UIFlags;
typedef enum {
UI_BUTTON,
UI_LABEL,
UI_INPUT,
UI_CHECKBOX,
UI_FRAME,
UI_SLIDER,
UI_DROPDOWN,
UI_CANVAS
} UIType;
typedef struct UIElement UIElement;
typedef struct UIConnection {
int id;
list* parent_list;
} UIConnection;
typedef struct {
float position;
Uint32 color;
} GradientStop;
typedef struct {
int enabled;
list* stops;
float angle;
} UIGradient;
typedef struct {
int enabled;
int width;
Uint32 color;
Uint8 alpha;
} UIOutline;
typedef struct {
int enabled;
int radius;
} UIRoundedCorners;
typedef struct {
UIGradient gradient;
UIOutline outline;
UIRoundedCorners rounded;
} UIEffects;
<<<<<<< HEAD
typedef void (*ClickCallback)(void* element);
typedef void (*FocusCallback)(void* element, int is_focused);
typedef void (*HoverCallback)(void* element, int is_hovered);
typedef void (*TextCallback)(void* element, const char* text);
typedef void (*ValueCallback)(void* element, float value);
typedef void (*DropdownCallback)(void* element, int index, const char* value);
typedef void (*FileDropCallback)(UIElement* element, const char* filepath);
=======
typedef void (*ClickCallback)(void *element);
typedef void (*FocusCallback)(void *element, int is_focused);
typedef void (*HoverCallback)(void *element, int is_hovered);
typedef void (*TextCallback)(void *element, const char *text);
typedef void (*ValueCallback)(void *element, float value);
typedef void (*DropdownCallback)(void *element, int index, const char *value);
typedef void (*FileDropCallback)(UIElement *element, const char *filepath);
typedef void (*MouseClickCallback)(UIElement *element, int button);
>>>>>>> 410878f (feat: Add new pages and enhance input handling)
// ============================================================================
// COLOR CONSTANTS
// ============================================================================
#define SX_COLOR_GREEN 0x00FF7AFF
#define SX_COLOR_RED 0xFF5A5AFF
#define SX_COLOR_BLUE 0x5A9FFFFF
#define SX_COLOR_ORANGE 0xFFAA00FF
#define SX_COLOR_PURPLE 0xAA5AFFFF
#define SX_COLOR_MAGENTA 0xFF00AAFF
#define SX_COLOR_YELLOW 0xFFEB3BFF
#define SX_COLOR_CYAN 0x00BCD4FF
#define SX_COLOR_PINK 0xFF4081FF
#define SX_COLOR_TEAL 0x009688FF
#define SX_COLOR_LIME 0xCDDC39FF
#define SX_COLOR_INDIGO 0x3F51B5FF
#define SX_COLOR_WHITE 0xFFFFFFFF
#define SX_COLOR_BLACK 0x000000FF
#define SX_COLOR_GRAY 0x808080FF
#define SX_COLOR_LIGHT 0xDCDCDCFF
#define SX_COLOR_DARK 0x101010FF
#define SX_COLOR_CHARCOAL 0x2A2A2AFF
#define SX_COLOR_SMOKE 0xF5F5F5FF
#define SX_COLOR_NONE 0xFFFFFF00
// ============================================================================
// INPUT CONSTANTS (SDL Aliases)
// ============================================================================
#define SX_MOUSE_LEFT SDL_BUTTON_LEFT
#define SX_MOUSE_MIDDLE SDL_BUTTON_MIDDLE
#define SX_MOUSE_RIGHT SDL_BUTTON_RIGHT
#define SX_KEY_ESCAPE SDL_SCANCODE_ESCAPE
#define SX_KEY_SPACE SDL_SCANCODE_SPACE
#define SX_KEY_ENTER SDL_SCANCODE_RETURN
#define SX_KEY_UP SDL_SCANCODE_UP
#define SX_KEY_DOWN SDL_SCANCODE_DOWN
#define SX_KEY_LEFT SDL_SCANCODE_LEFT
#define SX_KEY_RIGHT SDL_SCANCODE_RIGHT
#define SX_KEY_BACKSPACE SDL_SCANCODE_BACKSPACE
#define SX_KEY_TAB SDL_SCANCODE_TAB
#define SX_KEY_LSHIFT SDL_SCANCODE_LSHIFT
#define SX_KEY_RSHIFT SDL_SCANCODE_RSHIFT
#define SX_KEY_LCTRL SDL_SCANCODE_LCTRL
#define SX_KEY_RCTRL SDL_SCANCODE_RCTRL
#define SX_KEY_LALT SDL_SCANCODE_LALT
#define SX_KEY_RALT SDL_SCANCODE_RALT
// ============================================================================
// PUBLIC API - INITIALIZATION & CORE
// ============================================================================
void sxui_init(const char* title, int width, int height, Uint32 seed_color);
void sxui_set_theme(Uint32 seed_color, UIThemeMode mode);
void sxui_poll_events(void);
void sxui_render(void);
int sxui_should_quit(void);
void sxui_quit(void);
void sxui_cleanup(void);
int sxui_load_font(const char* path, int size);
// ============================================================================
// PUBLIC API - WIDGET CREATION
// ============================================================================
UIElement* sxui_frame(UIElement* parent, int x, int y, int w, int h, int flags);
UIElement* sxui_button(UIElement* parent, const char* label, ClickCallback callback);
UIElement* sxui_label(UIElement* parent, const char* text);
UIElement* sxui_input(UIElement* parent, const char* placeholder, int is_password);
UIElement* sxui_checkbox(UIElement* parent, const char* label);
UIElement* sxui_slider(UIElement* parent, float initial_value);
UIElement* sxui_dropdown(UIElement* parent, const char** options, int option_count, int default_index);
UIElement* sxui_canvas(UIElement* parent, int x, int y, int w, int h);
UIElement* sxui_clone(UIElement* element);
void sxui_delete(UIElement* element);
// ============================================================================
// PUBLIC API - ELEMENT MANIPULATION
// ============================================================================
<<<<<<< HEAD
void sxui_set_position(UIElement* el, int x, int y);
void sxui_set_size(UIElement* el, int w, int h);
void sxui_set_visible(UIElement* el, int visible);
void sxui_set_draggable(UIElement* el, int draggable);
void sxui_set_flags(UIElement* el, int flags);
int sxui_get_flags(UIElement* el);
void sxui_set_z_index(UIElement* el, int z);
int sxui_get_z_index(UIElement* el);
void sxui_set_transparency(UIElement* el, float alpha);
float sxui_get_transparency(UIElement* el);
void sxui_set_custom_color(UIElement* el, Uint32 color);
Uint32 sxui_get_custom_color(UIElement* el);
=======
void sxui_set_position(UIElement *el, int x, int y);
void sxui_set_size(UIElement *el, int w, int h);
int sxui_get_width(UIElement *el);
int sxui_get_height(UIElement *el);
void sxui_set_visible(UIElement *el, int visible);
void sxui_set_draggable(UIElement *el, int draggable);
void sxui_set_flags(UIElement *el, int flags);
int sxui_get_flags(UIElement *el);
void sxui_set_z_index(UIElement *el, int z);
int sxui_get_z_index(UIElement *el);
void sxui_set_transparency(UIElement *el, float alpha);
float sxui_get_transparency(UIElement *el);
void sxui_set_custom_color(UIElement *el, Uint32 color);
Uint32 sxui_get_custom_color(UIElement *el);
UIElement *sxui_get_parent(UIElement *el);
UIElement *sxui_get_last_element(void);
>>>>>>> 410878f (feat: Add new pages and enhance input handling)
const char* sxui_get_text(UIElement* el);
void sxui_set_text(UIElement* el, const char* text);
float sxui_get_value(UIElement* el);
void sxui_set_value(UIElement* el, float value);
int sxui_get_dropdown_index(UIElement* el);
// ============================================================================
// PUBLIC API - INPUT & SYSTEM
// ============================================================================
void sxui_get_mouse_pos(int *x, int *y);
int sxui_get_mouse_x(void);
int sxui_get_mouse_y(void);
int sxui_is_mouse_button_down(int button);
int sxui_is_mouse_button_pressed(int button);
int sxui_is_mouse_button_released(int button);
int sxui_is_key_down(int scancode);
int sxui_is_key_pressed(int scancode);
int sxui_is_key_released(int scancode);
const char *sxui_get_scancode_name(int scancode);
void sxui_get_window_size(int *w, int *h);
int sxui_get_window_width(void);
int sxui_get_window_height(void);
// ============================================================================
// PUBLIC API - EFFECTS
// ============================================================================
void sxui_set_gradient(UIElement* el, float* positions, Uint32* colors, int count, float angle);
void sxui_clear_gradient(UIElement* el);
void sxui_set_outline(UIElement* el, int width, Uint32 color, Uint8 alpha);
void sxui_clear_outline(UIElement* el);
void sxui_set_rounded_corners(UIElement* el, int radius);
void sxui_clear_rounded_corners(UIElement* el);
// ============================================================================
// PUBLIC API - CANVAS DRAWING
// ============================================================================
void sxui_canvas_clear(UIElement* canvas, Uint32 color);
void sxui_canvas_draw_pixel(UIElement* canvas, int x, int y, Uint32 color);
void sxui_canvas_draw_line(UIElement* canvas, int x1, int y1, int x2, int y2, Uint32 color);
void sxui_canvas_draw_rect(UIElement* canvas, int x, int y, int w, int h, Uint32 color, int filled);
void sxui_canvas_draw_circle(UIElement* canvas, int cx, int cy, int radius, Uint32 color, int filled);
// ============================================================================
// PUBLIC API - LAYOUT CONTROL
// ============================================================================
<<<<<<< HEAD
void sxui_frame_set_padding(UIElement* frame, int padding);
void sxui_frame_set_spacing(UIElement* frame, int spacing);
void sxui_frame_set_default_child_size(UIElement* frame, int w, int h);
void sxui_frame_set_grid_columns(UIElement* frame, int max_cols);
void sxui_frame_set_scrollbar_width(UIElement* frame, int width);
void sxui_frame_update_layout(UIElement* frame);
// New helpers to fix compilation error
int sxui_frame_get_child_count(UIElement* frame);
UIElement* sxui_frame_get_child(UIElement* frame, int index);
void sxui_frame_add_child(UIElement* frame, UIElement* child);
=======
void sxui_frame_set_padding(UIElement *frame, int padding);
void sxui_frame_set_spacing(UIElement *frame, int spacing);
void sxui_frame_set_default_child_size(UIElement *frame, int w, int h);
void sxui_frame_set_grid_columns(UIElement *frame, int max_cols);
void sxui_frame_set_scrollbar_width(UIElement *frame, int width);
void sxui_frame_update_layout(UIElement *frame);
int sxui_frame_get_child_count(UIElement *frame);
UIElement *sxui_frame_get_child(UIElement *frame, int index);
void sxui_frame_add_child(UIElement *frame, UIElement *child);
>>>>>>> 410878f (feat: Add new pages and enhance input handling)
// ============================================================================
// PUBLIC API - PAGE MANAGER
// ============================================================================
void sxui_page_init(void);
void sxui_add_page(UIElement* frame);
void sxui_add_page_at(UIElement* frame, int position);
void sxui_page_next(void);
void sxui_page_previous(void);
void sxui_switch_page(int index);
int sxui_get_current_page(void);
int sxui_get_page_count(void);
// ============================================================================
// PUBLIC API - EVENT SYSTEM
// ============================================================================
<<<<<<< HEAD
UIConnection sxui_on_click(UIElement* el, ClickCallback callback);
UIConnection sxui_on_hover_enter(UIElement* el, HoverCallback callback);
UIConnection sxui_on_hover_leave(UIElement* el, HoverCallback callback);
UIConnection sxui_on_focus_changed(UIElement* el, FocusCallback callback);
UIConnection sxui_on_text_changed(UIElement* el, TextCallback callback);
UIConnection sxui_on_submit(UIElement* el, TextCallback callback);
UIConnection sxui_on_value_changed(UIElement* el, ValueCallback callback);
UIConnection sxui_on_dropdown_changed(UIElement* el, DropdownCallback callback);
=======
UIConnection sxui_on_click(UIElement *el, ClickCallback callback);
UIConnection sxui_on_hover_enter(UIElement *el, HoverCallback callback);
UIConnection sxui_on_hover_leave(UIElement *el, HoverCallback callback);
UIConnection sxui_on_focus_changed(UIElement *el, FocusCallback callback);
UIConnection sxui_on_text_changed(UIElement *el, TextCallback callback);
UIConnection sxui_on_submit(UIElement *el, TextCallback callback);
UIConnection sxui_on_value_changed(UIElement *el, ValueCallback callback);
UIConnection sxui_on_dropdown_changed(UIElement *el, DropdownCallback callback);
UIConnection sxui_on_mouse_click(UIElement *el, MouseClickCallback callback);
>>>>>>> 410878f (feat: Add new pages and enhance input handling)
void sxui_disconnect(UIConnection conn);
void sxui_set_file_drop_callback(FileDropCallback callback);
#endif