From b8c8ddd8f566342dadf067f3adab414760753371 Mon Sep 17 00:00:00 2001 From: xda <150917089+xda2023@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:07:45 +0900 Subject: [PATCH] resizable: Fix the edge case of initializing Panels with zero initial_size (#377) --- crates/ui/src/resizable/panel.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/ui/src/resizable/panel.rs b/crates/ui/src/resizable/panel.rs index 9d8cdcc2..7453a531 100644 --- a/crates/ui/src/resizable/panel.rs +++ b/crates/ui/src/resizable/panel.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use gpui::{ canvas, div, prelude::FluentBuilder, px, relative, Along, AnyElement, AnyView, Axis, Bounds, - Element, Entity, EntityId, EventEmitter, IntoElement, MouseMoveEvent, MouseUpEvent, + Element, Entity, EntityId, EventEmitter, IntoElement, IsZero, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Render, StatefulInteractiveElement as _, Style, Styled, View, ViewContext, VisualContext as _, WindowContext, }; @@ -362,10 +362,16 @@ impl Render for ResizablePanel { .when(self.axis.is_vertical(), |this| this.min_h(PANEL_MIN_SIZE)) .when(self.axis.is_horizontal(), |this| this.min_w(PANEL_MIN_SIZE)) .when_some(self.initial_size, |this, size| { - // The `self.size` is None, that mean the initial size for the panel, so we need set flex_shrink_0 - // To let it keep the initial size. - this.when(self.size.is_none(), |this| this.flex_shrink_0()) + if size.is_zero() { + this + } else { + // The `self.size` is None, that mean the initial size for the panel, so we need set flex_shrink_0 + // To let it keep the initial size. + this.when(self.size.is_none() && size > px(0.), |this| { + this.flex_shrink_0() + }) .flex_basis(size) + } }) .map(|this| match (self.size_ratio, self.size, total_size) { (Some(size_ratio), _, _) => this.flex_basis(relative(size_ratio)),