data: add pinned strip overlay for sidebar custom content

This commit is contained in:
2026-11-12 05:00:40 +07:00
parent 97106b7a3a
commit 72118bdd6c
2 changed files with 79 additions and 42 deletions
+25 -2
View File
@@ -1,7 +1,7 @@
//! The sidebar: a controlled list with section headers — the Finder //! The sidebar: a controlled list with section headers — the Finder
//! sidebar's model of rows grouped under non-selectable labels. Custom content //! sidebar's model of rows grouped under non-selectable labels. Custom content
//! replaces the list and takes the whole container; the header and footer //! replaces the list and takes the whole container, sliding under a pinned
//! slots apply only to the entry list. //! strip; the header and footer slots apply only to the entry list.
use std::rc::Rc; use std::rc::Rc;
@@ -124,6 +124,7 @@ pub struct Sidebar {
header: Option<AnyElement>, header: Option<AnyElement>,
content: Option<AnyElement>, content: Option<AnyElement>,
footer: Option<AnyElement>, footer: Option<AnyElement>,
strip: Option<AnyElement>,
} }
impl Sidebar { impl Sidebar {
@@ -142,6 +143,7 @@ impl Sidebar {
header: None, header: None,
content: None, content: None,
footer: None, footer: None,
strip: None,
} }
} }
@@ -207,6 +209,15 @@ impl Sidebar {
self self
} }
/// Pins a titlebar strip at the sidebar's top, custom content renders behind it.
pub fn strip<E>(mut self, strip: E) -> Self
where
E: IntoElement,
{
self.strip = Some(strip.into_any_element());
self
}
/// Overrides the accessibility label, which defaults to the id. /// Overrides the accessibility label, which defaults to the id.
pub fn accessibility_label<L>(mut self, label: L) -> Self pub fn accessibility_label<L>(mut self, label: L) -> Self
where where
@@ -229,6 +240,7 @@ impl RenderOnce for Sidebar {
header, header,
content, content,
footer, footer,
strip,
} = self; } = self;
let custom = content.is_some(); let custom = content.is_some();
@@ -344,6 +356,15 @@ impl RenderOnce for Sidebar {
let theme = cx.theme(); let theme = cx.theme();
let (leading_strip, overlay_strip) = match strip {
Some(strip) if custom => (
None,
Some(div().absolute().top_0().left_0().right_0().child(strip)),
),
Some(strip) => (Some(strip), None),
None => (None, None),
};
div() div()
.id(id.clone()) .id(id.clone())
.debug_selector(move || format!("sidebar-{debug_id}")) .debug_selector(move || format!("sidebar-{debug_id}"))
@@ -355,9 +376,11 @@ impl RenderOnce for Sidebar {
.when(custom, |sidebar| { .when(custom, |sidebar| {
sidebar.role(Role::Group).aria_label(label) sidebar.role(Role::Group).aria_label(label)
}) })
.when_some(leading_strip, |sidebar, strip| sidebar.child(strip))
.when_some(header, |sidebar, header| sidebar.child(header)) .when_some(header, |sidebar, header| sidebar.child(header))
.child(body) .child(body)
.when_some(footer, |sidebar, footer| sidebar.child(footer)) .when_some(footer, |sidebar, footer| sidebar.child(footer))
.when_some(overlay_strip, |sidebar, strip| sidebar.child(strip))
} }
} }
+54 -40
View File
@@ -265,24 +265,36 @@ impl RenderOnce for Shell {
.overflow_hidden() .overflow_hidden()
.when(left_visible && left.is_some(), |layout| { .when(left_visible && left.is_some(), |layout| {
let width = state.read(cx).left_sidebar_width(); let width = state.read(cx).left_sidebar_width();
let titlebar = Titlebar {
side: Side::Left,
material: left_material,
height: titlebar_height,
padding_x: metrics.dense_padding_x,
toggle: strip_toggles,
};
layout layout
.child(sidebar_region( .child(
(id.clone(), "left"), v_flex()
width, .w(width)
left.take() .h_full()
.map(|sidebar| sidebar.into_any_element()) .overflow_hidden()
.unwrap_or_else(|| div().into_any_element()), .when(!left_material, |region| region.bg(background))
&state, .child(
Titlebar { left.take()
side: Side::Left, .map(|sidebar| {
material: left_material, sidebar
height: titlebar_height, .strip(sidebar_strip(
padding_x: metrics.dense_padding_x, (id.clone(), "left"),
toggle: strip_toggles, titlebar,
}, &state,
window, window,
cx, cx,
)) ))
.into_any_element()
})
.unwrap_or_else(|| div().into_any_element()),
),
)
.child(ResizeHandle::new((id.clone(), "left-resize")).on_resize({ .child(ResizeHandle::new((id.clone(), "left-resize")).on_resize({
let state = state.clone(); let state = state.clone();
move |delta, _, cx| { move |delta, _, cx| {
@@ -398,7 +410,6 @@ struct Titlebar {
toggle: bool, toggle: bool,
} }
/// One sidebar: a header strip with the hide toggle over the app's content.
fn sidebar_region<I>( fn sidebar_region<I>(
id: I, id: I,
width: Pixels, width: Pixels,
@@ -411,20 +422,37 @@ fn sidebar_region<I>(
where where
I: Into<ElementId>, I: Into<ElementId>,
{ {
let id = id.into();
let theme = cx.theme(); let theme = cx.theme();
let background = theme.colors.background; let background = theme.colors.background;
let strip_background = match (titlebar.side, titlebar.material) {
(Side::Left, true) => theme.material.background,
_ => theme.colors.background,
};
let strip = h_flex() v_flex()
.w(width)
.h_full()
.overflow_hidden()
.when(!titlebar.material, |region| region.bg(background))
.child(sidebar_strip(id, titlebar, state, window, cx))
.child(div().flex_1().min_h_0().overflow_hidden().child(content))
.into_any_element()
}
fn sidebar_strip<I>(
id: I,
titlebar: Titlebar,
state: &Entity<LayoutState>,
window: &mut Window,
cx: &mut App,
) -> AnyElement
where
I: Into<ElementId>,
{
let id = id.into();
h_flex()
.id((id.clone(), "strip")) .id((id.clone(), "strip"))
.debug_selector(move || format!("sidebar-strip-{}", titlebar.side.name())) .debug_selector(move || format!("sidebar-strip-{}", titlebar.side.name()))
.flex_none() .flex_none()
.h(titlebar.height) .h(titlebar.height)
.bg(strip_background) .occlude()
.items_center() .items_center()
.map(|strip| match titlebar.side { .map(|strip| match titlebar.side {
Side::Left => strip.when(cfg!(target_os = "macos"), |strip| { Side::Left => strip.when(cfg!(target_os = "macos"), |strip| {
@@ -449,20 +477,6 @@ where
)) ))
}), }),
Side::Right => strip.child(WindowControls::new((id, "window-controls"))), Side::Right => strip.child(WindowControls::new((id, "window-controls"))),
}); })
v_flex()
.w(width)
.h_full()
.overflow_hidden()
.child(strip)
.child(
div()
.flex_1()
.min_h_0()
.overflow_hidden()
.when(!titlebar.material, |content| content.bg(background))
.child(content),
)
.into_any_element() .into_any_element()
} }