From 08dda223e5002a6f95696bd80d292fb45c699177 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Mon, 16 Nov 2026 04:36:05 +0700 Subject: [PATCH] sidebar: add width option to override default size --- crates/data/src/sidebar.rs | 19 ++++++++++++++++--- examples/gallery/src/main.rs | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/data/src/sidebar.rs b/crates/data/src/sidebar.rs index 294d5c1..e85dea2 100644 --- a/crates/data/src/sidebar.rs +++ b/crates/data/src/sidebar.rs @@ -7,8 +7,8 @@ use std::rc::Rc; use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, - ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, - Styled as _, Window, div, + ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, + Styled as _, Window, div, px, }; use gpui_native_core::grain::grain as grain_overlay; use gpui_native_core::scroll_area::ScrollArea; @@ -140,6 +140,7 @@ pub struct Sidebar { grain: bool, border_right: bool, padded: bool, + width: Pixels, a11y_label: Option, on_change: Option, entries: Option, @@ -158,6 +159,7 @@ impl Sidebar { grain: false, border_right: true, padded: true, + width: px(240.0), a11y_label: None, on_change: None, entries: None, @@ -210,6 +212,15 @@ impl Sidebar { self.padded } + /// Sets the sidebar's width, overriding the default. + pub fn width(mut self, width: W) -> Self + where + W: Into, + { + self.width = width.into(); + self + } + /// Reports the next selected row, from clicks and keys alike. pub fn on_change(mut self, handler: F) -> Self where @@ -247,6 +258,7 @@ impl RenderOnce for Sidebar { grain, border_right, padded, + width, a11y_label, on_change, entries, @@ -355,7 +367,8 @@ impl RenderOnce for Sidebar { div() .id(id.clone()) .debug_selector(move || format!("sidebar-{debug_id}")) - .size_full() + .h_full() + .w(width) .flex() .flex_col() .when(material, |sidebar| sidebar.bg(theme.material.background)) diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index 97bdf6b..f4a89d2 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -4210,7 +4210,7 @@ impl Render for SidebarDemo { "standalone; the app's own left sidebar is this component", colors, div() - .w(rems(17.5)) + .w(rems(15.)) .h(rems(22.5)) .rounded(radius.control) .border_1() @@ -4260,7 +4260,7 @@ impl Render for SidebarDemo { "custom entries slot user content around the rows", colors, div() - .w(rems(17.5)) + .w(rems(15.)) .h(rems(22.5)) .rounded(radius.control) .border_1() @@ -4307,7 +4307,7 @@ impl Render for SidebarDemo { "a custom entry fills the list; the right border is off", colors, div() - .w(rems(17.5)) + .w(rems(15.)) .h(rems(13.)) .rounded(radius.control) .border_1()