From 147fc5a2a46e3b6d742617510a6245a222074bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= Date: Sun, 18 May 2025 18:32:25 +0200 Subject: [PATCH] improv(header_bar): reduce chance of end elements being pushed out --- src/widget/header_bar.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index 369685f5..1d19f095 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -326,7 +326,6 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { let portion = ((start.len().max(end.len()) as f32 / center.len().max(1) as f32).round() as u16) .max(1); - let center_empty = center.is_empty() && self.title.is_empty(); // Creates the headerbar widget. let mut widget = widget::row::with_capacity(3) // If elements exist in the start region, append them here. @@ -340,17 +339,19 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { ) // If elements exist in the center region, use them here. // This will otherwise use the title as a widget if a title was defined. - .push(if !center.is_empty() { - widget::row::with_children(center) - .spacing(space_xxxs) - .align_y(iced::Alignment::Center) - .apply(widget::container) - .center_x(Length::Fill) - .into() - } else if self.title.is_empty() { - widget::horizontal_space().into() + .push_maybe(if !center.is_empty() { + Some( + widget::row::with_children(center) + .spacing(space_xxxs) + .align_y(iced::Alignment::Center) + .apply(widget::container) + .center_x(Length::Fill) + .into(), + ) + } else if !self.title.is_empty() { + Some(self.title_widget()) } else { - self.title_widget() + None }) .push( widget::row::with_children(end) @@ -358,11 +359,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { .align_y(iced::Alignment::Center) .apply(widget::container) .align_x(iced::Alignment::End) - .width(if center_empty { - Length::Fill - } else { - Length::FillPortion(portion) - }), + .width(Length::FillPortion(portion)), ) .align_y(iced::Alignment::Center) .height(Length::Fixed(32.0 + padding[0] as f32 + padding[2] as f32))