Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): make clickable tab, checkbox, and radio labels non-selectable (#3972) (#4331)

Korg1chec61df6f06c1
diff --git a/crates/ui-egui/src/color_range_ui.rs b/crates/ui-egui/src/color_range_ui.rs
index 18084a6cc..37c90c18e 100644
--- a/crates/ui-egui/src/color_range_ui.rs
+++ b/crates/ui-egui/src/color_range_ui.rs
@@ -390,7 +390,9 @@ fn radio(ui: &mut egui::Ui, on: bool, label: &str) -> egui::Response {
if on {
ui.painter().circle_filled(r.center(), 3.0, t.accent);
}
- let l = ui.add(egui::Label::new(egui::RichText::new(tl!(&label)).color(t.text_dim)).sense(Sense::click()));
+ let l = ui
+ .add(egui::Label::new(egui::RichText::new(tl!(&label)).color(t.text_dim)).selectable(false).sense(Sense::click()))
+ .on_hover_cursor(egui::CursorIcon::PointingHand);
resp.union(l)
})
.inner
diff --git a/crates/ui-egui/src/gallery_ui.rs b/crates/ui-egui/src/gallery_ui.rs
index ed1597deb..ccf1a7637 100644
--- a/crates/ui-egui/src/gallery_ui.rs
+++ b/crates/ui-egui/src/gallery_ui.rs
@@ -609,7 +609,8 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
let r = ui.horizontal(|ui| {
let (ir, _) = ui.allocate_exact_size(vec2(16.0, 16.0), Sense::hover());
crate::icons::paint(ui, ir, icon, 14.0, t.icon);
- ui.add(egui::Label::new(egui::RichText::new(tl!(*cat)).color(t.text)).sense(Sense::click()))
+ ui.add(egui::Label::new(egui::RichText::new(tl!(*cat)).color(t.text)).selectable(false).sense(Sense::click()))
+ .on_hover_cursor(egui::CursorIcon::PointingHand)
});
if r.inner.clicked() {
d.open[ci] = !d.open[ci];
diff --git a/crates/ui-egui/src/new_doc_ui.rs b/crates/ui-egui/src/new_doc_ui.rs
index fe37bd0d2..9fe06a1a5 100644
--- a/crates/ui-egui/src/new_doc_ui.rs
+++ b/crates/ui-egui/src/new_doc_ui.rs
@@ -450,7 +450,9 @@ pub fn body(app: &mut crate::PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<Strin
for name in CATEGORIES.iter().map(|c| c.0).chain(["Saved"]) {
let on = cat == name;
let label = if name == "Saved" { tl!("Saved") } else { tl!(name) };
- let r = ui.add(egui::Label::new(RichText::new(label).size(13.0).color(if on { t.text } else { t.text_dim })).sense(Sense::click()));
+ let r = ui
+ .add(egui::Label::new(RichText::new(label).size(13.0).color(if on { t.text } else { t.text_dim })).selectable(false).sense(Sense::click()))
+ .on_hover_cursor(egui::CursorIcon::PointingHand);
if on {
ui.painter().line_segment([r.rect.left_bottom() + vec2(0.0, 3.0), r.rect.right_bottom() + vec2(0.0, 3.0)], Stroke::new(2.0, t.text));
}
@@ -1317,5 +1319,20 @@ mod tests {
enter(&mut h);
assert_eq!(created(&h), (256, 512, 72.0));
}
+
+ #[test]
+ fn hovering_preset_tabs_shows_pointing_hand_not_text_cursor() {
+ let mut h = harness();
+ for tab in ["Recent", "Saved", "Photo", "Print", "Art & Illustration", "Web", "Mobile", "Film & Video"] {
+ let rect = h.get_by_label(tab).rect();
+ h.hover_at(rect.center());
+ h.run_steps(2);
+ assert_eq!(
+ h.output().platform_output.cursor_icon,
+ egui::CursorIcon::PointingHand,
+ "hovering preset tab {tab:?} must show PointingHand instead of text caret"
+ );
+ }
+ }
}
}