Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
ui: Make `top_padding` an associated function on the `TitleBar` (#9577)
Marshall Bowers6cec3891250a
diff --git a/crates/ui/src/components/title_bar/title_bar.rs b/crates/ui/src/components/title_bar/title_bar.rsindex 8bbe9d80ec1..e16b2312685 100644--- a/crates/ui/src/components/title_bar/title_bar.rs+++ b/crates/ui/src/components/title_bar/title_bar.rs@@ -10,27 +10,6 @@ pub struct TitleBar {content: Stateful<Div>,children: SmallVec<[AnyElement; 2]>,}-#[cfg(not(target_os = "windows"))]-fn title_bar_top_padding(_cx: &WindowContext) -> Pixels {- px(0.)-}--#[cfg(target_os = "windows")]-fn title_bar_top_padding(cx: &WindowContext) -> Pixels {- use windows::Win32::UI::{- HiDpi::GetSystemMetricsForDpi,- WindowsAndMessaging::{SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI},- };-- // this top padding is not dependent on the title bar style and is instead a quirk of maximized windows on Windows- // https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543- let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) };- if cx.is_maximized() {- px((padding * 2) as f32)- } else {- px(0.)- }-}impl TitleBar {#[cfg(not(target_os = "windows"))]@@ -44,6 +23,28 @@ impl TitleBar {px(32.)}+ #[cfg(not(target_os = "windows"))]+ fn top_padding(_cx: &WindowContext) -> Pixels {+ px(0.)+ }++ #[cfg(target_os = "windows")]+ fn top_padding(cx: &WindowContext) -> Pixels {+ use windows::Win32::UI::{+ HiDpi::GetSystemMetricsForDpi,+ WindowsAndMessaging::{SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI},+ };++ // This top padding is not dependent on the title bar style and is instead a quirk of maximized windows on Windows:+ // https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543+ let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) };+ if cx.is_maximized() {+ px((padding * 2) as f32)+ } else {+ px(0.)+ }+ }+pub fn new(id: impl Into<ElementId>) -> Self {Self {platform_style: PlatformStyle::platform(),@@ -79,8 +80,8 @@ impl RenderOnce for TitleBar {h_flex().id("titlebar").w_full()- .pt(title_bar_top_padding(cx))- .h(height + title_bar_top_padding(cx))+ .pt(Self::top_padding(cx))+ .h(height + Self::top_padding(cx)).map(|this| {if cx.is_fullscreen() {this.pl_2()