diff options
author | 2024-01-12 13:34:14 +0100 | |
---|---|---|
committer | 2024-01-12 13:34:14 +0100 | |
commit | 5315e04a265190e943f42710f0b949e8af7dd37d (patch) | |
tree | 6b7a6529f6cb646f409bfdb953f0f7ac6333f427 /widget/src/text_input.rs | |
parent | a5ae442819227b3cd55116028e6d6c96caa6fda9 (diff) | |
download | iced-5315e04a265190e943f42710f0b949e8af7dd37d.tar.gz iced-5315e04a265190e943f42710f0b949e8af7dd37d.tar.bz2 iced-5315e04a265190e943f42710f0b949e8af7dd37d.zip |
Fix clipping of `TextInput` selection
Diffstat (limited to 'widget/src/text_input.rs')
-rw-r--r-- | widget/src/text_input.rs | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 65d3e1eb..c4c74a67 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -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); - }); + 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) + }, + viewport, + ); + }; + + if cursor.is_some() { + renderer.with_layer(text_bounds, |renderer| draw(renderer, *viewport)); } else { - renderer.with_translation(Vector::ZERO, |_| {}); + draw(renderer, 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) - }, - text_bounds, - ); } /// Computes the current [`mouse::Interaction`] of the [`TextInput`]. |