Freya 0.4 - Rust GUI library

Freya 0.4 - Rust GUI Library

Freya 0.4 7/16/2026 - marc2332 hey 👋 Hey again, this is the announcement of Freya v0.4, the latest release of my Rust 🦀 GUI library. It has been around a year since v0.3 and this is by far the biggest and most stable release yet. Freya 0.4 comes with a big rewrite, the most notable change is that Freya no longer depends on Dioxus. Instead, it now has its own reactive and component model built from scratch. For the full changelog you can check the v0.4 Release on GitHub. Valin, my code editor made using Freya: 大家好,这是我的 Rust 🦀 GUI 库 Freya v0.4 的发布公告。距离 v0.3 版本发布已经过去一年左右了,这是迄今为止规模最大、最稳定的一个版本。Freya 0.4 进行了大规模重构,最显著的变化是 Freya 不再依赖 Dioxus。取而代之的是,它现在拥有从零开始构建的响应式和组件模型。完整的更新日志可以在 GitHub 的 v0.4 Release 页面查看。Valin 是我使用 Freya 制作的代码编辑器。

Why the rewrite

为什么要重构

Freya originally used Dioxus as its reactive and component engine. Dioxus served Freya really well during the early versions and I am grateful for the foundation it provided. But as Freya grew, the limitations started to show up. Dioxus is primarily designed around web, things like the rsx!() macro, string-based attributes, and the way components and elements were defined made it harder to provide the kind of type safety, extensibility and simplicity I wanted. Also, depending on a large external framework meant that Freya would be affected by any upstream change and design decision, even if those were not aligned with Freya’s direction. Freya 最初使用 Dioxus 作为其响应式和组件引擎。Dioxus 在早期版本中为 Freya 提供了很好的支持,我很感激它所奠定的基础。但随着 Freya 的成长,局限性开始显现。Dioxus 主要围绕 Web 设计,诸如 rsx!() 宏、基于字符串的属性,以及组件和元素的定义方式,使得我难以实现我所追求的类型安全、可扩展性和简洁性。此外,依赖一个庞大的外部框架意味着 Freya 会受到任何上游变更和设计决策的影响,即使这些决策与 Freya 的发展方向并不一致。

So I decided to rewrite almost everything in Freya from scratch. The new system is heavily inspired by Dioxus (and React), but tailored specifically for Freya’s needs. It still has hooks, callback event handlers, and a very similar state and async model. But now Freya owns the full stack and can evolve freely. The start of the rewrite was done in this small PR. And since then I have been fixing bugs and adding new features. In practice, this rewrite also means a nicer day-to-day: typos in attributes are caught by the compiler instead of at runtime, your IDE actually autocompletes things, and stack traces point at the line you wrote instead of an expanded macro. 因此,我决定从零开始重写 Freya 的几乎所有内容。新系统深受 Dioxus(和 React)的启发,但专门针对 Freya 的需求进行了定制。它仍然拥有 Hooks、回调事件处理器以及非常相似的状态和异步模型。但现在 Freya 拥有了完整的技术栈,可以自由演进。重构的起点始于这个小 PR。从那时起,我一直在修复 Bug 并添加新功能。在实践中,这次重构也意味着更好的日常开发体验:属性中的拼写错误会被编译器捕获,而不是在运行时报错;IDE 可以实现真正的自动补全;堆栈跟踪会指向你编写的代码行,而不是展开后的宏。

A few crates that previously came from the Dioxus ecosystem (I made them all though) have been forked and adapted: dioxus-radio became freya-radio, dioxus-query became freya-query, dioxus-i18n became freya-i18n, dioxus-clipboard became freya-clipboard. And many crates were reorganized, split, or consolidated. 一些之前来自 Dioxus 生态系统的 crate(虽然都是我写的)已经被分叉并适配:dioxus-radio 变成了 freya-radiodioxus-query 变成了 freya-querydioxus-i18n 变成了 freya-i18ndioxus-clipboard 变成了 freya-clipboard。此外,许多 crate 也进行了重组、拆分或合并。

The new API

新的 API

The biggest user-facing change is the removal of the rsx!() macro. In its place, Freya now uses a sort of builder pattern with fully typed attributes. 用户层面最大的变化是移除了 rsx!() 宏。取而代之的是,Freya 现在使用一种带有完全类型化属性的构建器模式(Builder Pattern)。

(Code examples omitted for brevity, but the transition shows moving from macro-based syntax to method-chaining builder syntax.) (代码示例略,但展示了从基于宏的语法向方法链构建器语法的转变。)

A few things to notice: 需要注意的几点:

  • No macro. Just regular Rust method calls with full IDE support (autocomplete, go-to-definition, etc.)
  • 没有宏。 只有常规的 Rust 方法调用,并提供完整的 IDE 支持(自动补全、跳转到定义等)。
  • Attributes are fully typed. Instead of width: "fill" you write width(Size::fill()). This means compile-time errors instead of runtime panics.
  • 属性是完全类型化的。 不再使用 width: "fill",而是写成 width(Size::fill())。这意味着编译时错误取代了运行时恐慌(Panic)。
  • use_signal is now use_state.
  • use_signal 现在变成了 use_state
  • Components return impl IntoElement instead of Element.
  • 组件现在返回 impl IntoElement 而不是 Element
  • Helper methods like .center(), .horizontal(), and .expanded() make common layout patterns shorter.
  • .center().horizontal().expanded() 这样的辅助方法使常见的布局模式更加简洁。

Elements

元素

Elements in Freya 0.4 are regular Rust functions that return builders. Each builder has typed methods for every attribute it supports. Freya 0.4 中的元素是返回构建器的常规 Rust 函数。每个构建器都为其支持的每个属性提供了类型化的方法。

  • rect is still the general-purpose container.
  • rect 仍然是通用的容器。
  • label is for simple text.
  • label 用于简单的文本。
  • paragraph supports rich text with multiple spans and cursors.
  • paragraph 支持带有多个 span 和光标的富文本。