| Crates.io | clat_gui |
| lib.rs | clat_gui |
| version | 0.1.3 |
| created_at | 2025-10-09 12:56:47.940007+00 |
| updated_at | 2025-10-09 12:56:47.940007+00 |
| description | High-performance, cross-platform Rust desktop GUI framework. |
| homepage | |
| repository | https://github.com/example/clat_gui |
| max_upload_size | |
| id | 1875537 |
| size | 99,210 |
高性能、跨平台的Rust桌面端GUI框架。
将以下内容添加到你的Cargo.toml文件中:
[dependencies]
clat_gui = "0.1.0"
以下是一个简单的示例,展示如何创建一个基本窗口:
use clat_gui::Application;
use anyhow::Result;
fn main() -> Result<()> {
// 创建应用程序实例
let mut app = Application::new();
// 创建窗口
app.create_window("Clat Desktop", 800, 600)?;
// 运行应用程序
app.run();
}
use clat_gui::components::button::Button;
// 创建按钮
let mut button = Button::new(100.0, 100.0, 200.0, 50.0, "点击我");
// 设置点击事件处理
button.set_on_click(|| {
println!("按钮被点击了!");
});
use clat_gui::components::label::Label;
// 创建标签
let mut label = Label::new(100.0, 200.0, "这是一个标签");
// 设置文本颜色
label.set_color([1.0, 0.0, 0.0, 1.0]); // 红色文本
// 设置字体大小
label.set_font_size(20.0);
use clat_gui::layout::{LayoutManager, LayoutConstraints};
use clat_gui::layout::containers::HorizontalLayout;
// 创建布局管理器
let mut layout_manager = LayoutManager::new();
// 生成容器ID
let container_id = layout_manager.generate_id();
// 创建水平布局容器
let mut horizontal_layout = HorizontalLayout::new(10.0, 20.0); // 间距10,内边距20
// 注册布局策略
layout_manager.register_strategy(container_id, Box::new(horizontal_layout));
// 添加子组件
layout_manager.add_child(container_id, child_id_1, 1.0); // 权重1.0
layout_manager.add_child(container_id, child_id_2, 2.0); // 权重2.0
// 计算布局
let constraints = LayoutConstraints::default();
layout_manager.calculate_layout(container_id, constraints);
use clat_gui::layout::containers::VerticalLayout;
// 创建垂直布局容器
let mut vertical_layout = VerticalLayout::new(10.0, 20.0); // 间距10,内边距20
// 注册布局策略并添加子组件(与水平布局类似)
use clat_gui::layout::containers::GridLayout;
// 创建网格布局容器
let mut grid_layout = GridLayout::new(3, 3, 100.0, 50.0, 5.0, 10.0); // 3x3网格,单元格大小100x50,间距5,内边距10
// 设置单元格跨度
grid_layout.set_cell_span(child_id, 0, 0, 1, 2); // 第0行第0列,跨越1行2列
use clat_gui::render::Renderer;
// 创建渲染器(通常由Application内部管理)
let renderer = Renderer::new(device, queue, surface, config);
// 开始渲染帧
let (output, view, mut encoder) = renderer.begin_frame()?;
// 创建渲染通道
let mut render_pass = renderer.create_render_pass(&mut encoder, &view, Some(wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.3,
a: 1.0,
}));
// 绘制基本图形
renderer.draw_rect(&mut render_pass, 100.0, 100.0, 200.0, 100.0, [1.0, 0.0, 0.0, 1.0]);
renderer.draw_circle(&mut render_pass, 400.0, 200.0, 50.0, [0.0, 1.0, 0.0, 1.0]);
// 结束渲染帧
renderer.end_frame(output, encoder);
cargo build
cargo run --example simple_app
cargo test
本项目采用MIT许可证,详情请查看LICENSE文件。
欢迎提交问题和Pull Request来帮助改进这个项目!