A high-level, plug-and-play UI library for C built on SDL2. SXUI provides a simplified interface for creating responsive desktop-class interfaces without managing low-level SDL state.
- Buttons: Click events, hover effects, and press animations.
- Labels: Static and dynamic text display.
- Text Inputs: Full editing suite including selection, copy/paste, and word navigation.
- Checkboxes: State-based toggles with value callbacks.
- Sliders: Normalized value selection (0.0 - 1.0).
- Dropdowns: Expanded selection menus with custom callbacks.
- Canvas: Low-level drawing surface for custom animations and tools.
- Frames: Container elements with automated layout management.
- Vertical & Horizontal Lists: Automated element stacking.
- Grid Layout: Auto-wrapping grid with configurable column limits.
- Scrollable Containers: Clipping support with automated, fading scrollbars.
- Dynamic Switching: Change layout modes at runtime without recreating elements.
- Strict Mouse Logic:
sxui_on_mouse_clickensures clicks only fire if pressed and released on the same widget. - Real-time Access: Check
sxui_is_key_downorsxui_is_mouse_button_pressedanywhere in your code. - Window Utilities: Built-in support for window resizing events and resolution getters.
- Selection via Shift + Arrow keys.
- Standard shortcuts: Ctrl+A (Select All), Ctrl+C/X/V (Copy/Cut/Paste).
- Navigation: Ctrl+Left/Right (Word-jump), Home/End.
- Word deletion: Ctrl+Backspace and Ctrl+Delete.
- Native mouse selection and horizontal auto-scrolling for long strings.
Ensure you have the SDL2 and SDL2_ttf development headers installed.
Ubuntu/Debian:
sudo apt install libsdl2-dev libsdl2-ttf-dev
macOS:
brew install sdl2 sdl2_ttf
-
SXUI depends on the SXList library. For best results, place the SXList source files in
deps/directory within your project.git clone --recursive https://github.com/SwirX/SXUI cd SXUI -
Font: Ensure Montserrat-Regular.ttf is in the root directory
To compile SXUI as a static library:
# Compile dependencies and library
make lib
To link SXUI to your application:
gcc main.c libsxui.a -lSDL2 -lSDL2_ttf -lm -o my_app
Or to run the showcase directly:
make
./showcase#include "sxui.h"
void on_button_click(void* element) {
printf("Button clicked!\n");
}
int main() {
sxui_init("Application", 800, 600, 0x00FF7AFF);
UIElement* btn = sxui_button(NULL, "Click Me", on_button_click);
sxui_set_size(btn, 200, 50);
sxui_set_position(btn, 300, 275);
while (!sxui_should_quit()) {
sxui_poll_events();
sxui_render();
}
sxui_cleanup();
return 0;
}If you are new to SXUI or C programming, I maintain a dedicated Showcases Repository.
Unlike standard documentation, the showcases are designed as mini-courses. Each example includes:
- Commented Source: Step-by-step explanations of the implementation.
- Technical Deep-Dives: READMEs that explain the underlying C concepts (Pointers, Memory Management, Bitwise Logic, etc.).
Available Showcases:
- Simple Login Form: Learn about frames, inputs, and state management.
- More coming soon: Sliders, Custom Styling, and Advanced Layouts.
sxui_init(title, w, h, seed): Initialize the engine and window.sxui_set_theme(seed, mode): Update the procedural theme.sxui_poll_events(): Process input and internal logic.sxui_render(): Draw the current frame.sxui_cleanup(): Free all library resources.
UI_SCROLLABLE: Enable mouse-wheel scrolling.UI_LAYOUT_GRID: Enable auto-grid positioning.UI_FLAG_CLIP: Clip children to frame boundaries.UI_FLAG_DRAGGABLE: Allow user to move the element.
SXUI ships with Montserrat-Regular as the default fallback. You can load your own .ttf font at any time:
sxui_init("My App", 800, 600, 0x00FF7AFF);
sxui_load_font("path/to/my_font.ttf", 18);If your custom font fails to load or the path is incorrect, the library will automatically fallback to Montserrat to ensure the UI remains usable.
- SXUI: MIT License.
- Montserrat Font: Licensed under the SIL Open Font License.
- SXList: MIT License.