-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix text wrapping too late #2791
base: master
Are you sure you want to change the base?
Conversation
861e3e9
to
462f6db
Compare
if first_row_indentation > 0.0 | ||
&& !row_break_candidates.has_good_candidate(job.wrap.break_anywhere) | ||
{ | ||
// Allow the first row to be completely empty, because we know there will be more space on the next row: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If first_row_indentation == 0.0
then we never want an empty first row. We would rather overflow max_width
, because otherwise we will just run into the same problem on the next row. For instance if max_width == 0.0
we want a layout where we have exactly one glyph per row.
If first_row_indentation > 0.0
however we are fine with having an empty row, because there will be more space available on the next row, and that might be enough to fit the first word or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does your code handle this case (max_width == 0.0
) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran this in examples/wrapped_layout and it seems to work as you describe (one glyph per row).
let mut chui = ui.child_ui(
Rect::from_two_pos(ui.cursor().min, ui.cursor().min),
Layout::left_to_right(Align::Center),
);
chui.horizontal_wrapped(|ui| {
ui.label("Frick");
});
Is there more work to be done here, or is it ready for review? |
We've been using this patch for a few weeks now in https://github.com/mikedilger/gossip/. We did have to add another patch, to fix the case where the cursor is initialized to non-interactive default size and not to line height. It's a rough fix, I think the only way to fix it properly is to have a separate property for line height in the cursor (because you need to know line height for wrapping). This is the problem (the URL should actually be on the second line): And this is our additional patch: So in case you want to incorporate that patch as well, I would consider this one ready to merge. |
… source paragraph (the one that is too long) for which length has already been processed. When creating an empty row, this position should not be updated as no glyphs were consumed from the source paragraph. - added example that would demonstrate the problem if the line was included, and that is fixed with this commit Fix issue emilk#2578 There was confusion in the code over how to break when on a non-empty visual row (`first_row_indentation > 0.0`), causing text to be shifted left outside the ui frame. This is the case for example when another label has already been placed in this `ui.horizontal_wrapped()`. This fix will not create an empty row, essentially starting a newline, but rather try to fit as much text as possible on the existing row. IMO this is the desired use of a wrapping layout. I've also added an example that would demonstrate the problem if the line was included, and that is fixed with this commit
c9cc52c
to
a286a2d
Compare
Since this bug in |
since I'm hitting this issue on https://github.com/damus-io/notedeck I will try this and report back! |
UPDATE
This PR now fixes both #2578 and #2793. These fixes have now been tested for many months in https://github.com/mikedilger/gossip app.
To reproduce the problem, paste this code into a hello_world example:
Description for #2578 fix:
There was confusion in the code over how to break when on a non-empty visual row (
first_row_indentation > 0.0
), causing text to be shifted left outside the ui frame. This is the case for example when another label has already been placed in thisui.horizontal_wrapped()
.This fix will not create an empty row, essentially starting a newline, but rather try to fit as much text as possible on the existing row. IMO this is the desired use of a wrapping layout.
Description for #2793 fix:
Do not apply item_spacing to cursor when creating a new row