1     let distance = 0
2     let separator_width = 7
3     let default_offset = (separator_width + distance) / 2
4     
5     type Resizer @mut =
6         inherit Container
7     
8         var obs first : Option<Control> @dst = None
9         var obs second : Option<Control> @dst = None
10        var is_first_primary = true
11        var separator_offset : i32 = 0
12    
13        let mut delta : i32 = 0
14    
15        let first_presenter = Presenter
16            content@obs = first@obs
17    
18        let second_presenter = Presenter
19            content@obs = second@obs
20    
21        let border = Border
22            is_receive_mouse_move = true
23            run@ set_fixed_width separator_width
24    
25        let children = [first_presenter, border, second_presenter]
26    
27        def Container.get_slice =
28            SafeSlice<Control>.create children.as_ptr children.size
29    
30        border.parent = self
31        first_presenter.parent = self
32        second_presenter.parent = self
33    
34        border.subscribe { _, event -> if event is MouseEvent/Move then
35            let left_x = event.x as i32 - event.begin_relative_x as i32
36            delta = left_x - border.global_position.x as i32 }
37    
38        def Control.measure w h =
39            let first_control = first.unwrap
40            let second_control = second.unwrap
41            measure_clamped first_control 0 h
42            measure_clamped second_control 0 h
43    
44            assert w == 0
45                   || first_control.measure_width + second_control.measure_width
46                      + distance <= w
47    
48            if first_presenter.width < first_control.measure_width then
49                let diff = first_control.measure_width - first_presenter.width
50                first_presenter.set_fixed_width first_control.measure_width
51                if second_presenter.width >= diff then
52                    let second_w = second_presenter.width - diff
53                                   |> max second_control.measure_width
54                    second_presenter.set_fixed_width second_w
55    
56            if second_presenter.width < second_control.measure_width then
57                let diff = second_control.measure_width - second_presenter.width
58                second_presenter.set_fixed_width second_control.measure_width
59                if first_presenter.width >= diff then
60                    let first_w = first_presenter.width - diff
61                                  |> max first_control.measure_width
62                    first_presenter.set_fixed_width first_w
63    
64            if first_presenter.width + second_presenter.width + distance <> w
65            then
66                if is_first_primary then
67                    if second_presenter.width == 0 && second_control.measure_width <> 0
68                    then
69                        second_presenter.set_fixed_width second_control.measure_width
70    
71                    let first_w = if w < second_presenter.width + distance
72                                  then first_control.measure_width
73                                  else w - second_presenter.width - distance
74                                       |> max first_control.measure_width
75    
76                    first_presenter.set_fixed_width first_w
77                    if w <> 0
78                       && first_w + second_presenter.width + distance > w
79                    then
80                        let second_w = w - first_w - distance
81                        second_presenter.set_fixed_width second_w
82                else
83                    if first_presenter.width == 0 && first_control.measure_width <> 0
84                    then
85                        first_presenter.set_fixed_width first_control.measure_width
86    
87                    let second_w = if w < first_presenter.width + distance
88                                   then second_control.measure_width
89                                   else w - first_presenter.width - distance
90                                        |> max second_control.measure_width
91    
92                    second_presenter.set_fixed_width second_w
93                    if w <> 0
94                       && second_w + first_presenter.width + distance > w
95                    then
96                        let first_w = w - second_w - distance
97                        first_presenter.set_fixed_width first_w
98    
99            if delta <> 0 && w <> 0 then
100               let (first_w, second_w) = if delta < 0 then
101                   let first_w = first_presenter.width as i32 + delta
102                                 |> max first_control.measure_width.as<i32>
103                                 |> as<u32>
104                   let second_w = w - first_w - distance
105                   (first_w, second_w)
106               else
107                   let second_w = second_presenter.width as i32 - delta
108                                  |> max second_control.measure_width.as<i32>
109                                  |> as<u32>
110                   let first_w = w - second_w - distance
111                   (first_w, second_w)
112   
113               first_presenter.set_fixed_width first_w
114               second_presenter.set_fixed_width second_w
115               delta = 0
116   
117           measure_clamped first_control first_presenter.width h
118           measure_clamped second_control second_presenter.width h
119   
120           measure_width = if w == 0 then
121               first_control.measure_width + second_control.measure_width
122               + distance
123           else
124               first_presenter.width + second_presenter.width + distance
125   
126           measure_height =
127               first_control.measure_height.max second_control.measure_height
128   
129       def Control.arrange =
130           let second_x = first_presenter.width + distance |> as<f32>
131   
132           border.height = height
133                  position = Vector3 x = second_x - default_offset.as<f32>
134                                         + separator_offset.as<f32>
135                                     y = 0
136                                     z = -1
137   
138           first_presenter.height = height
139                           arrange
140   
141           second_presenter.height = height
142                            position = Vector3 second_x 0 0
143                            arrange
144