fix(segmented-button): misaligned icon when text is empty
This commit is contained in:
parent
33db28327a
commit
78e331d5ed
1 changed files with 22 additions and 18 deletions
|
|
@ -372,6 +372,7 @@ where
|
||||||
button: Entity,
|
button: Entity,
|
||||||
) -> (f32, f32) {
|
) -> (f32, f32) {
|
||||||
let mut width = 0.0f32;
|
let mut width = 0.0f32;
|
||||||
|
let mut icon_spacing = 0.0f32;
|
||||||
|
|
||||||
// Add text to measurement if text was given.
|
// Add text to measurement if text was given.
|
||||||
if let Some((text, entry)) = self
|
if let Some((text, entry)) = self
|
||||||
|
|
@ -380,21 +381,24 @@ where
|
||||||
.get(button)
|
.get(button)
|
||||||
.zip(state.paragraphs.entry(button))
|
.zip(state.paragraphs.entry(button))
|
||||||
{
|
{
|
||||||
let paragraph = entry.or_insert_with(|| {
|
if !text.is_empty() {
|
||||||
crate::Paragraph::with_text(Text {
|
icon_spacing = f32::from(self.button_spacing);
|
||||||
content: text,
|
let paragraph = entry.or_insert_with(|| {
|
||||||
size: iced::Pixels(self.font_size),
|
crate::Paragraph::with_text(Text {
|
||||||
bounds: Size::INFINITY,
|
content: text,
|
||||||
font,
|
size: iced::Pixels(self.font_size),
|
||||||
horizontal_alignment: alignment::Horizontal::Left,
|
bounds: Size::INFINITY,
|
||||||
vertical_alignment: alignment::Vertical::Center,
|
font,
|
||||||
shaping: Shaping::Advanced,
|
horizontal_alignment: alignment::Horizontal::Left,
|
||||||
line_height: self.line_height,
|
vertical_alignment: alignment::Vertical::Center,
|
||||||
})
|
shaping: Shaping::Advanced,
|
||||||
});
|
line_height: self.line_height,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
let size = paragraph.min_bounds();
|
let size = paragraph.min_bounds();
|
||||||
width += size.width;
|
width += size.width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add indent to measurement if found.
|
// Add indent to measurement if found.
|
||||||
|
|
@ -404,11 +408,11 @@ where
|
||||||
|
|
||||||
// Add icon to measurement if icon was given.
|
// Add icon to measurement if icon was given.
|
||||||
if let Some(icon) = self.model.icon(button) {
|
if let Some(icon) = self.model.icon(button) {
|
||||||
width += f32::from(icon.size) + f32::from(self.button_spacing);
|
width += f32::from(icon.size) + icon_spacing;
|
||||||
} else if self.model.is_active(button) {
|
} else if self.model.is_active(button) {
|
||||||
// Add selection icon measurements when widget is a selection widget.
|
// Add selection icon measurements when widget is a selection widget.
|
||||||
if let crate::theme::SegmentedButton::Control = self.style {
|
if let crate::theme::SegmentedButton::Control = self.style {
|
||||||
width += 16.0 + f32::from(self.button_spacing);
|
width += 16.0 + icon_spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1313,9 +1317,9 @@ where
|
||||||
- close_icon_width
|
- close_icon_width
|
||||||
- f32::from(self.button_padding[2]);
|
- f32::from(self.button_padding[2]);
|
||||||
|
|
||||||
if self.model.text(key).is_some() {
|
bounds.y = center_y;
|
||||||
bounds.y = center_y;
|
|
||||||
|
|
||||||
|
if self.model.text(key).is_some_and(|text| !text.is_empty()) {
|
||||||
// Draw the text for this segmented button or tab.
|
// Draw the text for this segmented button or tab.
|
||||||
renderer.fill_paragraph(
|
renderer.fill_paragraph(
|
||||||
&state.paragraphs[key],
|
&state.paragraphs[key],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue