From 57c1da2441faa6ff37fffc36feddd57f1ea248f6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 20 Dec 2024 19:02:55 +0800 Subject: [PATCH] panel: To keep panel size when it going to hidden. (#505) This change for make sure when Panel to hide and show, the original panel size will keep. --- crates/ui/src/resizable/panel.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/ui/src/resizable/panel.rs b/crates/ui/src/resizable/panel.rs index 2669f47a..f47a7106 100644 --- a/crates/ui/src/resizable/panel.rs +++ b/crates/ui/src/resizable/panel.rs @@ -340,14 +340,10 @@ impl ResizablePanel { self.bounds = bounds; self.size = Some(new_size); - let panel_view = cx.view().clone(); + let entity_id = cx.view().entity_id(); if let Some(group) = self.group.as_ref() { _ = group.update(cx, |view, _| { - if let Some(ix) = view - .panels - .iter() - .position(|v| v.entity_id() == panel_view.entity_id()) - { + if let Some(ix) = view.panels.iter().position(|v| v.entity_id() == entity_id) { view.sizes[ix] = new_size; } }); @@ -361,6 +357,9 @@ impl FluentBuilder for ResizablePanel {} impl Render for ResizablePanel { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { if !(self.content_visible)(cx) { + // To keep size as initial size, to make sure the size will not be changed. + self.initial_size = self.size; + self.size = None; return div(); }