zng_wgt_size_offset/
offset_impl.rs1use zng_wgt::prelude::*;
2
3#[property(LAYOUT, default((0, 0)))]
11pub fn offset(child: impl IntoUiNode, offset: impl IntoVar<Vector>) -> UiNode {
12 let offset = offset.into_var();
13 match_node(child, move |child, op| match op {
14 UiNodeOp::Init => {
15 WIDGET.sub_var_layout(&offset);
16 }
17 UiNodeOp::Layout { wl, final_size } => {
18 let size = child.layout(wl);
19 let offset = LAYOUT.with_constraints(PxConstraints2d::new_exact_size(LAYOUT.constraints().fill_size().max(size)), || {
20 offset.layout()
21 });
22 wl.translate(offset);
23 *final_size = size;
24 }
25 _ => {}
26 })
27}
28
29#[property(LAYOUT, default(0))]
37pub fn x(child: impl IntoUiNode, x: impl IntoVar<Length>) -> UiNode {
38 let x = x.into_var();
39 match_node(child, move |child, op| match op {
40 UiNodeOp::Init => {
41 WIDGET.sub_var_layout(&x);
42 }
43 UiNodeOp::Layout { wl, final_size } => {
44 let size = child.layout(wl);
45
46 let x = LAYOUT.with_constraints(PxConstraints2d::new_exact_size(LAYOUT.constraints().fill_size().max(size)), || {
47 x.layout_x()
48 });
49 wl.translate(PxVector::new(x, Px(0)));
50 *final_size = size;
51 }
52 _ => {}
53 })
54}
55
56#[property(LAYOUT, default(0))]
64pub fn y(child: impl IntoUiNode, y: impl IntoVar<Length>) -> UiNode {
65 let y = y.into_var();
66 match_node(child, move |child, op| match op {
67 UiNodeOp::Init => {
68 WIDGET.sub_var_layout(&y);
69 }
70 UiNodeOp::Layout { wl, final_size } => {
71 let size = child.layout(wl);
72 let y = LAYOUT.with_constraints(PxConstraints2d::new_exact_size(LAYOUT.constraints().fill_size().max(size)), || {
73 y.layout_y()
74 });
75 wl.translate(PxVector::new(Px(0), y));
76 *final_size = size;
77 }
78 _ => {}
79 })
80}