Masonry 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
Masonry 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
Masonry 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 Apache
开发语言 Rust 查看源码 »
操作系统 Linux
软件类型 开源软件
所属分类 程序开发GUI开发框架
开源组织
地区 不详
投 递 者
适用人群 未知
收录时间 2023-02-06

软件简介

Masonry 是一个 Rust GUI 框架。

Masonry 提供了用于创建窗口的平台(使用 Glazier 作为后端),每个窗口都包含一个 Widget 树。它还提供了用于在 runtime 检测 Widget 树的工具,可编写单元测试,方便开发者调试和维护应用程序。

基于 Masonry,开发者可实现即时模式 (immediate-mode) GUI、Elm 架构、函数式响应 GUI 等。

示例代码

use masonry::widget::{
    Button, CrossAxisAlignment, Flex, Label, Portal, SizedBox, TextBox, WidgetMut,
};
use masonry::{
    Action, AppDelegate, AppLauncher, Color, DelegateCtx, Env, WidgetId, WindowDescription,
    WindowId,
};

struct Delegate {
    next_task: String,
}

impl AppDelegate for Delegate {
    fn on_action(
        &mut self,
        ctx: &mut DelegateCtx,
        action: Action,
    ) {
        match action {
            Action::ButtonPressed | Action::TextEntered(_) => {
                let mut root: WidgetMut<Portal<Flex>> = ctx.get_root();
                if self.next_task != "" {
                    let mut flex = root.child_mut();
                    flex.add_child(Label::new(self.next_task.clone()));
                }
            }
            Action::TextChanged(new_text) => {
                self.next_task = new_text.clone();
            }
            _ => {}
        }
    }
}

fn main() {
    // The main button and text box with some space below,
    // all inside a scrollable area.
    let root_widget = Portal::new(
        Flex::column()
            .with_child(
                Flex::row()
                    .with_child(TextBox::new(""))
                    .with_child(Button::new("Add task")),
            )
            .with_spacer(VERTICAL_WIDGET_SPACING),
    )
    .constrain_horizontal(true);

    let main_window = WindowDescription::new(root_widget)
        .title("To-do list")
        .window_size((400.0, 400.0));

    AppLauncher::with_window(main_window)
        .with_delegate(Delegate {
            next_task: String::new(),
        })
        .launch()
        .expect("Failed to launch application");
}
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣
发表了资讯
02/07 07:51

Masonry 0.1 发布,Rust GUI 框架

Masonry 是一个 Rust GUI 框架,其作者最近刚发布了 0.1 版本,并提出了对 Rust UI 的愿景,他称之为"Fearless GUI",具备以下特点: 可迭代 具备灵活性 可测试 可观测 可重用 最新发布的 Masonry 0.1 旨在实现上述目标,目前提供了用于创建窗口的平台(使用 Glazier 作为后端),每个窗口都包含一个 Widget 树。它还提供了用于在 runtime 检测 Widget 树的工具,可编写单元测试,方便开发者调试和维护应用程序。 基于 Masonry,...

1
4
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
11 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部