Change sidebars to use the window width as a max width rather than participating in the flex

Kay Simmons and Mikayla created

co-authored-by: Mikayla <mikayla@zed.dev>

Change summary

crates/workspace/src/dock.rs      | 26 ++++++++++++++++++++++++--
crates/workspace/src/workspace.rs | 27 +++++++++++++++++++++++----
2 files changed, 47 insertions(+), 6 deletions(-)

Detailed changes

crates/workspace/src/dock.rs 🔗

@@ -2,8 +2,10 @@ use collections::HashMap;
 use gpui::{
     actions,
     elements::{ChildView, Container, Empty, MouseEventHandler, ParentElement, Side, Stack, Svg},
+    geometry::vector::Vector2F,
     impl_internal_actions, Border, CursorStyle, Element, ElementBox, Entity, MouseButton,
-    MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
+    MutableAppContext, RenderContext, SizeConstraint, View, ViewContext, ViewHandle,
+    WeakViewHandle,
 };
 use serde::Deserialize;
 use settings::{DockAnchor, Settings};
@@ -312,7 +314,27 @@ impl Dock {
                         }
                     });
 
-                    resizable.flex(5., false).boxed()
+                    if anchor == DockAnchor::Right {
+                        resizable
+                            .constrained()
+                            .dynamically(|constraint, cx| {
+                                SizeConstraint::new(
+                                    Vector2F::new(20., constraint.min.y()),
+                                    Vector2F::new(cx.window_size.x() * 0.8, constraint.max.y()),
+                                )
+                            })
+                            .boxed()
+                    } else {
+                        resizable
+                            .constrained()
+                            .dynamically(|constraint, cx| {
+                                SizeConstraint::new(
+                                    Vector2F::new(constraint.min.x(), 50.),
+                                    Vector2F::new(constraint.max.x(), cx.window_size.y() * 0.8),
+                                )
+                            })
+                            .boxed()
+                    }
                 }
                 DockAnchor::Expanded => {
                     enum ExpandedDockWash {}

crates/workspace/src/workspace.rs 🔗

@@ -32,12 +32,13 @@ use futures::{
 use gpui::{
     actions,
     elements::*,
+    geometry::vector::Vector2F,
     impl_actions, impl_internal_actions,
     keymap_matcher::KeymapContext,
     platform::{CursorStyle, WindowOptions},
     AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
-    MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View,
-    ViewContext, ViewHandle, WeakViewHandle,
+    MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, SizeConstraint,
+    Task, View, ViewContext, ViewHandle, WeakViewHandle,
 };
 use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
 use language::LanguageRegistry;
@@ -2471,7 +2472,16 @@ impl View for Workspace {
                                         if self.left_sidebar.read(cx).active_item().is_some() {
                                             Some(
                                                 ChildView::new(&self.left_sidebar, cx)
-                                                    .flex(0.8, false)
+                                                    .constrained()
+                                                    .dynamically(|constraint, cx| {
+                                                        SizeConstraint::new(
+                                                            Vector2F::new(20., constraint.min.y()),
+                                                            Vector2F::new(
+                                                                cx.window_size.x() * 0.8,
+                                                                constraint.max.y(),
+                                                            ),
+                                                        )
+                                                    })
                                                     .boxed(),
                                             )
                                         } else {
@@ -2508,7 +2518,16 @@ impl View for Workspace {
                                         if self.right_sidebar.read(cx).active_item().is_some() {
                                             Some(
                                                 ChildView::new(&self.right_sidebar, cx)
-                                                    .flex(0.8, false)
+                                                    .constrained()
+                                                    .dynamically(|constraint, cx| {
+                                                        SizeConstraint::new(
+                                                            Vector2F::new(20., constraint.min.y()),
+                                                            Vector2F::new(
+                                                                cx.window_size.x() * 0.8,
+                                                                constraint.max.y(),
+                                                            ),
+                                                        )
+                                                    })
                                                     .boxed(),
                                             )
                                         } else {