#include "sxui.h"
int main() {
// title, width, height, theme_seed
sxui_init("Title", 800, 600, 0x00FF7AFF);
// UI construction goes here
while (!sxui_should_quit()) {
sxui_poll_events();
sxui_render();
}
sxui_cleanup();
return 0;
}
UIElement* btn = sxui_button(parent, "Text", callback);
UIElement* lbl = sxui_label(parent, "Text");
UIElement* inp = sxui_input(parent, "Placeholder", 0); // 1 for password
UIElement* chk = sxui_checkbox(parent, "Label");
UIElement* sld = sxui_slider(parent, 0.5f); // Range 0.0 - 1.0
UIElement* dd = sxui_dropdown(parent, options_arr, count, default_idx);
UIElement* cnv = sxui_canvas(parent, x, y, w, h);
UIElement* frm = sxui_frame(parent, x, y, w, h, flags);
UI_SCROLLABLE: Enables vertical scrolling.
UI_LAYOUT_HORIZONTAL: Arranges children left-to-right.
UI_LAYOUT_GRID: Arranges children in a wrapping grid.
UI_FLAG_CLIP: Clips children to frame boundaries.
UI_FLAG_DRAGGABLE: Allows manual repositioning.
UI_FLAG_HIDDEN: Prevents rendering and interaction.
UI_FLAG_PASSWORD: Masks text input.
sxui_set_position(el, x, y);
sxui_set_size(el, w, h);
sxui_set_visible(el, 1); // 1=Show, 0=Hide
sxui_set_text(el, "String");
const char* txt = sxui_get_text(el);
sxui_set_value(el, 0.75f); // For sliders/checkboxes
int w = sxui_get_width(el);
int h = sxui_get_height(el);
// Mouse state
int mx, my;
sxui_get_mouse_pos(&mx, &my);
int is_down = sxui_is_mouse_button_down(SX_MOUSE_LEFT);
int pressed = sxui_is_mouse_button_pressed(SX_MOUSE_RIGHT);
// Keyboard state
int space_down = sxui_is_key_down(SX_KEY_SPACE);
int esc_pressed = sxui_is_key_pressed(SX_KEY_ESCAPE);
const char* name = sxui_get_scancode_name(SX_KEY_ENTER);
sxui_quit(); // Set running flag to 0
int ww = sxui_get_window_width();
int wh = sxui_get_window_height();
sxui_frame_set_padding(frame, 10);
sxui_frame_set_spacing(frame, 8);
sxui_frame_set_default_child_size(frame, 200, 50);
sxui_frame_set_grid_columns(frame, 4);
sxui_frame_update_layout(frame); // Call after dynamic changes
// Binding events
UIConnection c1 = sxui_on_click(btn, on_click);
UIConnection c2 = sxui_on_value_changed(sld, on_change);
UIConnection c3 = sxui_on_submit(inp, on_submit);
// Disconnecting
sxui_disconnect(c1);
void on_click(void* el);
void on_mouse_click(void* el, int button); // SDL_BUTTON_* or SX_MOUSE_*
void on_hover(void* el, int hovered);
void on_text(void* el, const char* text);
void on_value(void* el, float value);
void on_dropdown(void* el, int index, const char* value);
- Ctrl + A: Select All
- Ctrl + C / X / V: Copy / Cut / Paste
- Ctrl + Left / Right: Word navigation
- Shift + Left / Right: Text selection
- Enter: Trigger Submit callback and lose focus
# Build the library and showcase using the provided Makefile
make
# Manual compilation (if not using Makefile)
gcc -c sxui.c -Ideps -o sxui.o
gcc myapp.c sxui.o deps/dynamic_list.c -lSDL2 -lSDL2_ttf -lm -o myapp