summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-04-10 01:18:29 +0200
committerLibravatar GitHub <noreply@github.com>2020-04-10 01:18:29 +0200
commit19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f (patch)
treed83058bb4ff71148919121046cf02e151b2761bd /wgpu
parent867dad62fa599755e95d4cf0d5d9404b9ff6e398 (diff)
parentd3dee849b70e52dceddf83c46a8c83837b80094d (diff)
downloadiced-19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f.tar.gz
iced-19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f.tar.bz2
iced-19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f.zip
Merge pull request #279 from hecrj/fix/text-input-measure-value
Fix `text_input::Renderer` implementation in `iced_wgpu`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer/widget/text_input.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs
index 9093b0c6..1f804a1a 100644
--- a/wgpu/src/renderer/widget/text_input.rs
+++ b/wgpu/src/renderer/widget/text_input.rs
@@ -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
@@ -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
};
(