Rust 跨平台 GPUI 组件
Rust cross-platform GPUI components

原始链接: https://github.com/longbridge/gpui-component

## GPUI 组件:一个基于 Rust 的桌面 UI 库 GPUI 组件是一个正在开发的跨平台 UI 库,用于使用 Rust 构建桌面应用程序,它利用 GPUI 渲染框架。它提供 60 多个受 macOS 和 Windows 美学启发的 UI 组件,并结合了现代 shadcn/ui 设计。 主要特性包括无状态、易于定制的组件,内置主题和尺寸选项(xs-lg),以及通过停靠布局系统实现灵活的布局。性能是优先考虑的,虚拟化表格和列表组件可用于处理大型数据集。它还支持 Markdown、HTML、图表,以及具有 LSP 功能和 Tree Sitter 语法高亮显示的高性能代码编辑器。 第一个使用 GPUI 组件构建的应用程序 Longbridge Pro 演示了多主题支持。目前通过 Git 依赖项访问 (`gpui = "0.2.2"`,`gpui-component = "0.3.0"`),该库是实验性的,存在一些限制,包括可选的 WebView 元素。示例和贡献指南可用,展示了它的潜力,以及与 Iced、egui 和 Qt 的比较。

相关文章

原文

Build Status Docs Crates.io

UI components for building fantastic desktop applications using GPUI.

  • Richness: 60+ cross-platform desktop UI components.
  • Native: Inspired by macOS and Windows controls, combined with shadcn/ui design for a modern experience.
  • Ease of Use: Stateless RenderOnce components, simple and user-friendly.
  • Customizable: Built-in Theme and ThemeColor, supporting multi-theme and variable-based configurations.
  • Versatile: Supports sizes like xs, sm, md, and lg.
  • Flexible Layout: Dock layout for panel arrangements, resizing, and freeform (Tiles) layouts.
  • High Performance: Virtualized Table and List components for smooth large-data rendering.
  • Content Rendering: Native support for Markdown and simple HTML.
  • Charting: Built-in charts for visualization your data.
  • Editor: High performance code editor (support up to 200K lines) with LSP (diagnostics, completion, hover, etc).
  • Syntax Highlighting: Syntax highlighting for editor and markdown components using Tree Sitter.

Here is the first application: Longbridge Pro, built using GPUI Component.

Image

We built multi-theme support in the application. This feature is not included in GPUI Component itself, but is based on the Theme feature, so it's easy to implement.

GPUI and GPUI Component are still in development, so you need to add dependencies by git.

gpui = "0.2.2"
gpui-component = "0.3.0"
use gpui::*;
use gpui_component::{button::*, *};

pub struct HelloWorld;
impl Render for HelloWorld {
    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
        div()
            .v_flex()
            .gap_2()
            .size_full()
            .items_center()
            .justify_center()
            .child("Hello, World!")
            .child(
                Button::new("ok")
                    .primary()
                    .label("Let's Go!")
                    .on_click(|_, _, _| println!("Clicked!")),
            )
    }
}

fn main() {
    let app = Application::new();

    app.run(move |cx| {
        // This must be called before using any GPUI Component features.
        gpui_component::init(cx);

        cx.spawn(async move |cx| {
            cx.open_window(WindowOptions::default(), |window, cx| {
                let view = cx.new(|_| HelloWorld);
                // This first level on the window, should be a Root.
                cx.new(|cx| Root::new(view.into(), window, cx))
            })?;

            Ok::<_, anyhow::Error>(())
        })
        .detach();
    });
}

Still early and experimental; there are a lot of limitations.

GPUI Component has a WebView element based on Wry. This is an optional feature, which you can enable with a feature flag.

gpui-component = { version = "0.3.0", features = ["webview"] }
wry = { version = "0.53.3, package = "lb-wry" }

More usage examples can be found in the story directory.

GPUI Component has an Icon element, but it does not include SVG files by default.

The example uses Lucide icons, but you can use any icons you like. Just name the SVG files as defined in IconName. You can add any icons you need to your project.

We have a gallery of applications built with GPUI Component.

More examples can be found in the examples directory. You can run them with cargo run --example <example_name>.

Check out CONTRIBUTING.md for more details.

Features GPUI Component Iced egui QT 6
Language Rust Rust Rust C++/QML
Core Render GPUI wgpu wgpu QT
License Apache 2.0 MIT MIT/Apache 2.0 Commercial
Min Binary Size 1 12MB 11MB 5M 20MB 2
Cross-Platform Yes Yes Yes Yes
Documentation No Simple Simple Good
Web No Yes Yes Yes
UI Style Modern Basic Basic Basic
CJK Support Yes Yes Bad Yes
Chart Yes No No Yes
Table (Large dataset) Yes
(Virtual Rows, Columns)
No Yes
(Virtual Rows)
Yes
(Virtual Rows, Columns)
Table Column Resize Yes No Yes Yes
Text base Rope COSMIC Text 3 trait TextBuffer 4 QTextDocument
CodeEditor Simple Simple Simple Basic API
Dock Layout Yes Yes Yes Yes
Syntax Highlight Tree Sitter Syntect Syntect QSyntaxHighlighter
Markdown Rendering Yes Yes Basic No
Markdown mix HTML Yes No No No
HTML Rendering Basic No No Basic
Text Selection TextView No Any Label No
Themes Yes No No No
I18n Yes Yes Yes Yes

Please submit an issue or PR if any mistakes or outdated are found.

Apache-2.0

  1. Release builds by use simple hello world example.

  2. Reducing Binary Size of Qt Applications

  3. Iced Editor: https://github.com/iced-rs/iced/blob/db5a1f6353b9f8520c4f9633d1cdc90242c2afe1/graphics/src/text/editor.rs#L65-L68

  4. egui TextBuffer: https://github.com/emilk/egui/blob/0a81372cfd3a4deda640acdecbbaf24bf78bb6a2/crates/egui/src/widgets/text_edit/text_buffer.rs#L20

联系我们 contact @ memedata.com