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

Leading whitespaces in text are not drawn to the screen #45

Open
d0rianb opened this issue Dec 23, 2021 · 7 comments
Open

Leading whitespaces in text are not drawn to the screen #45

d0rianb opened this issue Dec 23, 2021 · 7 comments

Comments

@d0rianb
Copy link

d0rianb commented Dec 23, 2021

When there is leading whitespace in a text, they are not calculated by the layout_text method.
By removing this block of code, it works as intended :

    // Skip whitespace
    while let Some(word) = words.peek() {
        if word.is_whitespace {
            words.next().unwrap();
        } else {
            break;
        }
    }
@QuantumBadger
Copy link
Owner

Thanks for the report. This is intentional due to the word wrapping logic, and it's the behaviour of most text boxes/word processors/etc. However, if you use non-breaking spaces then I think you may get the behaviour you want.

https://unicode-table.com/en/00A0/

It's unicode 160 (0x00A0) -- if you replace all the normal spaces with this then I think they shouldn't be removed.

@d0rianb
Copy link
Author

d0rianb commented Dec 23, 2021

Thanks it works.
Is it a solution for tab characters \t which are also cut during the wrapping ?

@QuantumBadger
Copy link
Owner

Glad to hear it works :) The same solution should be usable for tabs, but you would need to replace the \t with multiple non-breaking spaces.

@Revertron
Copy link
Contributor

Maybe it would be better to add a parameter to layout_text, say keep_spaces, to ease the life? :-/

@QuantumBadger
Copy link
Owner

Maybe it would be better to add a parameter to layout_text, say keep_spaces, to ease the life? :-/

Yeah I think that's a good idea.

@matklad
Copy link
Contributor

matklad commented Mar 19, 2023

Also hitting this! In my case, I am rendering in monospaced font, so I obviously care about whitespace for alignment.

Couple of other options here:

  • trim only leading whitespace which would have been introduced by word-wrap
  • trim only if options.wrap_words_after_width is set

@QuantumBadger
Copy link
Owner

Now fixed thanks to @InfiniteCoder01! TextOptions::with_trim_each_line() will be in version 2.0.0.

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

No branches or pull requests

4 participants