MF

marc2332/freya

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

3475 stars 质量 75 趋势 42MIT

由 Skia 驱动🎨的 Rust 跨平台非网页图形界面库🦀。

概览

:警告:我最近在https://github.com/marc2332/freya/pull/1351,重写了Freya的大部分内容,所以主分支和最新的稳定版有很大不同。 Freya 的组件模型允许你创建可重复使用的 UI 元素,当它们依赖的状态发生变化时,这些元素会自动重新渲染。组件可以保留自己的内部状态,也可以订阅共享状态,它们的输出是 UI。任何实现组件特性的类型都可以是组件,而根(应用)组件可以只是函数。内置的例子包括像 Button 和 Switch 这样的组件。 Freya开箱即用,从简单的按钮、开关、滑块到更复杂的VirtualScrollView、日历、ColorPicker等。 你可以在 examples 文件夹里检查所有以 component_ 开头的例子。 为颜色、大小、位置及其他视觉属性创建过渡。

概述(AI 翻译)

网站 |文档 |Discord |联系方式

Freya 是一个跨平台、原生、声明式 Rust 🦀 的图形界面库。

用途 📜

最新稳定版:

下一个发布:

main 分支:

试试🚀看

确保开发设置准备好。

⚠️ 本仓库使用 git 子模块,克隆不使用 --recurse-submodules 会导致示例无法编译。

已经克隆了但没有子模块? 运行git submodule update --init --recursive去取它们。

然后放个例子:

⚠️ 如果你正好用的是Windows,使用windows-gnu并且编译时出现错误,建议你去看看这个问题。

组成部分与州

Freya 的组件模型允许你创建可重复使用的 UI 元素,当它们依赖的状态发生变化时,这些元素会自动重新渲染。组件可以保留自己的内部状态,也可以订阅共享状态,它们输出 UI 作为输出。任何实现 [Component 特征的类型都可以是组件,而根(app)组件可以是一个函数。内置的例子包括像 Button 和 [Switch 这样的组件。

开箱即用组件

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Freya 🦀

Website | Documentation | Discord | Contact

Freya is a cross-platform, native, declarative GUI library for Rust 🦀.

Usage 📜

Latest stable release:

freya = "0.5"

main branch:

freya = { git = "https://github.com/freya-rs/freya", branch = "main" }

Pre-release:

freya = "0.6.0-alpha.2"

Trying it out 🚀

Make sure to have Development Setup ready.

⚠️ This repo uses git submodules, cloning without --recurse-submodules will make the examples fail to compile.

git clone --recurse-submodules https://github.com/freya-rs/freya.git
cd freya

Already cloned without submodules? Run git submodule update --init --recursive to fetch them.

Then run an example:

cargo run --example counter

⚠️ If you happen to be on Windows using windows-gnu and get compile errors, maybe go check this issue.

Components & State

Freya’s component model lets you create reusable UI elements that automatically re-render when the state they depend on changes. Components can hold their own internal state or subscribe to shared state, and they produce UI as their output. Any type that implements the Component trait can be a component, while the root (app) component can simply be a function. Built-in examples include components like Button and Switch.

fn app() -> impl IntoElement {
    let mut count = use_state(|| 4);

    let counter = rect()
        .width(Size::fill())
        .height(Size::percent(50.))
        .center()
        .color((255, 255, 255))
        .background((15, 163, 242))
        .font_weight(FontWeight::BOLD)
        .font_size(75.)
        .shadow((0., 4., 20., 4., (0, 0, 0, 80)))
        .child(count.read().to_string());

    let actions = rect()
        .horizontal()
        .width(Size::fill())
        .height(Size::percent(50.))
        .center()
        .spacing(8.0)
        .child(
            Button::new()
                .on_press(move |_| {
                    *count.write() += 1;
                })
                .child("Increase"),
在 GitHub 查看完整 README

推荐工具

换一个关键词,或者移除筛选条件。

安装

npx skillfish add marc2332/freya
新手?先看 mcpskill.org 教程 →