diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index e762ba73713..3a2772ceb60 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -1009,7 +1009,8 @@ fn all_metadata_body(ui: &mut egui::Ui, t: &Tokens, dlg: &mut Dialog) { egui::Grid::new(format!("meta-{g}")).num_columns(2).spacing([16.0, 3.0]).striped(true).show(ui, |ui| { for (n, v) in list { ui.label(egui::RichText::new(n).color(t.text_dim)); - ui.add(egui::Label::new(egui::RichText::new(v).color(t.text_label)).wrap()); + // values (serial numbers, lens names) are copied out of here; the field names are not + ui.add(egui::Label::new(egui::RichText::new(v).color(t.text_label)).wrap().selectable(true)); ui.end_row(); } }); diff --git a/crates/ui-egui/src/panels/library_problem.rs b/crates/ui-egui/src/panels/library_problem.rs index c4a1bd94728..0ed90f8eb41 100644 --- a/crates/ui-egui/src/panels/library_problem.rs +++ b/crates/ui-egui/src/panels/library_problem.rs @@ -1108,9 +1108,9 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context, blocked: bool) { ui.label(RichText::new(crate::i18n::tr("LightCraft couldn't find where to keep your library.")).color(t.text)); } else { ui.label(RichText::new(crate::i18n::tr("LightCraft couldn't open the library at")).color(t.text_label)); - ui.label(RichText::new(&problem.path).font(t.semibold(12.5)).color(t.text)); + ui.add(egui::Label::new(RichText::new(&problem.path).font(t.semibold(12.5)).color(t.text)).selectable(true)); } - ui.add(egui::Label::new(RichText::new(&problem.error).color(t.caution)).wrap()); + ui.add(egui::Label::new(RichText::new(&problem.error).color(t.caution)).wrap().selectable(true)); ui.label(RichText::new(EXPLANATION).color(t.text_dim)); ui.add_space(4.0); ui.horizontal(|ui| { @@ -1227,7 +1227,7 @@ fn show_chooser(app: &mut LightcraftApp, ctx: &egui::Context, problem: &LibraryP } }); if !problem.error.is_empty() { - ui.add(egui::Label::new(RichText::new(&problem.error).color(t.caution)).wrap()); + ui.add(egui::Label::new(RichText::new(&problem.error).color(t.caution)).wrap().selectable(true)); } let selected = chooser.selected.and_then(|i| chooser.libraries.get(i)); let mut button = |ui: &mut egui::Ui, id: &str, label: &str, enabled: bool, c: Choice| { diff --git a/crates/ui-egui/src/panels/right/info.rs b/crates/ui-egui/src/panels/right/info.rs index 5810a0f2721..5fbba25698d 100644 --- a/crates/ui-egui/src/panels/right/info.rs +++ b/crates/ui-egui/src/panels/right/info.rs @@ -102,7 +102,8 @@ pub(super) fn info(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) { lightcraft_catalog::Source::File { path } => path.clone(), lightcraft_catalog::Source::Demo { .. } => crate::i18n::tr("Generated demo photo").into(), }; - ui.add(egui::Label::new(egui::RichText::new(path).size(12.0).color(t.text_label)).truncate()); + // Selectable so the source path can still be copied (#1885 turned plain labels off). + ui.add(egui::Label::new(egui::RichText::new(path).size(12.0).color(t.text_label)).truncate().selectable(true)); if crate::menus::ui_enabled(app, "app.showInFinder") { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { if crate::widgets::icon_button(ui, "infoReveal", Icon::Folder, vec2(20.0, 20.0), false, true, crate::menus::reveal_label()) diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 63ada41941d..b83265e6aa9 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -490,6 +490,9 @@ pub fn apply_kind(ctx: &egui::Context, kind: ThemeKind) { s.text_styles.insert(egui::TextStyle::Small, FontId::proportional(11.0)); s.text_styles.insert(egui::TextStyle::Heading, FontId::new(16.0, FontFamily::Name(FONT_SEMIBOLD.into()))); s.animation_time = animation_time; + // Captions and headings are not text to select (#1885); text meant for copying opts in + // with `Label::selectable(true)`. + s.interaction.selectable_labels = false; }); } @@ -584,6 +587,46 @@ mod tests { } } + /// Drag the pointer across `label` from end to end, press Copy, and return what egui copied. + fn drag_and_copy(label: impl Fn() -> egui::Label) -> Option { + let ctx = egui::Context::default(); + apply_kind(&ctx, ThemeKind::default()); + let frame = |events: Vec| { + let input = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(400.0, 200.0))), + events, + ..Default::default() + }; + let mut rect = egui::Rect::NOTHING; + let mut out = ctx.run_ui(input, |ui| rect = ui.add(label()).rect); + out.textures_delta.clear(); + (out.platform_output.commands, rect) + }; + let (_, rect) = frame(vec![]); + let (from, to) = (rect.left_center() + egui::vec2(1.0, 0.0), rect.right_center() - egui::vec2(1.0, 0.0)); + let button = + |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let mut commands = Vec::new(); + for events in [ + vec![egui::Event::PointerMoved(from)], + vec![button(from, true)], + vec![egui::Event::PointerMoved(to)], + vec![button(to, false)], + vec![egui::Event::Copy], + ] { + commands.extend(frame(events).0); + } + commands.into_iter().find_map(|c| if let egui::OutputCommand::CopyText(text) = c { Some(text) } else { None }) + } + + /// #1885: a panel caption is not text to select, as in Lightroom; text a dialog offers for + /// copying (a path) opts in and still copies. + #[test] + fn static_labels_cannot_be_drag_selected_but_opted_in_text_can() { + assert_eq!(drag_and_copy(|| egui::Label::new("Exposure")), None, "a plain label was selected and copied"); + assert_eq!(drag_and_copy(|| egui::Label::new("/Users/me/Pictures").selectable(true)).as_deref(), Some("/Users/me/Pictures")); + } + /// #736: the release input must carry Thai, not silently skip the check with an older pin. /// Exercise the Thai characters of the reported folder name through every egui family. #[test]