1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Cross-widget text select (#3870)

* Closes https://github.com/emilk/egui/issues/3816


![cross-widget-text-selection](https://github.com/emilk/egui/assets/1148717/5582b9d2-8b04-47b7-9637-f48e44064a70)

Turn off with `style.interaction.multi_widget_text_select`.

There is an API for this in `LabelSelectionState`, but it's pretty
bare-bones.

This became really hairy implementation-wise, but it works decently
well.

# Limitations
* Drag-select to scroll doesn't work
* A selection disappears if you scroll past one of its end-points
* Only the text of labels and links are selectable
 
## TODO
* [x] An option to turn it off
* [x] An API for querying about the selected text, and to deselect it.
* [x] Scrolling past selection behaves weird
* [x] Shift-click to select a range
This commit is contained in:
Emil Ernerfeldt
2024-01-24 15:45:22 +01:00
committed by GitHub
parent bcf032a08f
commit 41aad74552
19 changed files with 714 additions and 139 deletions

View File

@@ -32,6 +32,7 @@ impl Default for Demos {
Box::<super::MiscDemoWindow>::default(),
Box::<super::multi_touch::MultiTouch>::default(),
Box::<super::painting::Painting>::default(),
Box::<super::panels::Panels>::default(),
Box::<super::plot_demo::PlotDemo>::default(),
Box::<super::scrolling::Scrolling>::default(),
Box::<super::sliders::Sliders>::default(),
@@ -42,7 +43,6 @@ impl Default for Demos {
Box::<super::widget_gallery::WidgetGallery>::default(),
Box::<super::window_options::WindowOptions>::default(),
Box::<super::tests::WindowResizeTest>::default(),
Box::<super::window_with_panels::WindowWithPanels>::default(),
])
}
}

View File

@@ -19,6 +19,7 @@ pub mod misc_demo_window;
pub mod multi_touch;
pub mod paint_bezier;
pub mod painting;
pub mod panels;
pub mod password;
pub mod plot_demo;
pub mod scrolling;
@@ -31,7 +32,6 @@ pub mod text_layout;
pub mod toggle_switch;
pub mod widget_gallery;
pub mod window_options;
pub mod window_with_panels;
pub use {
about::About, demo_app_windows::DemoWindows, misc_demo_window::MiscDemoWindow,

View File

@@ -1,15 +1,15 @@
#[derive(Clone, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowWithPanels {}
pub struct Panels {}
impl super::Demo for WindowWithPanels {
impl super::Demo for Panels {
fn name(&self) -> &'static str {
"🗖 Window With Panels"
"🗖 Panels"
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
use super::View as _;
let window = egui::Window::new("Window with Panels")
let window = egui::Window::new("Panels")
.default_width(600.0)
.default_height(400.0)
.vscroll(false)
@@ -18,7 +18,7 @@ impl super::Demo for WindowWithPanels {
}
}
impl super::View for WindowWithPanels {
impl super::View for Panels {
fn ui(&mut self, ui: &mut egui::Ui) {
// Note that the order we add the panels is very important!