sidebar: add width option to override default size
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user