kui-ffi
C API for kui: a cdylib plus include/kui.h, and CExtension for loading a C plugin into a Rust host.
kui splits a UI into a model that lays out and paints into a display list (kui-core), a renderer (kui-wgpu) and a windowed runner (kui-native). This crate puts the model, and optionally the runner, behind a flat C ABI: every kui_* function declared in kui.h is exported from libkui_ffi, and the Kui* structs are its repr(C) mirrors. A C, C++ or other-language host links the library and either hands a window to kui_run or drives its own event loop and renderer; a Rust host running kui-native loads a C shared library as a guest extension through CExtension. Strings cross as (ptr, len) UTF-8, values you build are yours until a call consumes them, every entry point catches panics, and a host checks kui_abi_version() against the header's KUI_ABI_VERSION first.
Install
For a Rust host loading C plugins:
For a C host, build the library and include the header from the repository:
The runner feature (on by default) provides kui_run and kui_run_with; a host that owns its own window and renderer turns it off and ships less than half the library.
Example
A C host's frame loop without kui_run (the complete programs are under examples/c/ in the repository):
if return 1;
KuiCtx *ctx = ;
for
;
A Rust app loading a C plugin:
use CExtension;
use ;
;
Where it fits
| Crate | What it is |
|---|---|
| kui-core | The model: tree, layout, text, display list |
| kui-wgpu | The renderer |
| kui-native | The windowed runner most apps use |
| kui-derive | #[derive(Message)] |
| kui-lua | Lua binding |
| kui-ffi | This crate: the C API |
Documentation
- API reference: https://docs.rs/kui-ffi
- The book: https://kui-book.qxuken.dev
- Repository: https://github.com/qxuken/kui
License
MIT