gitmyhub

microui

C ★ 6.5k updated 1y ago

A tiny immediate-mode UI library

microui is a ~1100-line C library for building immediate-mode user interfaces, you describe your UI in code each frame and it outputs drawing commands that you render with your own graphics system.

Csetup: moderatecomplexity 3/5

microui is a very small library for building user interfaces in C. The entire codebase is around 1,100 lines of code, which is unusually compact for a UI toolkit. It is written in standard C, meaning it can be compiled and run on almost any platform without modification.

The library follows an approach called immediate-mode UI. Rather than creating persistent objects for each button or panel that live in memory and need to be managed, immediate-mode UI redraws the interface from scratch every frame by calling functions in sequence. Each call both defines what a widget looks like and checks whether the user interacted with it. The code example in the README shows this clearly: a window, two labels, two buttons, and a popup are all described by a handful of function calls inside a loop.

The built-in controls include windows, scrollable panels, buttons, sliders, text boxes, labels, checkboxes, and word-wrapped text. The library handles layout automatically and lets developers add custom controls if needed. One design constraint worth noting is that microui does not draw anything itself. It produces a list of drawing commands, and the developer is responsible for feeding those commands to whatever graphics system the application already uses. This makes it compatible with any rendering setup that can draw rectangles and text.

Memory usage is fixed at startup, meaning the library never allocates additional memory at runtime. The project is open source under the MIT license.

Where it fits