Skip to content

Commit

Permalink
Fix Row::ends_with_newline docs, explain skipping of last galley row
Browse files Browse the repository at this point in the history
  • Loading branch information
afishhh committed Nov 30, 2024
1 parent fd8413c commit bbe5662
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crates/epaint/src/text/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@ impl GalleyCache {
let current_offset = emath::vec2(0.0, merged_galley.rect.height());

let mut rows = galley.rows.iter();
// As documented in `Row::ends_with_newline`, a '\n' will always create a
// new `Row` immediately below the current one. Here it doesn't make sense
// for us to append this new row so we just ignore it.
if i != galleys.len() - 1 && !galley.elided {
let popped = rows.next_back();
debug_assert_eq!(popped.unwrap().row.glyphs.len(), 0);
Expand Down
2 changes: 1 addition & 1 deletion crates/epaint/src/text/text_layout_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ pub struct Row {
pub visuals: RowVisuals,

/// If true, this [`Row`] came from a paragraph ending with a `\n`.
/// The `\n` itself is omitted from [`glyphs`].
/// The `\n` itself is omitted from [`Self::glyphs`].
/// A `\n` in the input text always creates a new [`Row`] below it,
/// so that text that ends with `\n` has an empty [`Row`] last.
/// This also implies that the last [`Row`] in a [`Galley`] always has `ends_with_newline == false`.
Expand Down

0 comments on commit bbe5662

Please sign in to comment.