fix(segmented_button): clip text that overlaps with close button
This commit is contained in:
parent
0bef593ba4
commit
05f8ffeef1
1 changed files with 26 additions and 13 deletions
|
|
@ -694,10 +694,22 @@ where
|
||||||
alignment::Horizontal::Center
|
alignment::Horizontal::Center
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Whether to show the close button on this tab.
|
||||||
|
let show_close_button =
|
||||||
|
(key_is_active || !self.show_close_icon_on_hover || key_is_hovered)
|
||||||
|
&& self.model.is_closable(key);
|
||||||
|
|
||||||
|
// Width of the icon used by the close button, which we will subtract from the text bounds.
|
||||||
|
let close_icon_width = if show_close_button {
|
||||||
|
f32::from(self.close_icon.size)
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(text) = self.model.text(key) {
|
if let Some(text) = self.model.text(key) {
|
||||||
bounds.y = y;
|
bounds.y = y;
|
||||||
|
|
||||||
// Draw the text in this button.
|
// Draw the text for this segmented button or tab.
|
||||||
renderer.fill_text(
|
renderer.fill_text(
|
||||||
iced_core::text::Text {
|
iced_core::text::Text {
|
||||||
content: text,
|
content: text,
|
||||||
|
|
@ -711,25 +723,26 @@ where
|
||||||
},
|
},
|
||||||
bounds.position(),
|
bounds.position(),
|
||||||
status_appearance.text_color,
|
status_appearance.text_color,
|
||||||
*viewport,
|
Rectangle {
|
||||||
|
width: bounds.width - close_icon_width - 16.0,
|
||||||
|
..original_bounds
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let show_close_button =
|
// Draw a close button if set.
|
||||||
(key_is_active || !self.show_close_icon_on_hover || key_is_hovered)
|
|
||||||
&& self.model.is_closable(key);
|
|
||||||
|
|
||||||
// Draw a close button if this is set.
|
|
||||||
if show_close_button {
|
if show_close_button {
|
||||||
let width = f32::from(self.close_icon.size);
|
let close_button_bounds =
|
||||||
let icon_bounds = close_bounds(original_bounds, width, self.button_padding);
|
close_bounds(original_bounds, close_icon_width, self.button_padding);
|
||||||
|
|
||||||
let mut layout_node = layout::Node::new(Size {
|
let mut layout_node = layout::Node::new(Size {
|
||||||
width: icon_bounds.width,
|
width: close_button_bounds.width,
|
||||||
height: icon_bounds.height,
|
height: close_button_bounds.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
layout_node.move_to(Point {
|
layout_node.move_to(Point {
|
||||||
x: icon_bounds.x,
|
x: close_button_bounds.x,
|
||||||
y: icon_bounds.y,
|
y: close_button_bounds.y,
|
||||||
});
|
});
|
||||||
|
|
||||||
Widget::<Message, Renderer>::draw(
|
Widget::<Message, Renderer>::draw(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue