From 819a826a3154d19ead4b70ec2a9e3bfe33043dbd Mon Sep 17 00:00:00 2001 From: JoeZane Date: Fri, 30 May 2025 01:25:22 +0800 Subject: [PATCH] upd: fix container layout size error when children count is 0. --- examples/remove_demo/remove_widget.rs | 18 ++++++++++++++++++ tmui/src/layout.rs | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/examples/remove_demo/remove_widget.rs b/examples/remove_demo/remove_widget.rs index 84e98d1..8117cef 100644 --- a/examples/remove_demo/remove_widget.rs +++ b/examples/remove_demo/remove_widget.rs @@ -35,9 +35,11 @@ impl ObjectImpl for RemoveWidget { self.parent_construct(); self.bottom.set_margin_top(5); + self.bottom.set_background(Color::GREY_LIGHT); self.set_hexpand(true); self.set_vexpand(true); + let mut button_0 = Button::new(Some("Remove 1th")); let mut button_1 = Button::new(Some("Remove Left")); let mut button_2 = Button::new(Some("Remove Right")); let mut button_3 = Button::new(Some("Remove Stack")); @@ -45,6 +47,8 @@ impl ObjectImpl for RemoveWidget { let mut button_5 = Button::new(Some("Remove SplitPane RightTop")); let mut button_6 = Button::new(Some("Remove SplitPane RightBottomLeft")); let mut button_7 = Button::new(Some("Remove SplitPane RightBottomRight")); + button_0.width_request(100); + button_1.width_request(100); button_1.width_request(100); button_2.width_request(100); button_3.width_request(100); @@ -52,6 +56,12 @@ impl ObjectImpl for RemoveWidget { button_5.width_request(200); button_6.width_request(200); button_7.width_request(200); + connect!( + button_0, + mouse_pressed(), + self, + remove_0th_pressed(MouseEvent) + ); connect!( button_1, mouse_pressed(), @@ -94,6 +104,7 @@ impl ObjectImpl for RemoveWidget { self, remove_split_pane_right_bottom_right(MouseEvent) ); + self.top.add_child(button_0); self.top.add_child(button_1); self.top.add_child(button_2); self.top.add_child(button_3); @@ -123,6 +134,13 @@ impl RemoveWidget { Self::new_alloc() } + pub fn remove_0th_pressed(&mut self, _: MouseEvent) { + let id = self.bottom.children().first().map(|c| c.id()); + if let Some(id) = id { + self.bottom.remove_children(id); + } + } + pub fn remove_left_pressed(&mut self, _: MouseEvent) { self.bottom.remove_children(self.to_remove); } diff --git a/tmui/src/layout.rs b/tmui/src/layout.rs index f749592..f37316c 100644 --- a/tmui/src/layout.rs +++ b/tmui/src/layout.rs @@ -383,6 +383,8 @@ impl SizeCalculation for dyn WidgetImpl { } else { if self.detecting_width() != 0 { self.set_fixed_width(self.detecting_width()) + } else { + self.set_fixed_width(0); } } } @@ -442,6 +444,8 @@ impl SizeCalculation for dyn WidgetImpl { } else { if self.detecting_height() != 0 { self.set_fixed_height(self.detecting_height()) + } else { + self.set_fixed_height(0); } } }