rust语言orbtk GUI基础(old2018)-3.2 orbtk布局控件

本文详细介绍了OrbTk GUI框架中布局控件的使用方法,包括Container、Center、Row、Column、Spacer和Stack等控件的特性及示例代码。通过本文,读者可以了解如何在OrbTk中构建各种布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

orbtk的api在2019.2进行了修改,该文章为2018版
新版请转[新版orbtk gui基础]

orbtk布局控件

orbtk 0.3版支持的布局控件主要有:

  • Container:容器,只能有一个子控件,可以使用PaddingLayout定位子控件
  • Center
  • Row:行控件
  • Column:列控件
  • Spacer:在Row或Column内创建空区域
  • Stack:子控件在z方向上层叠

其中:Container,Center是只能放一个子控件的容器,Spacer是个占位符,调整多个控件间空隙的。Center和Spacer事实上都可以用样式实现。

只有Row,Column,Stack算是真正的布局控件。

Container

Container容器为子控件四周增加padding边框。

Container容器只能有一个子控件。

Container::create().with_child(TextBlock::create())
    
Container::create()
    .with_child(TextBlock::create())
    .with_property(Padding::default().with(20))
    
Container::create()
    .with_child(TextBlock::create())
    .with_property(Padding::default().with_lefts(20))

Center

Center容器也只能有一个子控件,Center会将子控件距中显示。

Center::create().with_child(TextBlock::create())

目前Center貌似不能起作用,建议使用css样式实现center效果,不用Center控件。

Row和Column

Row将子控件显示在一行内,Column将子控件显示在一列内。

Row::create()
    .with_child(TextBlock::create())
    .with_child(TextBlock::create())
    
Column::create()
    .with_child(TextBlock::create())
    .with_child(TextBlock::create())

Row和Column可以相互包含,形成表格状布局

spacer

Spacer是一个不显示任何内容的占位符,通常可以用于Row或者Column两个子元素之间。

Row::create()
    .with_child(TextBlock::create())
    .with_child(Spacer::create())
    .with_child(TextBlock::create())

Spacer的css选择器为spacer。Spacer默认的css样式为:

spacer {
    width: 4;
}

Stack

Stack的子控件会重叠在一块显示,比如两个TextBlock子控件,一个是"text",一个是"—",则两者叠加后就显示加删除线的"text"。

Stack::create()
    .with_child(TextBox::create())
    .with_child(TextBlock::create())
    .with_child(TextBlock::create().with_property(Label::from("~~~~~~~")))

本文代码

本文代码在https://github.com/hustlei/RustGuiOrbtkTutorial

可以使用下面命令编译运行

cargo run --bin layout
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hustlei

您的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值