mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
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:
parent
9ab7a22fa8
commit
6cec389125
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user