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
//! sidebar's model of rows grouped under non-selectable labels. Custom content
//! replaces the list and takes the whole container; the header and footer
//! slots apply only to the entry list.
//! replaces the list and takes the whole container, sliding under a pinned
//! strip; the header and footer slots apply only to the entry list.
use std::rc::Rc;
@@ -124,6 +124,7 @@ pub struct Sidebar {
header: Option<AnyElement>,
content: Option<AnyElement>,
footer: Option<AnyElement>,
strip: Option<AnyElement>,
}
impl Sidebar {
@@ -142,6 +143,7 @@ impl Sidebar {
header: None,
content: None,
footer: None,
strip: None,
}
}
@@ -207,6 +209,15 @@ impl Sidebar {
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.
pub fn accessibility_label<L>(mut self, label: L) -> Self
where
@@ -229,6 +240,7 @@ impl RenderOnce for Sidebar {
header,
content,
footer,
strip,
} = self;
let custom = content.is_some();
@@ -344,6 +356,15 @@ impl RenderOnce for Sidebar {
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()
.id(id.clone())
.debug_selector(move || format!("sidebar-{debug_id}"))
@@ -355,9 +376,11 @@ impl RenderOnce for Sidebar {
.when(custom, |sidebar| {
sidebar.role(Role::Group).aria_label(label)
})
.when_some(leading_strip, |sidebar, strip| sidebar.child(strip))
.when_some(header, |sidebar, header| sidebar.child(header))
.child(body)
.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()
.when(left_visible && left.is_some(), |layout| {
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
.child(sidebar_region(
(id.clone(), "left"),
width,
left.take()
.map(|sidebar| sidebar.into_any_element())
.unwrap_or_else(|| div().into_any_element()),
&state,
Titlebar {
side: Side::Left,
material: left_material,
height: titlebar_height,
padding_x: metrics.dense_padding_x,
toggle: strip_toggles,
},
window,
cx,
))
.child(
v_flex()
.w(width)
.h_full()
.overflow_hidden()
.when(!left_material, |region| region.bg(background))
.child(
left.take()
.map(|sidebar| {
sidebar
.strip(sidebar_strip(
(id.clone(), "left"),
titlebar,
&state,
window,
cx,
))
.into_any_element()
})
.unwrap_or_else(|| div().into_any_element()),
),
)
.child(ResizeHandle::new((id.clone(), "left-resize")).on_resize({
let state = state.clone();
move |delta, _, cx| {
@@ -398,7 +410,6 @@ struct Titlebar {
toggle: bool,
}
/// One sidebar: a header strip with the hide toggle over the app's content.
fn sidebar_region<I>(
id: I,
width: Pixels,
@@ -411,20 +422,37 @@ fn sidebar_region<I>(
where
I: Into<ElementId>,
{
let id = id.into();
let theme = cx.theme();
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"))
.debug_selector(move || format!("sidebar-strip-{}", titlebar.side.name()))
.flex_none()
.h(titlebar.height)
.bg(strip_background)
.occlude()
.items_center()
.map(|strip| match titlebar.side {
Side::Left => strip.when(cfg!(target_os = "macos"), |strip| {
@@ -449,20 +477,6 @@ where
))
}),
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()
}