8000 GitHub - Loowootoo/CUI: Native UI components for C: about 150 of them, with spring motion and full keyboard support. Windows, macOS and Linux, no dependencies. · GitHub
[go: up one dir, main page]

Skip to content
LoowootooPublic
forked from yappologistic/CUI

About

Native UI components for C: about 150 of them, with spring motion and full keyboard support. Windows, macOS and Linux, no dependencies.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

CUI

A UI library for C that draws its own components.

CI Release License: MIT

Live site · Getting started · Tutorial · Components · Downloads


CUI components: a sign up form, metric cards, a calendar with time slots, a bar chart, team members and settings

Every image on this page is drawn by CUI, from plain C.

CUI is an immediate-mode UI library written in C99. You describe the screen with function calls every frame. CUI lays it out, handles the mouse and keyboard, and draws it with OpenGL or its own software renderer, in a window on Windows, macOS or Linux, or in a browser through WebAssembly.

  • About 210 components, from buttons and text fields to a data grid, charts, a code editor and docking panels.
  • No dependencies. One CMake target, or two files (cui.h and cui.c) dropped into your project.
  • Small. A complete app, window, fonts and all, is about 250 KB. There is no browser or runtime inside.
  • MIT licensed.

Try it first

  • In your browser: the live site runs every component and the example apps. It is the same C code, compiled to WebAssembly.
  • On your computer, without a compiler: each release has the example apps built for Windows, macOS and Linux.
  • In code: the tutorial builds a to-do app in about 130 lines.

A small program

#include <cui/cui.h>
#include <cui/cui_app.h>

int main(void) {
    cui_app *app = cui_app_create(&(cui_app_desc){
        .title = "Hello", .width = 420, .height = 300 });
    if (!app) return 1;
    bool notifications = true;
    int clicks = 0;

    while (cui_app_frame(app)) {
        cui_ctx *ui = cui_app_ui(app);
        cui_column(ui, .pad = 32, .gap = 16) {
            cui_heading(ui, "Hello, CUI", 2);
            cui_secondary(ui, "A native window, a few components "
                              "and no dependencies.");
            cui_switch(ui, "Notifications", &notifications);
            cui_row(ui, .gap = 8) {
                if (cui_button(ui, "Click me", .variant = CUI_BUTTON_PRIMARY))
                    clicks++;
                cui_textf(ui, "Clicked %d times", clicks);
            }
        }
    }
    cui_app_destroy(app);
    return 0;
}
The hello example: a heading, a line of text, a switch and a button

A component is a function call. It draws itself, handles input and returns what happened: cui_button returns true on the frame it is clicked.

Options are named arguments. Leave one out and it takes its default.

Your variables are the state. The screen is described again every frame, so there are no widgets to create, keep or update.

What it is, and what it is not

CUI draws every component itself. It does not wrap the system's buttons and menus, so an app looks the same on every system and does not look like the system's own apps. "Native" here means compiled code in a real window, with nothing interpreted and no web view.

How it sits beside the libraries you may know:

  • Dear ImGui and Nuklear are also immediate-mode. They are aimed mostly at tools and debug panels inside a program that already has a renderer. CUI uses the same model for the app itself: it opens the window, and its components come with the things end users expect, such as full text editing, animation, light and dark themes and right-to-left layouts.
  • Qt, GTK and wxWidgets keep a tree of widgets for you and are far more mature. They have screen reader support, complete input-method support and years of use behind them. If you need those today, use one of them.
  • Electron and web views ship a browser with your app. CUI ships about 250 KB.

CUI is a good fit for a desktop tool, an editor, a dashboard or a game's interface written in C or C++, where you want it small and want it to look finished without designing every control. Read Limitations before you decide.

Install

With CMake (GCC, Clang, MSVC and MinGW are tested):

include(FetchContent)
FetchContent_Declare(cui
    GIT_REPOSITORY https://github.com/yappologistic/CUI.git
    GIT_TAG v1.4.0)
FetchContent_MakeAvailable(cui)
target_link_libraries(my_app PRIVATE cui::cui)
cui_app_target(my_app)   # no console window on Windows, and only the code your app uses

Without CMake, take cui.h and cui.c from a release and compile them with your program. Getting started has the exact commands for both, and CI runs those commands on every push.

To build the library and run an example:

git clone https://github.com/yappologistic/CUI.git
cmake -S CUI -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/examples/tracker

Linux needs the X11 development headers (libx11-dev). Windows and macOS need nothing beyond the system SDK.

What is in it

Group Components
Basics and actions text, buttons, icon buttons, split and toggle buttons, menus, command palette
Inputs text field, text area, number, money, tags, one time code, select, combobox, multi-select, shortcut recorder, dropzone
Selection and pickers checkbox, switch, radio, slider, chips, date and date range, time, color, emoji, knob and fader
Navigation and windows tabs, sidebar, breadcrumb, menu bar, toolbar, status bar, document tabs, docking panels
Overlays and feedback dialog, sheet, popover, tooltip, toast, alert, progress, skeleton, empty state, guided tour
Data table, data grid for very large data, tree, tree table, list, file browser with open and save dialogs
Code and text code block, code editor, diff viewer, markdown view, JSON viewer, terminal, log console, hex viewer
Charts line, bar, donut, sparkline, gauge, candlestick, heatmap, treemap, radar, funnel, sankey, scatter
Planning kanban board, week and month calendars, gantt chart, node editor
Developer tools trace viewer, network waterfall, flame graph, dependency and commit graphs, CI pipeline, test explorer, regex tester, query builder
Instruments dot-matrix chart, chart annotations, event track on a time axis, readout, dot-matrix display
Creative controls status tag, ratio slider, gradient and step sliders, palette strip, aspect ratio picker, seed field
Canvas and bars grouped and floating toolbars, format bar, live cursors, canvas zoom controls, result card, selection bar
Conversation and AI chat, comments, composer, reasoning and tool calls, agent plan, sources and citations, voice recorder, voice notes, voice session
Your own a canvas with a 2D drawing API, per-component state and spring animation

Every component has a page with a live example, its options, its data structures and what it does with the keyboard: on the site, or in Components and More components.

Pictures of the larger components
A docked workspace with a scene tree, a viewport, a log console and a property inspector, with a tab being dragged to a new place
Docking: drag a tab to stack it or split any side; the layout saves as a short string · docs
A data grid with a filter bar, two selected rows, team tags and score bars
Data grid: 2,000 virtualized rows, filters, sorting, resizable columns and spreadsheet style selection
A kanban board with a card being dragged between columns A command palette with grouped commands and shortcuts
Kanban: the lifted card follows the pointer and the column opens a slot for it Command palette: fuzzy search, groups and shortcuts
A date range picker with presets and two months, and a wheel time picker
Pickers: a date range with presets over two months, and wheels that spin with momentum
More: charts, planning, conversation, effects
A contribution heatmap, a sankey of test runs, a radar chart and a task plan Control tiles, a now playing card, a waveform and a dock
Charts: calendar heatmap, sankey and radar, with a live task plan Dock, tiles and player: icons grow under the pointer, the waveform seeks on click
Chat bubbles, threaded comments, a rolling counter and presence avatars Three cards for choosing a renderer, one lit by the pointer
Conversation: grouped bubbles, threads, a rolling counter, presence Spotlight cards: the surface and edge nearest the pointer light up
A gantt chart with dependencies, progress and a today line
Gantt: drag to reschedule, pull the ends to resize, arrows follow dependencies

Example apps

Complete apps in examples/, each a single C file. They run in the browser on the site.

An AI assistant built with CUI
Muse: reasoning, tool calls, sources, a plan and a composer with a model picker · assistant.c
An issue tracker built with CUI An analytics dashboard built with CUI
Orbit: grouped issues, custom glyphs, an activity pane · tracker.c Larkspur: figures, charts and a sortable table · dashboard.c
All examples
Example What it shows
hello The smallest app
todo The app the tutorial builds: a list, a filter, a dialog, saving to a file
caffeine The instruments together: a dot-matrix chart with annotations, cups you drag on a time axis, readouts and a dot-matrix verdict
assistant AI assistant: reasoning, tool calls, sources, plan, composer with a model picker
tracker Issue tracker: grouped list, custom status glyphs, detail pane, activity
music Music player: cover art drawn on a canvas, track list, transport bar
finance Personal finance: top navigation, charts, painted card, budgets, goals
dashboard Sidebar, top bar, KPIs, charts and a sortable table
mail Three pane inbox, folders, reading pane, compose dialog
notes Split view, search, context menus, dialogs, shortcuts, file export
settings Forms, validation, preferences and a danger zone
gallery Every component, light and dark, all accents
Music player Personal finance app
Mail client Notes app

Themes

The same controls in all eight accents
cui_set_theme(ui, CUI_THEME_DARK);      /* animates */
cui_set_accent(ui, CUI_ACCENT_BLUE);    /* neutral, violet, blue, green, amber, orange, coral, rose */

Colors are named tokens (CUI_COLOR_SURFACE, CUI_COLOR_ACCENT and so on), so your own drawing follows the theme too. See Theming.

Size and speed

Measure Result
hello on Linux, the whole executable, stripped about 250 KB
assistant (the AI app above), the whole executable about 360 KB
The whole library: every component, both renderers, the X11 backend, fonts and icons about 1,130 KB
Build, lay out and paint one frame (gallery pages, 1240 × 820 points at 2×) 0.09 to 0.75 ms, most under 0.25
A real app in use (Notes, Mail, an IDE; software renderer, 1280 × 800) 2 to 3% of one core, 11 to 13 MB of memory
Library memory over an hour of use 2 to 9 MB, flat, with nothing left after cui_destroy
CPU while nothing happens 0%: the app waits for events

An app carries only the components it calls, which is why hello is a quarter of the library. The times are wall clock on a 4 core cloud VM. cui_bench in tests/ reproduces them, and Performance describes the hour-long runs behind the memory and CPU rows.

Platforms

Platform Backend Renderer Tested in CI
Windows 7+ Win32 (per monitor DPI, dark title bar) OpenGL 3.3, GDI software fallback MSVC, MinGW
macOS 10.13+ Cocoa (Retina, native menus, text input) OpenGL 3.3+, layer software fallback Apple clang
Linux, BSD X11 (XIM text input, HiDPI) OpenGL 3.3 (GLX), XPutImage fallback GCC, Clang
Wayland and others SDL2 or GLFW OpenGL 3.3 GCC
Browser WebAssembly, plain clang (how) WebGL2, or software Docs site, every push
Anything Your own Your own (one shader)

To use CUI inside an engine with your own window and renderer, see Integration and Rendering. The core only emits triangles.

Limitations

  • No screen reader support. There is no accessibility tree yet. This rules CUI out for apps that must be accessible to blind users.
  • The keyboard does not reach everything. Most components work from the keyboard and each one's page lists its keys. Some parts still need a pointer: the rating, the histogram slider's handles, swipe actions, the reorderable list, the JSON viewer, the agent plan's steps, blame, the time histogram, and the choices inside the open time picker and color picker.
  • Complex scripts are partial. Text is UTF-8 with kerning and font fallback, and layouts mirror for right-to-left languages. Arabic-script shaping and bidirectional text are an optional, experimental build option for static text (details). CJK works once you add a fallback font.
  • Input methods compose in the system's window. Committed text arrives; the text being composed is not drawn inline. The window opens at the caret on Windows, macOS, X11, SDL2 and the docs site, but not yet on the GLFW backend.
  • No native Wayland backend. Use the SDL2 or GLFW backend, or XWayland.
  • No Android or iOS. Layouts adapt to phone widths and touch, and apps run in mobile browsers, but there is no platform layer for phones.
  • It is new. Version 1.0 was released in November 2026, so it has little real-world use behind it yet. The changelog lists what each release changed.

How it is built and tested

Most of CUI's code is written by AI models under the maintainer's direction. Every commit names the model that wrote it in a Co-Authored-By trailer, and the contribution rules ask the same of everyone who sends a change.

Because of that, the tests are what the project stands on. Every push runs 19 CI jobs:

  • unit, interaction and render tests on Windows (MSVC and MinGW), macOS and Linux (GCC and Clang, with the X11, SDL2 and GLFW backends);
  • a fuzzer that drives the gallery and the example apps with random input under AddressSanitizer and UndefinedBehaviorSanitizer;
  • real windows opened on all three systems;
  • the single-file build with GCC and Clang;
  • the commands of the getting-started guide, taken from the guide and run as written.

The images in docs/images are rendered by the tests, so a visual change and its documentation move together.

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
ctest --test-dir build --output-on-failure

Documentation

Guide What it covers
Getting started Install, build, the frame loop, your first screens
Tutorial Build a small, complete app step by step
Building an app The window, when frames happen, what components return, threads, shipping
Recipes Complete programs: a form, a sorted table, a background task, saved settings
Layout Rows, columns, sizes, alignment, grids, scrolling, split views
Components and more Every component: what it is, usage, options, keyboard
Theming Tokens, light and dark, accents, fonts, motion
Icons The built-in Lucide icons, and how to use another icon font
Custom components The canvas, the drawing API, state and animation
Integration Your own window, input and renderer; C++; binary size
Rendering The vertex format and the reference shader
Performance How memory and speed are tested, and the results
Function reference Every public function with its signature, on the site
Questions What CUI is and is not, how it compares, what it cannot do
How CUI is built The code map and the outline every component follows
Design principles The visual rules every component follows

The live site has the same guides with every component running beside its page. It is rebuilt from master on every push; to run it locally, use web/tools/serve.sh (needs clang with the wasm32 target).

Contributing

Bug reports and pull requests are welcome, from people and from AI agents. Every report needs an honest account of who wrote it (and which model, if an AI did) and evidence you produced yourself: the commands you ran and their output. Contributing explains what that means.

Credits

Type: Inter and Geist (SIL Open Font License). Icons: Lucide (ISC). Font rasterization, image decoding and PNG output: stb (public domain). See THIRD_PARTY.md. The site's overview uses Ansel Adams' The Tetons and the Snake River (1942, U.S. National Archives, public domain).

License

MIT. See LICENSE.

About

Native UI components for C: about 150 of them, with spring motion and full keyboard support. Windows, macOS and Linux, no dependencies.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0