From 913775c6326708ebf6261a7c0ff60e7cdf25269b Mon Sep 17 00:00:00 2001 From: xda <150917089+xda2023@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:39:00 +0900 Subject: [PATCH] resizable: Fix the bug for parent groups when initializing Panels with sizes Some and None (#356) Optimization of https://github.com/longbridgeapp/gpui-component/pull/329 The issue with the initial width of the Panel has been optimised to ensure that the left side of a Panel combination like [Some(px(510.)), None] is initially rendered with a width of 510px. --------- Co-authored-by: Jason Lee --- crates/ui/src/resizable/panel.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ui/src/resizable/panel.rs b/crates/ui/src/resizable/panel.rs index 08250154..dfb29a16 100644 --- a/crates/ui/src/resizable/panel.rs +++ b/crates/ui/src/resizable/panel.rs @@ -351,7 +351,8 @@ impl FluentBuilder for ResizablePanel {} impl Render for ResizablePanel { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { let view = cx.view().clone(); - + let total_size = self.group.as_ref().map(|group| group.read(cx).total_size()); + div() .flex() .flex_grow() @@ -366,9 +367,16 @@ impl Render for ResizablePanel { this.when(self.size.is_none(), |this| this.flex_shrink_0()) .flex_basis(size) }) - .when_some(self.size_ratio, |this, size_ratio| { - this.flex_basis(relative(size_ratio)) - }) + .map( + |this| match (self.size_ratio, self.size, total_size) { + (Some(size_ratio), _, _) => this.flex_basis(relative(size_ratio)), + (None, Some(size), Some(total_size)) => { + this.flex_basis(relative(size / total_size)) + } + (None, Some(size), None) => this.flex_basis(size), + _ => this, + }, + ) .child({ canvas( move |bounds, cx| view.update(cx, |r, cx| r.update_size(bounds, cx)),