From 4d849aaf0bded82b728b9470bb41203b49cc4db2 Mon Sep 17 00:00:00 2001 From: Maja Kądziołka Date: Sat, 3 Aug 2024 20:32:51 +0200 Subject: text_editor: Avoid rendering text outside the border If the height could fit slightly less than an extra line, said line would protrude beyond the border of the text editor. --- widget/src/text_editor.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'widget') diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index a264ba06..8b4b892d 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -729,7 +729,7 @@ where defaults: &renderer::Style, layout: Layout<'_>, cursor: mouse::Cursor, - viewport: &Rectangle, + _viewport: &Rectangle, ) { let bounds = layout.bounds(); @@ -793,7 +793,7 @@ where }, position, style.placeholder, - *viewport, + bounds, ); } } else { @@ -801,7 +801,7 @@ where &internal.editor, position, defaults.text_color, - *viewport, + bounds, ); } -- cgit From 03472dfd4f8a472f38f03d332b4835580eb84489 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Aug 2024 02:53:23 +0200 Subject: Make `Padding` affect `text_editor` clipping --- widget/src/text_editor.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'widget') diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 8b4b892d..9e8479fc 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -768,20 +768,14 @@ where style.background, ); - let position = bounds.position() - + Vector::new(self.padding.left, self.padding.top); + let text_bounds = bounds.shrink(self.padding); if internal.editor.is_empty() { if let Some(placeholder) = self.placeholder.clone() { renderer.fill_text( Text { content: placeholder.into_owned(), - bounds: bounds.size() - - Size::new( - self.padding.right, - self.padding.bottom, - ), - + bounds: text_bounds.size(), size: self .text_size .unwrap_or_else(|| renderer.default_size()), @@ -791,7 +785,7 @@ where vertical_alignment: alignment::Vertical::Top, shaping: text::Shaping::Advanced, }, - position, + text_bounds.position(), style.placeholder, bounds, ); @@ -799,16 +793,13 @@ where } else { renderer.fill_editor( &internal.editor, - position, + text_bounds.position(), defaults.text_color, - bounds, + text_bounds, ); } - let translation = Vector::new( - bounds.x + self.padding.left, - bounds.y + self.padding.top, - ); + let translation = text_bounds.position() - Point::ORIGIN; if let Some(focus) = state.focus.as_ref() { match internal.editor.cursor() { @@ -826,7 +817,9 @@ where ), ); - if let Some(clipped_cursor) = bounds.intersection(&cursor) { + if let Some(clipped_cursor) = + text_bounds.intersection(&cursor) + { renderer.fill_quad( renderer::Quad { bounds: Rectangle { @@ -843,7 +836,7 @@ where } Cursor::Selection(ranges) => { for range in ranges.into_iter().filter_map(|range| { - bounds.intersection(&(range + translation)) + text_bounds.intersection(&(range + translation)) }) { renderer.fill_quad( renderer::Quad { -- cgit From be7d175388076cf24ca902a2d4cd457ce2a8e9ab Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Aug 2024 02:54:22 +0200 Subject: Remove cursor snapping hack in `text_editor` The `quad` shader now properly takes care of snapping lines to the pixel grid. --- widget/src/text_editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget') diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 9e8479fc..32537aff 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -823,7 +823,7 @@ where renderer.fill_quad( renderer::Quad { bounds: Rectangle { - x: clipped_cursor.x.floor(), + x: clipped_cursor.x, y: clipped_cursor.y, width: clipped_cursor.width, height: clipped_cursor.height, -- cgit From 3e59d824f8be029720f4064b49099e6aabc11179 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Aug 2024 02:57:45 +0200 Subject: Fix clipping area of `text_editor` placeholder --- widget/src/text_editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget') diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 32537aff..e41c50d7 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -787,7 +787,7 @@ where }, text_bounds.position(), style.placeholder, - bounds, + text_bounds, ); } } else { -- cgit