Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

sidebar: Fix window controls shifting when the sidebar is open (#64381)

PIYUSH RATHORE6fae7f351370
diff --git a/crates/agent_ui/src/threads_archive_view.rs b/crates/agent_ui/src/threads_archive_view.rs
index 09a3ea8c969..ca56756195b 100644
--- a/crates/agent_ui/src/threads_archive_view.rs
+++ b/crates/agent_ui/src/threads_archive_view.rs
@@ -28,6 +28,7 @@ use picker::{
Picker, PickerDelegate,
highlighted_match_with_paths::{HighlightedMatch, HighlightedMatchWithPaths},
};
+use platform_title_bar::apply_title_bar_insets;
use project::{AgentId, AgentServerStore};
use settings::Settings as _;
use theme::ActiveTheme;
@@ -869,7 +870,12 @@ impl ThreadsArchiveView {
h_flex()
.h(header_height)
.map(|header| match window.window_decorations() {
- Decorations::Client { .. } => header.mt(px(-1.)),
+ Decorations::Client { .. } => apply_title_bar_insets(
+ header,
+ left_window_controls,
+ right_window_controls,
+ false,
+ ),
Decorations::Server => header.mt_px().pb_px(),
})
.when(left_window_controls, |this| {
diff --git a/crates/platform_title_bar/src/platform_title_bar.rs b/crates/platform_title_bar/src/platform_title_bar.rs
index b44f019ff43..b69bb0d1ff0 100644
--- a/crates/platform_title_bar/src/platform_title_bar.rs
+++ b/crates/platform_title_bar/src/platform_title_bar.rs
@@ -25,6 +25,29 @@ pub use system_window_tabs::{
DraggedWindowTab, MergeAllWindows, MoveTabToNewWindow, ShowNextWindowTab, ShowPreviousWindowTab,
};
+/// With client-side decorations, the title bar is pulled over the window frame's
+/// border to avoid a transparent gap in the rounded corners, and a border in the
+/// title bar's own color insets its content back by the same amount. Headers that
+/// render window controls in place of the title bar use this to apply the same
+/// insets as padding, so the controls stay on the same pixel.
+///
+/// `pad_bottom` should be false when the header already has a bottom border of
+/// its own occupying that space.
+pub fn apply_title_bar_insets<E: Styled + FluentBuilder>(
+ header: E,
+ left_window_controls: bool,
+ right_window_controls: bool,
+ pad_bottom: bool,
+) -> E {
+ let inset = theme::CLIENT_SIDE_DECORATION_BORDER;
+ header
+ .mt(-inset)
+ .pt(inset)
+ .when(pad_bottom, |header| header.pb(inset))
+ .when(left_window_controls, |header| header.pl(inset))
+ .when(right_window_controls, |header| header.pr(inset))
+}
+
pub struct PlatformTitleBar {
id: ElementId,
platform_style: PlatformStyle,
@@ -277,10 +300,10 @@ impl Render for PlatformTitleBar {
&& !(sidebar.open && sidebar.side == SidebarSide::Left),
|el| el.rounded_tl(theme::CLIENT_SIDE_DECORATION_ROUNDING),
)
- // this border is to avoid a transparent gap in the rounded corners
- .mt(px(-1.))
- .mb(px(-1.))
- .border(px(1.))
+ // Keep in sync with `apply_title_bar_insets`.
+ .mt(-theme::CLIENT_SIDE_DECORATION_BORDER)
+ .mb(-theme::CLIENT_SIDE_DECORATION_BORDER)
+ .border(theme::CLIENT_SIDE_DECORATION_BORDER)
.border_color(titlebar_color),
})
.bg(titlebar_color)
diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs
index a0b6f43fc26..37491eb69e3 100644
--- a/crates/sidebar/src/sidebar.rs
+++ b/crates/sidebar/src/sidebar.rs
@@ -39,6 +39,7 @@ use menu::{
Cancel, Confirm, SelectChild, SelectFirst, SelectLast, SelectNext, SelectParent, SelectPrevious,
};
use notifications::status_toast::StatusToast;
+use platform_title_bar::apply_title_bar_insets;
use project::{
AgentId, AgentRegistryStore, Event as ProjectEvent, WorktreeId, repo_identity_path_if_local,
};
@@ -7348,7 +7349,13 @@ impl Sidebar {
h_flex()
.h(header_height)
.map(|header| match window.window_decorations() {
- Decorations::Client { .. } => header.mt(px(-1.)),
+ // Without projects there's no bottom border to match the title bar's.
+ Decorations::Client { .. } => apply_title_bar_insets(
+ header,
+ left_window_controls,
+ right_window_controls,
+ no_open_projects,
+ ),
Decorations::Server => header.mt_px().pb_px(),
})
.when(left_window_controls, |this| {
diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs
index a23bedd504f..d2e13047267 100644
--- a/crates/theme/src/theme.rs
+++ b/crates/theme/src/theme.rs
@@ -53,6 +53,8 @@ pub const DEFAULT_DARK_THEME: &str = "One Dark";
pub const CLIENT_SIDE_DECORATION_ROUNDING: Pixels = px(10.0);
/// Defines window shadow size for platforms that use client side decorations.
pub const CLIENT_SIDE_DECORATION_SHADOW: Pixels = px(10.0);
+/// Defines window border width for platforms that use client side decorations.
+pub const CLIENT_SIDE_DECORATION_BORDER: Pixels = px(1.0);
/// Styling helpers for elements that follow client-side window decorations.
pub trait ClientDecorationsExt: Styled {
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index afe8c7d7adb..7d50ce7297f 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -11938,7 +11938,6 @@ pub fn client_side_decorations(
window: &mut Window,
cx: &mut App,
) -> Stateful<Div> {
- const BORDER_SIZE: Pixels = px(1.0);
let decorations = window.window_decorations();
let is_resizable = window.is_resizable();
let tiling = match decorations {
@@ -12018,10 +12017,18 @@ pub fn client_side_decorations(
Decorations::Client { .. } => div
.border_color(cx.theme().colors().border)
.rounded_client_corners(tiling)
- .when(!tiling.top, |div| div.border_t(BORDER_SIZE))
- .when(!tiling.bottom, |div| div.border_b(BORDER_SIZE))
- .when(!tiling.left, |div| div.border_l(BORDER_SIZE))
- .when(!tiling.right, |div| div.border_r(BORDER_SIZE))
+ .when(!tiling.top, |div| {
+ div.border_t(theme::CLIENT_SIDE_DECORATION_BORDER)
+ })
+ .when(!tiling.bottom, |div| {
+ div.border_b(theme::CLIENT_SIDE_DECORATION_BORDER)
+ })
+ .when(!tiling.left, |div| {
+ div.border_l(theme::CLIENT_SIDE_DECORATION_BORDER)
+ })
+ .when(!tiling.right, |div| {
+ div.border_r(theme::CLIENT_SIDE_DECORATION_BORDER)
+ })
.when(!tiling.is_tiled(), |div| {
div.shadow(vec![
gpui::BoxShadow::new(