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