-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments
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.mp4Would 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 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. |
@YgorSouza that would be nice, but is a lot more workand outside the scope of this issue. |
* 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
@YgorSouza I created a follow-up issue for multi-widget select in #3816 |
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 aCCursorRange
, similar toTextEdit
. 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
andLabel
(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
…
)The text was updated successfully, but these errors were encountered: