Ribir: 适用于 Rust/WASM 的非侵入式 GUI 框架
Ribir: Non-intrusive GUI framework for Rust/WASM

原始链接: https://github.com/RibirX/Ribir

## Ribir:用于跨平台应用的 Rust GUI Ribir 是一个 Rust GUI 框架,能够使用单一代码库创建适用于 Linux、Windows、macOS 和 Web 的美观原生应用程序。其核心原则是数据驱动方法:开发者专注于数据结构和 API,而 UI 会自动随任何数据更改而更新。 Ribir 提供灵活性,具有可选的 Rust 宏,方便 UI 定义,以及一个可组合的小部件系统,包含函数小部件、组合、渲染和子小部件控制。它包含非侵入式状态管理、Flutter 风格的布局系统和可组合的事件系统。 目前正在积极开发中,Ribir 拥有主题系统、GPU 渲染(默认使用 wgpu 实现)、基本文本支持以及不断增长的 20 多个小部件库。移动支持(iOS 和 Android)计划在框架稳定后实现。 该项目欢迎社区贡献——从文档改进和错误报告到功能建议,并采用 MIT 许可。在他们的仓库中找到更多信息并参与其中!

## Ribir:一个新的 Rust/WASM GUI 框架 一个名为 Ribir 的新的、非侵入性的 Rust 和 WASM GUI 框架被推出,引发了 Hacker News 的讨论。Ribir 的特点在于它为小部件使用纯组合模型,避免了像 QML 这样的框架中常见的传统基于继承的方法。 然而,评论者质疑这种组合在实践中是否真的与现有框架不同。讨论的一个中心主题是构建 Rust UI 的挑战,考虑到 Rust 专注于防止共享可变性——这是许多 UI 范例的核心原则。 几位用户指出了以符合人体工程学的方式管理状态更新的困难。 EGUI、GPUI 和 Slint 等替代方案也被提及,其中一些方案的可访问性支持被强调为一个关键优势。 讨论还涉及 Rust 中 UI 框架的激增,并将之与 JavaScript 中的“每日框架”周期相提并论。 一位用户分享了一个令人印象深刻的、使用 EGUI 构建的开源分子查看器/CAD 应用程序的链接,展示了它在非平凡项目中的可行性。
相关文章

原文

Ribir-logo

Use Rust to build multi-platform applications from a single codebase.

Ribir is a Rust GUI framework that helps you build beautiful and native multi-platform applications from a single codebase.

Experience a novel approach to UI development that's directly based on your data structure APIs. Any data mutation will trigger a precise UI update. Your focus should be on designing your data structure and its APIs. Then, you can describe your data's UI without intruding on its logic.

A simple example of a counter:

To use Ribir without DSL:

use ribir::prelude::*;
fn main() {
  App::run_with_data(
    || Stateful::new(0),
    move |cnt: &'static Stateful<i32>| {
      let c_cnt = cnt.clone_writer();
      let mut btn = Button::declarer();
      btn
        .on_tap(move |_| *c_cnt.write() += 1)
        .with_h_align(HAlign::Center)
        .with_v_align(VAlign::Center);
      btn.finish().with_child(pipe!($read(cnt).to_string()))
    });
}

More Examples

  • Declarative language It doesn't introduce a completely new language. Instead, it provides a set of Rust macros for easier interaction. You can choose to use it or not.
  • Widgets compose system has four kinds of widgets to support you can implement your widget in different ways:
    • function widget and Compose, from other widgets composition.
    • Render, implement your layout and paint anything you want.
    • ComposeChild, control the compose logic between parent and child widgets and specify the template of child widgets.
  • Non-intrusive state converts your data to a listenable state and updates the view according to the change of the state.
  • Layout system learning and inspired by Flutter Sublinear layout, but not the same.
  • Event system is a composition event system, that supports event bubbling and capture. Allow to compose with any widget, and exists only if you use it.
  • Theme System: Supports using different themes for various parts of the sub-tree and enables theme modifications at runtime.
  • Painter converts the view to 2D paths.
  • GPU render is a backend of the Painter, do path tessellation so that you can easily render the triangles in any GPU render engine. A wgpu implementation is provided as the default GPU render engine. Tessellation base on [lyon].
  • Text support basic text typography and IME input, in a usable but rough stage.
  • Widgets library provides 20+ basic widgets, but all are in a rough stage, and the API is not stable yet.

Platform Support situation
Linux
Windows
macOS
iOS 🚧 Not yet
Android 🚧 Not yet
Web

Ribir is actively being developed and tested on desktop platforms, with both desktop and web platforms integrated into our CI/CD pipeline.

While the framework can compile and run on mobile platforms, we haven't fully tested or adapted the user interface for them yet. We plan to focus on mobile support once the core framework is stable and a production-ready widget library is released.

If you like Ribir, give our repo a ⭐ STAR ⬆️ and WATCH 👀 our repository to stay updated with the latest developments!

Every encouragement and feedback can support us to go further.

We are grateful to the community for contributing bug fixes and improvements.

😎 New to Ribir?

Start learning about the framework by helping us improve our documentation. Feel free to open a new "Documentation" issue. We are also very welcome:

  • Point out to us where our document has misunderstandings
  • Pull requests which improve test coverage
  • Add undocumented code (e.g. built-in widget)
  • Report typo

For more information please read:

🤔 Confused about something?

Feel free to go to Discussions and open a new "Q&A" to get help from contributors. Often questions lead to improvements to the ergonomics of the framework, better documentation, and even new features!

😱 Found a bug?

Please report all bugs! We are happy to help support developers fix the bugs they find if they are interested and have the time.

This project exists thanks to all the people who contributed:

We also found inspiration from the following frameworks:

Ribir is MIT-licensed

联系我们 contact @ memedata.com