raui_core/widget/component/
space_box.rs1use crate::{
2 PropsData, Scalar,
3 widget::{
4 context::WidgetContext,
5 node::WidgetNode,
6 unit::size::{SizeBoxNode, SizeBoxSizeValue},
7 },
8};
9use serde::{Deserialize, Serialize};
10
11#[derive(PropsData, Debug, Default, Clone, Serialize, Deserialize)]
12#[props_data(crate::props::PropsData)]
13#[prefab(crate::Prefab)]
14pub struct SpaceBoxProps {
15 #[serde(default)]
16 pub width: Scalar,
17 #[serde(default)]
18 pub height: Scalar,
19}
20
21impl SpaceBoxProps {
22 pub fn cube(value: Scalar) -> Self {
23 Self {
24 width: value,
25 height: value,
26 }
27 }
28
29 pub fn horizontal(width: Scalar) -> Self {
30 Self { width, height: 0.0 }
31 }
32
33 pub fn vertical(height: Scalar) -> Self {
34 Self { width: 0.0, height }
35 }
36}
37
38pub fn space_box(context: WidgetContext) -> WidgetNode {
39 let WidgetContext { id, props, .. } = context;
40
41 let SpaceBoxProps { width, height } = props.read_cloned_or_default();
42
43 SizeBoxNode {
44 id: id.to_owned(),
45 props: props.clone(),
46 width: SizeBoxSizeValue::Exact(width),
47 height: SizeBoxSizeValue::Exact(height),
48 ..Default::default()
49 }
50 .into()
51}