From f82c347e3716787b45f7a07e59482c2b3aac3d2f Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 11 Jun 2025 16:52:51 +0800 Subject: [PATCH] title_bar: Fix `pl` to override default TitleBar left padding. (#944) --- crates/ui/src/title_bar.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ui/src/title_bar.rs b/crates/ui/src/title_bar.rs index 4944adf1..e1187a9c 100644 --- a/crates/ui/src/title_bar.rs +++ b/crates/ui/src/title_bar.rs @@ -27,7 +27,7 @@ pub struct TitleBar { impl TitleBar { pub fn new() -> Self { Self { - base: div().id("title-bar"), + base: div().id("title-bar").pl(TITLE_BAR_LEFT_PADDING), children: Vec::new(), on_close_window: None, } @@ -243,10 +243,12 @@ impl ParentElement for TitleBar { } impl RenderOnce for TitleBar { - fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { + fn render(mut self, window: &mut Window, cx: &mut App) -> impl IntoElement { let is_linux = cfg!(target_os = "linux"); - const HEIGHT: Pixels = px(34.); + let paddings = self.base.style().padding.clone(); + self.base.style().padding.left = None; + let left_padding = paddings.left.unwrap_or(TITLE_BAR_LEFT_PADDING.into()); div().flex_shrink_0().child( self.base @@ -254,7 +256,7 @@ impl RenderOnce for TitleBar { .flex_row() .items_center() .justify_between() - .h(HEIGHT) + .h(TITLE_BAR_HEIGHT) .border_b_1() .border_color(cx.theme().title_bar_border) .bg(cx.theme().title_bar) @@ -264,8 +266,8 @@ impl RenderOnce for TitleBar { .child( h_flex() .id("bar") - .pl(TITLE_BAR_LEFT_PADDING) - .when(window.is_fullscreen(), |this| this.pl(px(12.))) + .pl(left_padding) + .when(window.is_fullscreen(), |this| this.pl_3()) .window_control_area(WindowControlArea::Drag) .h_full() .justify_between()