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