MicroUI – 一个用 ANSI C 编写的轻量级、便携式立即模式 UI 库
MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C

原始链接: https://github.com/rxi/microui

该项目是一个轻量级的即时模式 UI 库,由约 1,100 行 ANSI C 代码编写而成。它专为简洁性和可移植性而设计,在固定内存区域内运行,无需动态分配内存。 该库提供了必要的控件(包括窗口、按钮、滑块和文本输入框),并具备一套简明的布局系统。值得注意的是,它与渲染器无关;其本身不执行任何绘制操作,而是要求用户自行处理渲染指令和输入处理。这种模块化设计使开发人员能够轻松将其与任何现有的渲染系统集成,或实现自定义控件。 该项目遵循“保持简单”的哲学,倾向于极简主义的基础架构,而非功能堆砌。它以 MIT 许可证发布,可自由重新分发和修改。详细的文档和使用示例可在仓库中获取。

Hacker News 社区正在讨论 **MicroUI**,这是一个由约 1,100 行 ANSI C 代码编写的极简即时模式(immediate-mode)UI 库。该库旨在实现高可移植性和效率,无需动态内存分配,并能轻松集成到任何支持绘制基础矩形和文本的渲染系统中。 讨论中强调了该库作为轻量级工具在调试界面、嵌入式系统或游戏引擎中的实用性。一些用户批评该项目缺乏原生无障碍(a11y)支持。然而,也有人认为对于此类工具而言,无障碍并非通用需求,并指出像 *Dear ImGui* 这样同样缺乏原生无障碍支持的流行替代方案,已被广泛应用于游戏引擎和企业软件等专业领域。 技术观察人士指出,尽管核心库十分紧凑,但用户仍需自行处理与窗口系统(如 X11 或 Win32)的集成,不过项目提供的演示程序包含一个基于 SDL 的渲染器,可作为一个跨平台的起点。总的来说,MicroUI 被视为一种专门的、“务实”的工具,适合那些相比功能全面的 UI 框架,更看重小体积的开发者。
相关文章

原文

A tiny, portable, immediate-mode UI library written in ANSI C

  • Tiny: around 1100 sloc of ANSI C
  • Works 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

Browser Demo

  • See doc/usage.md for usage instructions
  • See the demo directory for a usage example

The library expects the user to provide input and handle the resultant drawing commands, it does not do any drawing itself.

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.

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

联系我们 contact @ memedata.com