Skip to content

Conversation

NfNitLoop
Copy link

@NfNitLoop NfNitLoop commented Jul 21, 2025

Fixes #1272

  • I have followed the instructions in the PR template

for glyph in &mut row.glyphs {
glyph.pos.x += translate_x;
glyph.pos.x = point_scale.round_to_pixel(glyph.pos.x);
translate_x += extra_x_per_glyph;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: there was a secondary minor bug here:

previously we were distributing the extra_x_per_glyph among all glyphs, even those that we had chosen to be trimmed. We calculated extra_x_per_glyph based on num_glyphs_in_range, but were then multiplying it by total glyphs. We were probably getting a bit too much extra spacing.

Below, we only add more extra_x_* when we're operating on glyphs within the visible_glyphs range.


let glyph_range = if num_leading_spaces == row.glyphs.len() {
// There is only whitespace
(0, row.glyphs.len())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this logic in my refactor below. And I see that it avoids possible underflow when/after we get to the assert!() but I'm still a bit fuzzy on why we even continue in that case. Do we need to shift all of the spaces into a left/center/right-aligned location? So... what, they're in a useful place when selecting label texts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. Now I bet I see why all text was being trimmed when right-justified.

Each "row" that's being justified may contain a trailing space because the rest of the text has been moved into the next row.

I'll look into this later today. Which would you prefer?

  • A local solution within halign_and_justify_row() that fixes this case.
  • A higher-level fix, which will remove whitespace between rows as they get split? (I imagine this one might result in incorrect copy/paste though?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a fix within halign_and_justify_row.

Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be awesome if you could add an explicit test for this case so we don't break it in the future

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a fix within halign_and_justify_row.

Copy link

Preview available at https://egui-pr-preview.github.io/pr/7379-fix-justify
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect leading spaces for rendering

2 participants