Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text_input::Renderer implementation in iced_wgpu #279

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions wgpu/src/renderer/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl text_input::Renderer for Renderer {
Size::INFINITY,
);

let spaces_at_the_end = value.len() - value.trim_end().len();
let spaces_around = value.len() - value.trim().len();

if spaces_at_the_end > 0 {
if spaces_around > 0 {
let space_width = self.text_pipeline.space_width(size as f32);
width += spaces_at_the_end as f32 * space_width;
width += spaces_around as f32 * space_width;
}

width
Expand Down Expand Up @@ -210,10 +210,20 @@ impl text_input::Renderer for Renderer {
(text_value, Vector::new(0, 0))
};

let contents = Primitive::Clip {
bounds: text_bounds,
offset,
content: Box::new(contents_primitive),
let text_width = self.measure_value(
if text.is_empty() { placeholder } else { &text },
size,
font,
);

let contents = if text_width > text_bounds.width {
Primitive::Clip {
bounds: text_bounds,
offset,
content: Box::new(contents_primitive),
}
} else {
contents_primitive
};

(
Expand Down