Merge pull request #2199 from iced-rs/fix/clip-text-input-selection

Fix clipping of `TextInput` selection
This commit is contained in:
Héctor Ramón 2024-01-12 13:42:46 +01:00 committed by GitHub
commit 63e9adac56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1194,31 +1194,39 @@ pub fn draw<Renderer>(
(None, 0.0)
};
if let Some((cursor, color)) = cursor {
renderer.with_translation(Vector::new(-offset, 0.0), |renderer| {
renderer.fill_quad(cursor, color);
});
} else {
renderer.with_translation(Vector::ZERO, |_| {});
}
let draw = |renderer: &mut Renderer, viewport| {
if let Some((cursor, color)) = cursor {
renderer.with_translation(Vector::new(-offset, 0.0), |renderer| {
renderer.fill_quad(cursor, color);
});
} else {
renderer.with_translation(Vector::ZERO, |_| {});
}
renderer.fill_paragraph(
if text.is_empty() {
&state.placeholder
} else {
&state.value
},
Point::new(text_bounds.x, text_bounds.center_y())
- Vector::new(offset, 0.0),
if text.is_empty() {
theme.placeholder_color(style)
} else if is_disabled {
theme.disabled_color(style)
} else {
theme.value_color(style)
},
text_bounds,
);
renderer.fill_paragraph(
if text.is_empty() {
&state.placeholder
} else {
&state.value
},
Point::new(text_bounds.x, text_bounds.center_y())
- Vector::new(offset, 0.0),
if text.is_empty() {
theme.placeholder_color(style)
} else if is_disabled {
theme.disabled_color(style)
} else {
theme.value_color(style)
},
viewport,
);
};
if cursor.is_some() {
renderer.with_layer(text_bounds, |renderer| draw(renderer, *viewport));
} else {
draw(renderer, text_bounds);
}
}
/// Computes the current [`mouse::Interaction`] of the [`TextInput`].