1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! SpacerWidget — Flex 内部推开剩余空间的零尺寸叶子
use crate::widget::Widget;
use super::sized_box::SizedBoxRenderObject;
/// Spacer(零尺寸叶子,配合 FlexItem::grow 推开剩余空间)
///
/// 本身没有任何尺寸,也不绘制任何东西。语义完全由 Flex 容器的
/// `FlexItem` 参数决定 —— 通常是 `.spacer(grow)` 把它和
/// `FlexItem::grow` 配对使用。
///
/// ```ignore
/// FlexWidget::row()
/// .push(title)
/// .spacer(1.0) // ← 把剩余空间都吃掉
/// .push(button)
/// ```
#[derive(Debug, Default)]
pub struct SpacerWidget;
impl SpacerWidget {
pub fn new() -> Self {
Self
}
}
impl Widget for SpacerWidget {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn is_equivalent(&self, old: &dyn Widget) -> bool {
old.as_any().downcast_ref::<SpacerWidget>().is_some()
}
fn create_render_object(&self) -> Box<dyn crate::render_object::RenderObject> {
// 复用 SizedBox:显式 0×0 + 无子节点 → layout 恒返回 ZERO
Box::new(SizedBoxRenderObject::new(Some(0.0), Some(0.0), None))
}
fn semantics(&self) -> Option<crate::semantics::WidgetSemantics> {
// Spacer 是纯布局件,不出现在无障碍树里
None
}
}