sidebar: add width option to override default size

This commit is contained in:
2026-11-16 04:36:05 +07:00
parent 0fda22caf7
commit 08dda223e5
2 changed files with 19 additions and 6 deletions
+16 -3
View File
@@ -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<SharedString>,
on_change: Option<ChangeHandler>,
entries: Option<EntriesFn>,
@@ -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<W>(mut self, width: W) -> Self
where
W: Into<Pixels>,
{
self.width = width.into();
self
}
/// Reports the next selected row, from clicks and keys alike.
pub fn on_change<F>(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))