From 9afa31899f9daa4523cb23db75e736d7d652da13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 9 Apr 2020 05:01:09 +0200 Subject: [PATCH 1/2] Fix `measure_value` for text input in `iced_wgpu` It accounts for spaces at the start of text now. --- wgpu/src/renderer/widget/text_input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index 9093b0c6..ab0ba363 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 From d3dee849b70e52dceddf83c46a8c83837b80094d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 9 Apr 2020 05:03:43 +0200 Subject: [PATCH 2/2] Fix unnecessary clip of text input in `iced_wgpu` It should only produce a `Clip` primitive when the contents overflow the input now. --- wgpu/src/renderer/widget/text_input.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index ab0ba363..1f804a1a 100644 --- a/wgpu/src/renderer/widget/text_input.rs +++ b/wgpu/src/renderer/widget/text_input.rs @@ -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 }; (