Move layout metrics into theme and apply audit cleanups

This commit is contained in:
2026-11-09 15:59:13 +07:00
parent 122f9b12ae
commit 2e7711ee2e
32 changed files with 762 additions and 972 deletions
+20 -40
View File
@@ -4,8 +4,7 @@
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, AppContext as _, Context, ElementId, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, Pixels, RenderOnce, SharedString, Styled as _, Window, div,
px,
IntoElement, ParentElement as _, Pixels, RenderOnce, Styled as _, Window, div, px,
};
use gpui_native_core::button::{Button, ButtonVariant};
use gpui_native_core::common::{Sizable as _, h_flex, v_flex};
@@ -108,20 +107,6 @@ impl Side {
Side::Right => "right",
}
}
fn toggle_icon(self) -> IconRole {
match self {
Side::Left => IconRole::PanelLeft,
Side::Right => IconRole::PanelRight,
}
}
fn toggle_label(self) -> SharedString {
match self {
Side::Left => SharedString::from("Hide left sidebar"),
Side::Right => SharedString::from("Hide right sidebar"),
}
}
}
/// The application shell.
@@ -204,6 +189,7 @@ impl RenderOnce for Shell {
let width = state.read(cx).left_sidebar_width();
layout
.child(sidebar_region(
(id.clone(), "left"),
width,
left.take()
.map(|sidebar| sidebar.into_any_element())
@@ -242,6 +228,7 @@ impl RenderOnce for Shell {
}
}))
.child(sidebar_region(
(id.clone(), "right"),
width,
right.take().unwrap_or_else(|| div().into_any_element()),
Side::Right,
@@ -262,6 +249,7 @@ impl RenderOnce for Shell {
/// One sidebar: a header strip with the hide toggle over the app's content.
#[allow(clippy::too_many_arguments)]
fn sidebar_region(
id: impl Into<ElementId>,
width: Pixels,
content: AnyElement,
side: Side,
@@ -272,6 +260,7 @@ fn sidebar_region(
window: &mut Window,
cx: &mut App,
) -> AnyElement {
let id = id.into();
let theme = cx.theme();
let background = theme.colors.background;
let strip_background = match (side, material) {
@@ -280,7 +269,7 @@ fn sidebar_region(
};
let strip = h_flex()
.id(SharedString::from(format!("sidebar-strip-{}", side.name())))
.id((id.clone(), "strip"))
.debug_selector(move || format!("sidebar-strip-{}", side.name()))
.flex_none()
.h(strip_height)
@@ -288,40 +277,31 @@ fn sidebar_region(
.items_center()
.map(|strip| match side {
Side::Left => strip.when(cfg!(target_os = "macos"), |strip| {
strip.pl(px(TRAFFIC_LIGHT_PAD))
strip.pl(TRAFFIC_LIGHT_PAD)
}),
Side::Right => strip,
})
.px(padding_x)
.child(titlebar_strip(
div()
.id(SharedString::from(format!(
"sidebar-strip-drag-{}",
side.name()
)))
.flex_1()
.self_stretch(),
div().id((id.clone(), "strip-drag")).flex_1().self_stretch(),
window,
cx,
))
.map(|strip| match side {
Side::Left => strip.child(
Button::new(SharedString::from(format!(
"sidebar-toggle-{}",
side.name()
)))
.icon(side.toggle_icon())
.variant(ButtonVariant::Ghost)
.small()
.accessibility_label(side.toggle_label())
.on_click({
let state = state.clone();
move |_, _, cx| {
state.update(cx, |state, cx| state.set_left_sidebar_visible(false, cx))
}
}),
Button::new((id, "sidebar-toggle"))
.icon(IconRole::PanelLeft)
.variant(ButtonVariant::Ghost)
.small()
.accessibility_label("Hide left sidebar")
.on_click({
let state = state.clone();
move |_, _, cx| {
state.update(cx, |state, cx| state.set_left_sidebar_visible(false, cx))
}
}),
),
Side::Right => strip.child(WindowControls::new("sidebar-window-controls")),
Side::Right => strip.child(WindowControls::new((id, "window-controls"))),
});
v_flex()