<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          MasonryRust GUI 框架

          聯(lián)合創(chuàng)作 · 2023-09-28 06:04

          Masonry 是一個 Rust GUI 框架。

          Masonry 提供了用于創(chuàng)建窗口的平臺(使用 Glazier 作為后端),每個窗口都包含一個 Widget 樹。它還提供了用于在 runtime 檢測 Widget 樹的工具,可編寫單元測試,方便開發(fā)者調(diào)試和維護應(yīng)用程序。

          基于 Masonry,開發(fā)者可實現(xiàn)即時模式 (immediate-mode) GUI、Elm 架構(gòu)、函數(shù)式響應(yīng) 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");
          }
          瀏覽 14
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚州无码高清视频在线观看 | 欧美999| 一區二區三區色 | 丰满女人做爱视频 | 先锋资源成人 |