1    def arrange_offset (control : Container
2                        control_width : u32
3                        control_height : u32
4                        left : u32
5                        up : u32
6                        down : u32) =
7        let maybe_child = control.get_slice.try_single
8        if maybe_child.is_none then
9            return
10   
11       let child = maybe_child.unwrap
12       let align_h = child.align_h
13       let align_v = child.align_v
14       let width = if align_h == AlignH/Stretch
15                   then control_width
16                   else control_width.min child.measure_width
17   
18       let height = if align_v == AlignV/Stretch
19                    then control_height.max child.measure_height
20                    else child.measure_height
21   
22       child.width = width
23             height = height
24             arrange
25   
26       let child_width = child.width
27       assert child_width <= control_width
28       let x = if child_width == control_width
29               then 0
30               else
31                   case align_h of
32                       AlignH/Left | AlignH/Stretch -> 0
33                       AlignH/Right -> control_width - child_width
34                       AlignH/Center -> (control_width - child_width) / 2
35                   |> as<f32>
36   
37       let child_height = child.height
38       let y = if child_height >= control_height
39               then 0
40               else
41                   case align_v of
42                       AlignV/Up | AlignV/Stretch -> 0
43                       AlignV/Down -> control_height - child.height
44                       AlignV/Center -> (control_height - child.height) / 2
45                   |> as<f32>
46   
47       let v = Vector3 (x + left as f32) (y + up as f32) Control.offset_z
48       child.position = v
49       let min_control_height = up + child_height + down
50       if control.height < min_control_height then
51           control.height = min_control_height
52   
53   def arrange_single_child (control : Container) =
54       arrange_offset control control.width control.height 0 0 0
55   
56   def arrange_measured (control : Control) =
57       control.width = control.measure_width
58               height = control.measure_height
59               arrange
60   
61   def arrange_unmeasured (control : Control
62                           w : u32
63                           h : u32) =
64       measure_clamped control w h
65       arrange_measured control
66