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

[epaint] Add more text wrapping options #1291

Merged
merged 13 commits into from
Apr 3, 2022
Merged

Conversation

awaken1ng
Copy link
Contributor

Add an ability to limit how many lines the text should have,
control breaking behavior a little bit,
and insert arbitrary character, e.g. , to represent clipped text.

Maybe TextWrapping::overflow_character should be renamed into something more descriptive, like overflow_representation?

out.mp4

@awaken1ng awaken1ng force-pushed the text-wrapping branch 2 times, most recently from d435431 to 5207e51 Compare February 22, 2022 10:46
@awaken1ng awaken1ng changed the title [epain] Add more text wrapping options [epaint] Add more text wrapping options Feb 22, 2022
@BctfN0HUK7Yg
Copy link
Contributor

Very good. I want to use it. Can you add wrapping by char (no by word) for small textareas?

@awaken1ng
Copy link
Contributor Author

Very good. I want to use it. Can you add wrapping by char (no by word) for small textareas?

For TextEdits? Or you mean a single line Label?

If you mean the latter, TextWrapping::break_anywhere should do exactly that, if it's set to true then wrapping will break at a character, instead of trying to break at a word, you can see it's behaviour in the demo video.

@awaken1ng awaken1ng force-pushed the text-wrapping branch 2 times, most recently from 9c8f906 to 4092f9a Compare February 23, 2022 13:29
@juancampa
Copy link
Contributor

Pulled this into my fork and it works like a charm, at least in my use case. Thank you!

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Left some comments, but looks good!

egui_demo_lib/src/apps/demo/misc_demo_window.rs Outdated Show resolved Hide resolved
Comment on lines 269 to 270
/// Set to `0` to disable this.
pub max_lines: usize,
Copy link
Owner

Choose a reason for hiding this comment

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

I think usize::MAX is a better way to disable it; then there is no need for any special cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default was initially usize::MAX, but I then later realized that if it's set to 0, then egui crashes in rows_from_paragraphs because we end up with no paragraphs, hence the check in line_break function.

epaint/src/text/text_layout_types.rs Outdated Show resolved Hide resolved
epaint/src/text/text_layout_types.rs Outdated Show resolved Hide resolved
epaint/src/text/text_layout.rs Outdated Show resolved Hide resolved
epaint/src/text/text_layout.rs Outdated Show resolved Hide resolved
@emilk emilk merged commit 901b7c7 into emilk:master Apr 3, 2022
emilk added a commit that referenced this pull request Apr 9, 2022
Using `max_rows == 0` as a special case was a bad idea.
@emilk emilk mentioned this pull request Apr 9, 2022
emilk added a commit that referenced this pull request Apr 9, 2022
Fix text layout bug added in #1291
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.

4 participants