windows: Fix title bar height when maximized (#9449)
screenshots and description incoming ## title bar when window is maximized | before | after | | --- | --- | |  |  | ## ~~caption buttons at 200%~~ ~~buttons are now properly responsive at different scales~~ ~~closes #9438~~ ~~proper scale factor handling in follow up PR (possibly #9440)~~ <details> <summary>out of date image</summary>  </details> should be fixed by https://github.com/zed-industries/zed/pull/9456 Release Notes: - N/A
This commit is contained in:
parent
3dadfe4787
commit
d5e0817fbc
5 changed files with 67 additions and 42 deletions
|
@ -10,12 +10,40 @@ 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"))]
|
||||
pub fn height(cx: &mut WindowContext) -> Pixels {
|
||||
(1.75 * cx.rem_size()).max(px(32.))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn height(_cx: &mut WindowContext) -> Pixels {
|
||||
// todo(windows) instead of hard coded size report the actual size to the Windows platform API
|
||||
px(32.)
|
||||
}
|
||||
|
||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
Self {
|
||||
platform_style: PlatformStyle::platform(),
|
||||
|
@ -29,16 +57,6 @@ impl TitleBar {
|
|||
self.platform_style = style;
|
||||
self
|
||||
}
|
||||
|
||||
fn top_padding(&self, cx: &WindowContext) -> Pixels {
|
||||
if self.platform_style == PlatformStyle::Windows && cx.is_maximized() {
|
||||
// todo(windows): get padding from win32 api, need HWND from window context somehow
|
||||
// should be GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) * 2
|
||||
px(8.)
|
||||
} else {
|
||||
px(0.)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InteractiveElement for TitleBar {
|
||||
|
@ -58,13 +76,11 @@ impl ParentElement for TitleBar {
|
|||
impl RenderOnce for TitleBar {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let height = Self::height(cx);
|
||||
let top_padding = self.top_padding(cx);
|
||||
|
||||
h_flex()
|
||||
.id("titlebar")
|
||||
.w_full()
|
||||
.pt(top_padding)
|
||||
.h(height)
|
||||
.pt(title_bar_top_padding(cx))
|
||||
.h(height + title_bar_top_padding(cx))
|
||||
.map(|this| {
|
||||
if cx.is_fullscreen() {
|
||||
this.pl_2()
|
||||
|
@ -88,9 +104,7 @@ impl RenderOnce for TitleBar {
|
|||
.children(self.children),
|
||||
)
|
||||
.when(self.platform_style == PlatformStyle::Windows, |title_bar| {
|
||||
let button_height = Self::height(cx) - top_padding;
|
||||
|
||||
title_bar.child(WindowsWindowControls::new(button_height))
|
||||
title_bar.child(WindowsWindowControls::new(height))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,9 +98,11 @@ impl WindowsCaptionButton {
|
|||
|
||||
impl RenderOnce for WindowsCaptionButton {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
// todo(windows): get padding from win32 api, need HWND from window context somehow
|
||||
// should be GetSystemMetricsForDpi(SM_CXSIZE, dpi)
|
||||
let width = px(36.0);
|
||||
// todo(windows) report this width to the Windows platform API
|
||||
// NOTE: this is intentionally hard coded. An option to use the 'native' size
|
||||
// could be added when the width is reported to the Windows platform API
|
||||
// as this could change between future Windows versions.
|
||||
let width = px(36.);
|
||||
|
||||
h_flex()
|
||||
.id(self.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue