mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Selectable text in Labels (#3814)
* Closes https://github.com/emilk/egui/issues/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`.  ## TODO * [x] Test
This commit is contained in:
@@ -142,7 +142,7 @@ impl LayoutJob {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.sections.is_empty()
|
||||
}
|
||||
@@ -618,22 +618,45 @@ impl Row {
|
||||
}
|
||||
|
||||
impl Galley {
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.job.is_empty()
|
||||
}
|
||||
|
||||
/// The full, non-elided text of the input job.
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn text(&self) -> &str {
|
||||
&self.job.text
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn size(&self) -> Vec2 {
|
||||
self.rect.size()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for Galley {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &str {
|
||||
self.text()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::borrow::Borrow<str> for Galley {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &str {
|
||||
self.text()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Galley {
|
||||
type Target = str;
|
||||
#[inline]
|
||||
fn deref(&self) -> &str {
|
||||
self.text()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// ## Physical positions
|
||||
|
||||
Reference in New Issue
Block a user