外观
即时 UI
cici::ui 是一个轻量的即时模式 UI,所有控件直接绘制在当前帧。
rust
let mut enabled = true;
let mut volume = 0.5;
let mut name = String::new();
ui::window("设置", 40.0, 40.0, 320.0, 240.0, || {
ui::label("cici ui", 56.0, 84.0, 18.0);
if ui::button("开始游戏", 56.0, 112.0, 140.0, 32.0) {
// clicked
}
ui::checkbox("音效", 56.0, 156.0, &mut enabled);
ui::slider("音量", 56.0, 192.0, 240.0, &mut volume, 0.0, 1.0);
});
ui::text_input("输入名字", 40.0, 300.0, 300.0, &mut name);控件
| 函数 | 说明 |
|---|---|
ui::window(title, x, y, w, h, body) | 面板与标题栏,body 内继续绘制控件 |
ui::window_draggable(title, x, y, w, h, body) | 可拖动窗口,body(origin_x, origin_y) |
ui::popup(x, y, w, h, body) | 浮动面板 |
ui::scroll_area(id, x, y, w, h, content_h, body) | 裁剪 + 滚轮滚动,body(scroll) |
ui::tree_node(label, x, y, &mut expanded) | 可展开节点,返回是否切换 |
ui::Layout::new(x, y).next(h) | 垂直布局游标 |
ui::panel(x, y, w, h) | 无标题面板 |
ui::label(text, x, y, size) | 文本 |
ui::button(text, x, y, w, h) | 返回是否点击 |
ui::checkbox(label, x, y, &mut bool) | 返回是否切换 |
ui::slider(label, x, y, w, &mut f32, min, max) | 拖动修改数值 |
ui::text_input(label, x, y, w, &mut String) | 点击聚焦后接收键盘输入 |
控件使用全局输入与绘制函数,需要放在 cici::run / run_state 的闭包内。没有保留布局状态,坐标由调用者决定。