gpui-component
只要组件 builder 和应用的 GPUI 依赖解析到同一个 GPUI source,gpui-component 就可以与 GPUI-RSX 一起使用。
demo 使用:
[dependencies]gpui = { git = "https://github.com/zed-industries/zed" }gpui_platform = { git = "https://github.com/zed-industries/zed", features = ["font-kit", "runtime_shaders", "wayland", "x11"] }gpui-rsx = { path = ".." }gpui-component = { git = "https://github.com/longbridge/gpui-component", rev = "8752104289424b7f35045b68a2d394018da48e7e" }应用项目应提交 Cargo.lock,避免解析到的 Zed revision 意外漂移。
用 base 指定构造器
Section titled “用 base 指定构造器”GPUI-RSX 可以从标签名推导简单构造器,但组件 builder 往往需要显式构造器。此时使用宏专用的 base 属性:
use gpui_component::button::{Button, ButtonVariants as _};use gpui_component::Sizable as _;
rsx! { <Button base={Button::new("save")} label={"Save"} small primary />}base 会替换推导出的构造器,不会生成 .base(...) 方法调用。
显式导入扩展 Trait
Section titled “显式导入扩展 Trait”很多 gpui-component 方法来自扩展 trait。建议在组件使用处显式导入:
use gpui_component::button::ButtonVariants as _;use gpui_component::Sizable as _;这样宏生成的方法链可以正常通过类型检查,缺少 trait 导入时也更容易定位。
cargo check --manifest-path demo/Cargo.toml --bins --lockedcargo tree --manifest-path demo/Cargo.toml --locked -i gpui如果组件类型不匹配,先查看依赖树。大多数问题来自重复 GPUI crate 实例。