Clip bounds to prevent text overflow

This commit is contained in:
Cory Forsstrom 2022-04-25 09:01:04 -07:00
parent 83171f05d0
commit 6e70d9ad83

View file

@ -402,22 +402,24 @@ pub fn draw<T, Renderer>(
if let Some(label) = if let Some(label) =
label.as_ref().map(String::as_str).or_else(|| placeholder) label.as_ref().map(String::as_str).or_else(|| placeholder)
{ {
renderer.fill_text(Text { renderer.with_layer(bounds, |layer| {
content: label, layer.fill_text(Text {
size: f32::from(text_size.unwrap_or(renderer.default_size())), content: label,
font: font.clone(), size: f32::from(text_size.unwrap_or(layer.default_size())),
color: is_selected font: font.clone(),
.then(|| style.text_color) color: is_selected
.unwrap_or(style.placeholder_color), .then(|| style.text_color)
bounds: Rectangle { .unwrap_or(style.placeholder_color),
x: bounds.x + f32::from(padding.left), bounds: Rectangle {
y: bounds.center_y(), x: bounds.x + f32::from(padding.left),
width: f32::INFINITY, y: bounds.center_y(),
..bounds width: f32::INFINITY,
}, ..bounds
horizontal_alignment: alignment::Horizontal::Left, },
vertical_alignment: alignment::Vertical::Center, horizontal_alignment: alignment::Horizontal::Left,
}) vertical_alignment: alignment::Vertical::Center,
})
});
} }
} }