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
+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()
}