From b997eabcba6e7ed2a6bdafeb59c72cbfdbaedd2a Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Fri, 1 Nov 2024 14:20:49 +0800 Subject: [PATCH] title_bar: Make the left padding adjustable (#386) --- crates/ui/src/title_bar.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/ui/src/title_bar.rs b/crates/ui/src/title_bar.rs index 854ac824..c371fa6b 100644 --- a/crates/ui/src/title_bar.rs +++ b/crates/ui/src/title_bar.rs @@ -18,8 +18,14 @@ pub const TITLE_BAR_HEIGHT: Pixels = px(35.); impl TitleBar { pub fn new() -> Self { + // Leave more space for the macOS window controls. + #[cfg(target_os = "macos")] + let pl = px(80.); + #[cfg(not(target_os = "macos"))] + let pl = px(12.); + Self { - base: div().id("title-bar"), + base: div().id("title-bar").pl(pl), children: Vec::new(), } } @@ -184,11 +190,6 @@ impl ParentElement for TitleBar { impl RenderOnce for TitleBar { fn render(self, cx: &mut WindowContext) -> impl IntoElement { let is_linux = cfg!(target_os = "linux"); - let macos_pl = if cfg!(target_os = "macos") { - Some(px(80.)) - } else { - None - }; const HEIGHT: Pixels = px(34.); @@ -201,14 +202,10 @@ impl RenderOnce for TitleBar { .items_center() .justify_between() .h(HEIGHT) - .pl(px(12.)) - .when(!cx.is_fullscreen(), |this| { - // Leave space for the macOS window controls. - this.when_some(macos_pl, |this, pl| this.pl(pl)) - }) .border_b_1() .border_color(cx.theme().title_bar_border) .bg(cx.theme().title_bar) + .when(cx.is_fullscreen(), |this| this.pl(px(12.))) .on_double_click(|_, cx| cx.zoom_window()) .child( h_flex()