Skip to content

Commit

Permalink
Merge pull request #2199 from iced-rs/fix/clip-text-input-selection
Browse files Browse the repository at this point in the history
Fix clipping of `TextInput` selection
  • Loading branch information
hecrj authored Jan 12, 2024
2 parents a5ae442 + 5315e04 commit 63e9ada
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions widget/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down

0 comments on commit 63e9ada

Please sign in to comment.