Merge pull request #279 from hecrj/fix/text-input-measure-value
Fix `text_input::Renderer` implementation in `iced_wgpu`
This commit is contained in:
commit
19f6a5e2fd
@ -23,11 +23,11 @@ impl text_input::Renderer for Renderer {
|
|||||||
Size::INFINITY,
|
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);
|
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
|
width
|
||||||
@ -210,10 +210,20 @@ impl text_input::Renderer for Renderer {
|
|||||||
(text_value, Vector::new(0, 0))
|
(text_value, Vector::new(0, 0))
|
||||||
};
|
};
|
||||||
|
|
||||||
let contents = Primitive::Clip {
|
let text_width = self.measure_value(
|
||||||
bounds: text_bounds,
|
if text.is_empty() { placeholder } else { &text },
|
||||||
offset,
|
size,
|
||||||
content: Box::new(contents_primitive),
|
font,
|
||||||
|
);
|
||||||
|
|
||||||
|
let contents = if text_width > text_bounds.width {
|
||||||
|
Primitive::Clip {
|
||||||
|
bounds: text_bounds,
|
||||||
|
offset,
|
||||||
|
content: Box::new(contents_primitive),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contents_primitive
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user