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

Add option to truncate text at wrap width #3244

Merged
merged 15 commits into from
Aug 14, 2023
Merged

Add option to truncate text at wrap width #3244

merged 15 commits into from
Aug 14, 2023

Conversation

emilk
Copy link
Owner

@emilk emilk commented Aug 12, 2023

You can now easily elide text that doesn't fit a certain max width.

This is done using Label::new(long_text).truncate(true). The text will be truncated to fit the max width of the parent Ui, and the ellipsis will replace the omitted text. The text may get truncated in the middle of a word. When hovering a label with elided text, the full non-elided text will be shown in a tool-tip.

You can use the options in TextWrapping for finer control.

⚠️ BREAKING: TextWrapping::max_rows == 0 will now output zero rows. Use usize::MAX to set no limit.
⚠️ BREAKING: TextWrapping::max_rows will now count total rows (not rows per paragraph, as previous).
ADDED: Galley::elided, to see if the text layout elided the input text

Most of the implementation had already be done by @awaken1ng in #1291

Future work

There are normally three modes of elision that can be desired:

  • Start: … jumps over the lazy dog
  • Middle: The quick … the lazy dog
  • End: The quick brown fox jumps…

This PR only adds support for the latter kind.

It would also be good to have an option to only omit whole words, never breaking them.

Finally, being able to set the truncate character to a string (e.g. with a leading space) would be nice.

@emilk emilk changed the title Add option to clip text to wrap width Add option to elide text to wrap width Aug 14, 2023
@emilk emilk marked this pull request as ready for review August 14, 2023 08:38
@emilk emilk changed the title Add option to elide text to wrap width Add elide option to truncate text at wrap width Aug 14, 2023
@emilk emilk added the text Problems related to text label Aug 14, 2023
@emilk emilk changed the title Add elide option to truncate text at wrap width Add option to truncate text at wrap width Aug 14, 2023
@emilk emilk changed the title Add option to truncate text at wrap width Add option to truncate text at wrap width Aug 14, 2023
Copy link
Collaborator

@abey79 abey79 left a comment

Choose a reason for hiding this comment

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

Great feature! Nothing strikes me in particular with the implementation. I just have a weak preference for truncateinstead of elide for the API until we have various forms of elision.

@emilk emilk merged commit a3ae81c into master Aug 14, 2023
34 checks passed
@emilk emilk deleted the emilk/clip-text branch August 14, 2023 09:22
abey79 added a commit to rerun-io/rerun that referenced this pull request Aug 16, 2023
### What

As the title says. Also fixes `StoreHub::remove_recording_id()` to only
change selection _if_ the currently selected recording is being removed
(otherwise the selection remains unchanged).

TODO:
- [x] blocked on emilk/egui#3244

<img width="1293" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/e2272633-86bb-423c-935d-c7dd8e68fe67">


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2976) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2976)
- [Docs
preview](https://rerun.io/preview/pr%3Aantoine%2Frecording-close-button/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aantoine%2Frecording-close-button/examples)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
@paul-hansen
Copy link

paul-hansen commented Oct 10, 2023

Just a heads up, this breaking change didn't seem to make it into the changelog for 0.22.0 in epaint or egui. Took a bit to figure out why text wasn't showing, but not the end of the world. Might want check to make sure whatever processes for updating the changelog is working for future breaking changes though.
Edit: Nvm I see it linked in epaint's changelog for 0.23.0, for some reason I thought I was on 0.22.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui epaint text Problems related to text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to truncate text in Label
3 participants