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
This commit is contained in:
Marshall Bowers 2024-03-20 10:55:09 -04:00 committed by GitHub
parent 9ab7a22fa8
commit 6cec389125
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,27 +10,6 @@ pub struct TitleBar {
content: Stateful<Div>, content: Stateful<Div>,
children: SmallVec<[AnyElement; 2]>, 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 { impl TitleBar {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
@ -44,6 +23,28 @@ impl TitleBar {
px(32.) 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 { pub fn new(id: impl Into<ElementId>) -> Self {
Self { Self {
platform_style: PlatformStyle::platform(), platform_style: PlatformStyle::platform(),
@ -79,8 +80,8 @@ impl RenderOnce for TitleBar {
h_flex() h_flex()
.id("titlebar") .id("titlebar")
.w_full() .w_full()
.pt(title_bar_top_padding(cx)) .pt(Self::top_padding(cx))
.h(height + title_bar_top_padding(cx)) .h(height + Self::top_padding(cx))
.map(|this| { .map(|this| {
if cx.is_fullscreen() { if cx.is_fullscreen() {
this.pl_2() this.pl_2()