MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
摘要
这是一个名为 MicroUI 的极小型即时模式(immediate-mode)UI 库,用 ANSI C 编写,代码规模约 1100 行。它运行在固定大小内存区域中,不进行额外内存分配。库内置了窗口、滚动面板、按钮、滑块、文本框、标签、复选框和自动换行文本等基础控件,并提供简单布局系统。设计上强调可移植性,要求用户自行提供输入处理与绘制逻辑,库本身不负责渲染,只输出绘制命令,适配任意能画矩形和文本的渲染后端。同时它允许用户扩展自定义控件,但不鼓励通过 PR 增加大量新功能。许可证为 MIT。
荐读理由
在做自定义渲染或内部工具界面时,可以借鉴 immediate-mode UI 的交互与状态组织方式(由调用端每帧描述界面、UI 不持有复杂内部状态),并结合固定内存分配模型减少运行时分配复杂度,从而降低 UI 系统实现与调试成本。
原文
A tiny, portable, immediate-mode UI library written in ANSI C
Features
Tiny: around
1100 slocof ANSI CWorks within a fixed-sized memory region: no additional memory is allocated
Built-in controls: window, scrollable panel, button, slider, textbox, label, checkbox, wordwrapped text
Works with any rendering system that can draw rectangles and text
Designed to allow the user to easily add custom controls
Simple layout system
Example
if (mu_begin_window(ctx, "My Window", mu_rect(10, 10, 140, 86))) {
mu_layout_row(ctx, 2, (int[]) { 60, -1 }, 0);
mu_label(ctx, "First:");
if (mu_button(ctx, "Button1")) {
printf("Button1 pressed\n");
}
mu_label(ctx, "Second:");
if (mu_button(ctx, "Button2")) {
mu_open_popup(ctx, "My Popup");
}
if (mu_begin_popup(ctx, "My Popup")) {
mu_label(ctx, "Hello world!");
mu_end_popup(ctx);
}
mu_end_window(ctx);
}
Screenshot
Usage
See
doc/usage.mdfor usage instructionsSee the
demodirectory for a usage example
Notes
The library expects the user to provide input and handle the resultant drawing commands, it does not do any drawing itself.
Contributing
The library is designed to be lightweight, providing a foundation to which you can easily add custom controls and UI elements; pull requests adding additional features will likely not be merged. Bug reports are welcome.
License
This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.
这条对你有帮助吗?


