From 5c13c843f9ab9fe7fefc891848cf387fb847fd00 Mon Sep 17 00:00:00 2001 From: Juan Campa Date: Wed, 17 Apr 2024 18:57:00 -0400 Subject: [PATCH 1/3] Fix incorrect line breaks --- crates/epaint/src/text/text_layout.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 322026da3c5..57241bfbcbf 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -296,7 +296,7 @@ fn line_break(paragraph: &Paragraph, job: &LayoutJob, out_rows: &mut Vec, e // Start a new row: row_start_idx = last_kept_index + 1; row_start_x = paragraph.glyphs[row_start_idx].pos.x; - row_break_candidates = Default::default(); + row_break_candidates.forget_candiates_before_idx(row_start_idx); } else { // Found no place to break, so we have to overrun wrap_width. } @@ -943,6 +943,27 @@ impl RowBreakCandidates { .or(self.any) } } + + fn forget_candiates_before_idx(&mut self, index: usize) { + if self.space.map(|s| s < index).unwrap_or_default() { + self.space = None; + } + if self.cjk.map(|s| s < index).unwrap_or_default() { + self.cjk = None; + } + if self.pre_cjk.map(|s| s < index).unwrap_or_default() { + self.pre_cjk = None; + } + if self.dash.map(|s| s < index).unwrap_or_default() { + self.dash = None; + } + if self.punctuation.map(|s| s < index).unwrap_or_default() { + self.punctuation = None; + } + if self.any.map(|s| s < index).unwrap_or_default() { + self.any = None; + } + } } #[inline] From 99bb0124f5ebbe07c275551402b3c6478162a2ec Mon Sep 17 00:00:00 2001 From: Juan Campa Date: Wed, 17 Apr 2024 19:07:09 -0400 Subject: [PATCH 2/3] Rename --- crates/epaint/src/text/text_layout.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 57241bfbcbf..217e3a62ce2 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -296,7 +296,7 @@ fn line_break(paragraph: &Paragraph, job: &LayoutJob, out_rows: &mut Vec, e // Start a new row: row_start_idx = last_kept_index + 1; row_start_x = paragraph.glyphs[row_start_idx].pos.x; - row_break_candidates.forget_candiates_before_idx(row_start_idx); + row_break_candidates.forget_before_idx(row_start_idx); } else { // Found no place to break, so we have to overrun wrap_width. } @@ -944,7 +944,7 @@ impl RowBreakCandidates { } } - fn forget_candiates_before_idx(&mut self, index: usize) { + fn forget_before_idx(&mut self, index: usize) { if self.space.map(|s| s < index).unwrap_or_default() { self.space = None; } From 837d908cfa9bd9864482a59a384cdba5454dc3cf Mon Sep 17 00:00:00 2001 From: Juan Campa Date: Fri, 19 Apr 2024 13:05:18 -0400 Subject: [PATCH 3/3] Use destructure Co-authored-by: Emil Ernerfeldt --- crates/epaint/src/text/text_layout.rs | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 217e3a62ce2..c9956aac197 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -945,23 +945,31 @@ impl RowBreakCandidates { } fn forget_before_idx(&mut self, index: usize) { - if self.space.map(|s| s < index).unwrap_or_default() { - self.space = None; + let Self { + space, + cjk, + pre_cjk, + dash, + punctuation, + any, + } = self; + if space.map_or(false, |s| s < index) { + *space = None; } - if self.cjk.map(|s| s < index).unwrap_or_default() { - self.cjk = None; + if cjk.map_or(false, |s| s < index) { + *cjk = None; } - if self.pre_cjk.map(|s| s < index).unwrap_or_default() { - self.pre_cjk = None; + if pre_cjk.map_or(false, |s| s < index) { + *pre_cjk = None; } - if self.dash.map(|s| s < index).unwrap_or_default() { - self.dash = None; + if dash.map_or(false, |s| s < index) { + *dash = None; } - if self.punctuation.map(|s| s < index).unwrap_or_default() { - self.punctuation = None; + if punctuation.map_or(false, |s| s < index) { + *punctuation = None; } - if self.any.map(|s| s < index).unwrap_or_default() { - self.any = None; + if any.map_or(false, |s| s < index) { + *any = None; } } }