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::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
|
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
|
||||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||||
Styled as _, Window, div,
|
Styled as _, Window, div, px,
|
||||||
};
|
};
|
||||||
use gpui_native_core::grain::grain as grain_overlay;
|
use gpui_native_core::grain::grain as grain_overlay;
|
||||||
use gpui_native_core::scroll_area::ScrollArea;
|
use gpui_native_core::scroll_area::ScrollArea;
|
||||||
@@ -140,6 +140,7 @@ pub struct Sidebar {
|
|||||||
grain: bool,
|
grain: bool,
|
||||||
border_right: bool,
|
border_right: bool,
|
||||||
padded: bool,
|
padded: bool,
|
||||||
|
width: Pixels,
|
||||||
a11y_label: Option<SharedString>,
|
a11y_label: Option<SharedString>,
|
||||||
on_change: Option<ChangeHandler>,
|
on_change: Option<ChangeHandler>,
|
||||||
entries: Option<EntriesFn>,
|
entries: Option<EntriesFn>,
|
||||||
@@ -158,6 +159,7 @@ impl Sidebar {
|
|||||||
grain: false,
|
grain: false,
|
||||||
border_right: true,
|
border_right: true,
|
||||||
padded: true,
|
padded: true,
|
||||||
|
width: px(240.0),
|
||||||
a11y_label: None,
|
a11y_label: None,
|
||||||
on_change: None,
|
on_change: None,
|
||||||
entries: None,
|
entries: None,
|
||||||
@@ -210,6 +212,15 @@ impl Sidebar {
|
|||||||
self.padded
|
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.
|
/// Reports the next selected row, from clicks and keys alike.
|
||||||
pub fn on_change<F>(mut self, handler: F) -> Self
|
pub fn on_change<F>(mut self, handler: F) -> Self
|
||||||
where
|
where
|
||||||
@@ -247,6 +258,7 @@ impl RenderOnce for Sidebar {
|
|||||||
grain,
|
grain,
|
||||||
border_right,
|
border_right,
|
||||||
padded,
|
padded,
|
||||||
|
width,
|
||||||
a11y_label,
|
a11y_label,
|
||||||
on_change,
|
on_change,
|
||||||
entries,
|
entries,
|
||||||
@@ -355,7 +367,8 @@ impl RenderOnce for Sidebar {
|
|||||||
div()
|
div()
|
||||||
.id(id.clone())
|
.id(id.clone())
|
||||||
.debug_selector(move || format!("sidebar-{debug_id}"))
|
.debug_selector(move || format!("sidebar-{debug_id}"))
|
||||||
.size_full()
|
.h_full()
|
||||||
|
.w(width)
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.when(material, |sidebar| sidebar.bg(theme.material.background))
|
.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",
|
"standalone; the app's own left sidebar is this component",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(17.5))
|
.w(rems(15.))
|
||||||
.h(rems(22.5))
|
.h(rems(22.5))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
@@ -4260,7 +4260,7 @@ impl Render for SidebarDemo {
|
|||||||
"custom entries slot user content around the rows",
|
"custom entries slot user content around the rows",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(17.5))
|
.w(rems(15.))
|
||||||
.h(rems(22.5))
|
.h(rems(22.5))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
@@ -4307,7 +4307,7 @@ impl Render for SidebarDemo {
|
|||||||
"a custom entry fills the list; the right border is off",
|
"a custom entry fills the list; the right border is off",
|
||||||
colors,
|
colors,
|
||||||
div()
|
div()
|
||||||
.w(rems(17.5))
|
.w(rems(15.))
|
||||||
.h(rems(13.))
|
.h(rems(13.))
|
||||||
.rounded(radius.control)
|
.rounded(radius.control)
|
||||||
.border_1()
|
.border_1()
|
||||||
|
|||||||
Reference in New Issue
Block a user