首页 > 解决方案 > 如何删除 OrbTk 中的小部件?

问题描述

我能够使用 OrbTk 的开发版本(不是 crates.io 上的那个)制作带有标签和按钮的基本 GUI。现在,我想在单击该按钮时删除标签和按钮。

我查看了 GitHub 上的示例,以及 docs.rs 上的 OrbTk 文档,但这些小部件似乎没有功能delete()remove()除了 Grid。

所以我把小部件放在一个网格中,希望我可以通过执行来清除整个网格grid.clear()。但现在在我的代码中,该函数clear()似乎不存在......

它虽然写在文档中。

代码:

use orbtk::*;

widget!(MainView);

//MainView
impl Template for MainView {
    fn template(self, _: Entity, ctx: &mut BuildContext) -> Self {
        self.name("MainView").child(
            Grid::create()
                .columns(
                    Columns::create()
                        .column("*").build()
                )
                .rows(
                    Rows::create().row("*").row("*").build()
                )
                .child(
                    TextBlock::create()
                        .text("Label A!")
                        .attach(Grid::row(0))
                        .build(ctx),
                )
                .child(
                    Button::create()
                        .text("My button")
                        .attach(Grid::row(1))
                        .on_click(move |_states, _| -> bool {
                            println!("Rofl");

                            true
                        })
                        .build(ctx),
                )
            .build(ctx)
        )
    }
}

fn main() {
      Application::new()
        .window(|ctx| {
            Window::create()
                .title("OrbTk - minimal example")
                .position((100.0, 100.0))
                .size(420.0, 730.0)
                .child(MainView::create().build(ctx))
                .build(ctx)
        })
        .run();
}

货物.toml:

[package]
name = "orb_tk"
version = "0.1.0"
authors = ["Niel"]
edition = "2018"

[dependencies]
orbtk = { git = "https://github.com/redox-os/orbtk.git", branch= "develop" }

似乎在我使用的 OrbTk 的新开发版本中Grid不再具有remove()orclear()功能。不,我根本不知道如何删除小部件。

如何删除 OrbTk 中的一个小部件或一组小部件?

标签: rust

解决方案


推荐阅读