Skip to content
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

Alignment of long text without word wrap #240

Open
jamesthurley opened this issue Jan 7, 2025 · 0 comments · May be fixed by #241
Open

Alignment of long text without word wrap #240

jamesthurley opened this issue Jan 7, 2025 · 0 comments · May be fixed by #241

Comments

@jamesthurley
Copy link

As per the Zulip discussion here.

My code currently looks like this:

    let max_advance = if text_context.wrap {
        width_constraint
    } else {
        Some(f32::MAX)
    };
    layout.break_all_lines(max_advance);
    layout.align(
        width_constraint,
        match text_context.horizontal_alignment {
            HorizontalAlignment::Center => Alignment::Middle,
            HorizontalAlignment::Right => Alignment::End,
            HorizontalAlignment::Left => Alignment::Start,
        },
    );

When word wrap is off I've found I still need to call break_all_lines and I still need to supply a max_advance, so I set it to f32::MAX. This is fine.

This code is all working well, except for the cases where word wrap is off, the text is longer than the width constraint, and the text alignment is Middle or End.

The result is as follows:

image

There are 9 tests here. First three left aligned, then right aligned, then centered. Within each set of three tests the middle test case is the problematic one - you can see in all three cases it gets left-aligned.

The expected behaviour was that the left side of the right-aligned text would be cropped, and both sides of the centered text would be cropped. Although with further thought I can see that chopping off the start of the text may not always be desirable.

After the discussion on Zulip it was decided I should create a GitHub issue.

@nicoburns nicoburns linked a pull request Jan 17, 2025 that will close this issue
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 a pull request may close this issue.

1 participant