SlintForge / 文档

快速开始

在 Rust 或 C++ 项目中接入 SlintForge

SlintForge 是基于 Slint 1.18 的桌面组件库。组件只在 .slint 中实现一次,Rust 与 C++ 分别通过各自的 SDK 接入。

NOTE SlintForge 即将在 GitHub 开源。首版以 Windows x64、Slint 1.18.0、fluent 样式为基线。

环境要求

  • Rust:1.98.0,x86_64-pc-windows-msvc 工具链
  • C++:Visual Studio 2026 x64、CMake 3.21+、Slint 1.18.0 Windows MSVC SDK

导入组件

所有公共组件和类型都从 @slintforge 导入:

import { ForgeWindow, ForgeCard } from "@slintforge";

export component App inherits ForgeWindow {
    title: "Hello SlintForge";
    ForgeCard { }
}

Rust

构建脚本中调用 slintforge_build::configure_style(),并把 style_include_paths() 传入 slint_build::CompilerConfiguration。创建第一个窗口前调用:

slintforge::configure_rendering(Default::default())?;

C++

使用安装包提供的 CMake 包,用 slintforge_target_sources() 编译 .slint 文件(默认把图片、字体等资源嵌入程序)。创建第一个窗口前调用 forge_configure_rendering()。

绑定服务

部分组件需要宿主绑定服务才能工作,绑定应在显示窗口前完成:

能力 Rust / C++
二维码、代码高亮、材质、建议输入 bind_widget_services! / forge_bind_widget_services
DataGrid、TreeDataGrid bind_grid_services! / forge_bind_grid_services
ForgePlot 图表 bind_plot_services! / forge_bind_plot_services
ForgeFlow 节点编辑 bind_flow_services! / forge_bind_flow_services
窗口 / 页面截图 bind_capture_service! / forge_bind_capture_service

所有 Slint 属性、模型和回调都在 UI 线程执行。后台线程完成计算后,通过 slint::invoke_from_event_loop 把数据回传到 UI 线程。

ForgeFlow 需要 Skia 渲染器(winit-skia 或 winit-skia-software),必须在应用启动前选定。

许可

SlintForge 计划以 GPL-3.0-only 开源。公开仓库尚未开放;使用前请分别核对 SlintForge 与 Slint 的实际许可条款。