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

Selectable text in labels #3804

Closed
emilk opened this issue Jan 10, 2024 · 3 comments · Fixed by #3814
Closed

Selectable text in labels #3804

emilk opened this issue Jan 10, 2024 · 3 comments · Fixed by #3814
Assignees
Labels
egui feature New feature or request rerun Desired for Rerun.io text Problems related to text

Comments

@emilk
Copy link
Owner

emilk commented Jan 10, 2024

We should have an option to turn on selectable text in labels, i.e. how text works on a website.

Drag-to-select, double-click to select words, triple-click to select entire text, etc.

As a first step, let's limit ourselves to selection within a single Label (not selections spanning multiple widgets).

Since only one label can have a selection at a time, this means some sort of shared mono-state for the labels, mapping a label widget Id to a CCursorRange, similar to TextEdit. We should keep the same selected range of characters even if the label text changes (you should be able to select a label which text is changing).

We need to figure out a good way to share code between TextEdit and Label (all the logic for cursors, selection, etc);

In browsers you can also use the keyboard to select parts of the text (i.e. shift-arrows to move selection), but I suggest we punt on that (I suspect it is a seldom used feature).

Note that making text selectable means they now responds to clicks and drags, so that e.g. "drag-to-scroll" won't work if you drag a label. I think therefore this should be n opt-in feature, globally.

We also have to figure out how this feature interact with text elision (when text is shortened using )

@emilk emilk added feature New feature or request text Problems related to text dependencies Pull requests that update a dependency file egui rerun Desired for Rerun.io labels Jan 10, 2024
@emilk emilk added this to the Next Major Release milestone Jan 10, 2024
@YgorSouza
Copy link
Contributor

In web pages, some widgets have selectable text but still respond to click and drag without selecting the text. There are some example right here in this page.

web_browser_text_highlighting.mp4

Would this be an end goal for egui? I guess it would be a matter of keeping a global selection rect for each viewport (or maybe for each area) which is updated according to the user's gestures (Shift + click etc), and then each widget containing selectable text would calculate its intersection with this rect and highlight its text accordingly. And I guess PlatformOutput::copied_text would have to be converted to a Vec? So every widget could push its highlighted text to it, and at the end it would all be joined by newlines and pushed to the clipboard. Or maybe the widgets could just add the newlines themselves as needed when appending to the string.

But egui is also used to make entire desktop apps rather than just web pages, so it should probably still have text that isn't selectable at all, right? Like the tab names and other buttons on the browser.

@emilk emilk self-assigned this Jan 13, 2024
@emilk emilk removed the dependencies Pull requests that update a dependency file label Jan 13, 2024
@emilk emilk mentioned this issue Jan 13, 2024
1 task
@emilk
Copy link
Owner Author

emilk commented Jan 13, 2024

@YgorSouza that would be nice, but is a lot more workand outside the scope of this issue.

emilk added a commit that referenced this issue Jan 14, 2024
* Closes #3804

Add ability to select the text in labels with mouse-drag, double-click,
and keyboard (once clicked).
Hit Cmd+C to copy the text. If everything of a label with elided text is
selected, the copy command will copy the full non-elided text. IME and
accesskit _should_ work, but is untested.

You can control wether or not text in labels is selected globally in
`style.interaction.selectable_labels` or on a per-label basis in
`Label::selectable`. The default is ON.

This also cleans up the `TextEdit` code somewhat, fixing a couple
smaller bugs along the way.

This does _not_ implement selecting text across multiple widgets. Text
selection is only supported within a single `Label`, `TextEdit`, `Link`
or `Hyperlink`.


![label-text-selection](https://github.com/emilk/egui/assets/1148717/c161e819-50da-4b97-9686-042e6abf3564)


## TODO
* [x] Test
@emilk
Copy link
Owner Author

emilk commented Jan 14, 2024

@YgorSouza I created a follow-up issue for multi-widget select in #3816

emilk added a commit that referenced this issue Jan 19, 2024
This is a follow-up to #3804 and a
pre-requisite for #3816
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request rerun Desired for Rerun.io text Problems related to text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants