From 6cec3891250a86e92dab64a9a531bc95f5db597f Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Mar 2024 10:55:09 -0400 Subject: [PATCH] ui: Make `top_padding` an associated function on the `TitleBar` (#9577) This PR makes the function for computing the top padding for the `TitleBar` an associated function. Release Notes: - N/A --- .../ui/src/components/title_bar/title_bar.rs | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/crates/ui/src/components/title_bar/title_bar.rs b/crates/ui/src/components/title_bar/title_bar.rs index 8bbe9d80ec..e16b231268 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
, 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) -> 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()