improv(header_bar): reduce chance of end elements being pushed out
This commit is contained in:
parent
2a1af3a24f
commit
147fc5a2a4
1 changed files with 13 additions and 16 deletions
|
|
@ -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()
|
let portion = ((start.len().max(end.len()) as f32 / center.len().max(1) as f32).round()
|
||||||
as u16)
|
as u16)
|
||||||
.max(1);
|
.max(1);
|
||||||
let center_empty = center.is_empty() && self.title.is_empty();
|
|
||||||
// Creates the headerbar widget.
|
// Creates the headerbar widget.
|
||||||
let mut widget = widget::row::with_capacity(3)
|
let mut widget = widget::row::with_capacity(3)
|
||||||
// If elements exist in the start region, append them here.
|
// 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.
|
// If elements exist in the center region, use them here.
|
||||||
// This will otherwise use the title as a widget if a title was defined.
|
// This will otherwise use the title as a widget if a title was defined.
|
||||||
.push(if !center.is_empty() {
|
.push_maybe(if !center.is_empty() {
|
||||||
widget::row::with_children(center)
|
Some(
|
||||||
.spacing(space_xxxs)
|
widget::row::with_children(center)
|
||||||
.align_y(iced::Alignment::Center)
|
.spacing(space_xxxs)
|
||||||
.apply(widget::container)
|
.align_y(iced::Alignment::Center)
|
||||||
.center_x(Length::Fill)
|
.apply(widget::container)
|
||||||
.into()
|
.center_x(Length::Fill)
|
||||||
} else if self.title.is_empty() {
|
.into(),
|
||||||
widget::horizontal_space().into()
|
)
|
||||||
|
} else if !self.title.is_empty() {
|
||||||
|
Some(self.title_widget())
|
||||||
} else {
|
} else {
|
||||||
self.title_widget()
|
None
|
||||||
})
|
})
|
||||||
.push(
|
.push(
|
||||||
widget::row::with_children(end)
|
widget::row::with_children(end)
|
||||||
|
|
@ -358,11 +359,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
||||||
.align_y(iced::Alignment::Center)
|
.align_y(iced::Alignment::Center)
|
||||||
.apply(widget::container)
|
.apply(widget::container)
|
||||||
.align_x(iced::Alignment::End)
|
.align_x(iced::Alignment::End)
|
||||||
.width(if center_empty {
|
.width(Length::FillPortion(portion)),
|
||||||
Length::Fill
|
|
||||||
} else {
|
|
||||||
Length::FillPortion(portion)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.align_y(iced::Alignment::Center)
|
.align_y(iced::Alignment::Center)
|
||||||
.height(Length::Fixed(32.0 + padding[0] as f32 + padding[2] as f32))
|
.height(Length::Fixed(32.0 + padding[0] as f32 + padding[2] as f32))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue