Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #1708

Brandon Thomasa0401d6949df
diff --cc crates/ui-egui/src/panels/edit.rs
index d67f35cc4,2e59508eb..23c68a933
--- a/crates/ui-egui/src/panels/edit.rs
+++ b/crates/ui-egui/src/panels/edit.rs
@@@ -699,58 -678,22 +699,62 @@@ fn histogram(app: &mut LightcraftApp, u
p.add(egui::Shape::line(pts, Stroke::new(1.5, *c)));
}
}
- let (lo, hi) = h.clipping();
- // the panel's floating scroll bar widens over the right edge when hovered: both buttons keep
- // clear of it, the left one too so they stay symmetric (#1640)
- let scroll = ui.spacing().scroll;
- let inset = 12.0 + scroll.bar_width + scroll.bar_outer_margin;
- for (name, on, x, active) in
- [("low", lo > 0.003, plot.left() + inset, app.ui.show_clipping), ("high", hi > 0.003, plot.right() - inset, app.ui.show_clipping)]
- {
- let tri = Rect::from_center_size(pos2(x, plot.top() + 10.0), vec2(14.0, 12.0));
- register(ui.ctx(), format!("histogramClip:{name}"), tri);
- p.rect_filled(tri, 2.0, if active { t.hover } else { Color32::from_gray(60) });
- paint(p, tri.shrink(2.0), Icon::ChevronDown, if on { Color32::WHITE } else { Color32::from_gray(130) });
+ }
+ let mut clicked = resp.clicked();
++ // the panel's floating scroll bar widens over the right edge when hovered: both buttons keep
++ // clear of it, the left one too so they stay symmetric (#1640)
++ let scroll = ui.spacing().scroll;
++ let inset = 20.0 + scroll.bar_width + scroll.bar_outer_margin;
+ for (name, x, label, clipped) in [
- ("shadows", plot.left() + 20.0, "Shadow clipping", clipping.map(|(lo, _)| lo > 0.003)),
- ("highlights", plot.right() - 20.0, "Highlight clipping", clipping.map(|(_, hi)| hi > 0.003)),
++ ("shadows", plot.left() + inset, "Shadow clipping", clipping.map(|(lo, _)| lo > 0.003)),
++ ("highlights", plot.right() - inset, "Highlight clipping", clipping.map(|(_, hi)| hi > 0.003)),
+ ] {
+ let rect = Rect::from_center_size(pos2(x, plot.top() + 14.0), vec2(24.0, 22.0));
+ let response = ui.interact(rect, ui.id().with(("histogram-clipping", name)), Sense::click());
+ register(ui.ctx(), format!("histogram:{name}"), rect);
+ response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), app.ui.show_clipping, crate::i18n::tr(label)));
+ clicked |= response.clicked();
+ let active = app.ui.show_clipping;
+ // Keep the hit target comfortable, with a smaller box and clear space to the plot edges.
+ let box_rect = rect.shrink2(vec2(2.0, 2.0));
+ p.rect_filled(
+ box_rect,
+ 3.0,
+ if active {
+ t.pressed
+ } else if response.hovered() {
+ t.hover
+ } else {
+ Color32::from_gray(60)
+ },
+ );
+ if active {
+ p.rect_stroke(box_rect, 3.0, Stroke::new(1.0, t.text), egui::StrokeKind::Inside);
}
+ paint(
+ p,
+ Rect::from_center_size(rect.center(), vec2(16.0, 16.0)),
+ Icon::ChevronDown,
+ if clipped == Some(true) || active { t.text } else { t.text_dim },
+ );
+ let status = match clipped {
+ Some(true) => "Clipping detected in this preview.",
+ Some(false) => "No clipping detected in this preview.",
+ None => "Histogram not yet available.",
+ };
+ response.on_hover_text(format!(
+ "{}\n{}\n{}",
+ crate::i18n::tr(label),
+ crate::i18n::tr(if active {
+ "Click to hide clipping warnings for shadows and highlights."
+ } else {
+ "Click to show clipping warnings for shadows and highlights."
+ }),
+ crate::i18n::tr(status)
+ ));
}
- if resp.clicked() {
- app.ui.show_clipping = !app.ui.show_clipping;
+ if clicked {
+ let _ = app.run("view.clipping", json!({}));
}
// EXIF strip
if let Some(ph) = app.session.catalog.photo(id) {
diff --cc crates/ui-egui/src/tests_panels.rs
index 5b979ccdc,aa2c8ece5..8e360f862
--- a/crates/ui-egui/src/tests_panels.rs
+++ b/crates/ui-egui/src/tests_panels.rs
@@@ -2366,29 -2366,19 +2366,46 @@@ fn new_album_can_leave_the_selected_pho
assert!(photos(&h, "Nothing").is_empty());
}
+/// Histogram corner controls stay usable even before a histogram is available, and each
+/// click invokes the same clipping-warning command as the J shortcut exactly once.
+#[test]
+fn histogram_corners_toggle_clipping_warnings() {
+ let mut h = demo([1400.0, 1000.0], json!({"view": "detail", "right": "edit"}));
+ for texture in h.app.renderer.textures.values_mut() {
+ texture.histogram = None;
+ }
+ h.step();
+ h.app.ui.show_clipping = false;
+ let histogram = h.app.widgets.iter().find(|(id, _)| id == "histogram").unwrap().1;
+ for id in ["histogram:shadows", "histogram:highlights"] {
+ let rect = h.app.widgets.iter().find(|(widget, _)| widget == id).unwrap().1;
+ assert!(histogram.shrink(8.0).contains_rect(rect), "{id} keeps clear space to the histogram edges: {rect:?} in {histogram:?}");
+ }
+ for (id, enabled) in [("histogram:shadows", true), ("histogram:highlights", false), ("histogram", true)] {
+ let r = h.request("ui.clickWidget", json!({"id": id}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ assert_eq!(h.app.ui.show_clipping, enabled, "{id} must toggle exactly once");
+ }
+ let r = h.request("ui.key", json!({"key": "J"}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.step();
+ assert!(!h.app.ui.show_clipping);
+}
++
+ #[test]
+ fn the_histogram_clipping_buttons_stay_clear_of_the_hovered_scroll_bar() {
+ // every section open: the Edit panel scrolls, so its scroll bar runs past the histogram
+ let h = demo(
+ [1400.0, 700.0],
+ json!({"view": "detail", "right": "edit", "histogram": true, "openSections": ["light", "color", "effects", "detail", "optics"]}),
+ );
+ let hist = widget(&h, "histogram");
- let (low, high) = (widget(&h, "histogramClip:low"), widget(&h, "histogramClip:high"));
++ let (low, high) = (widget(&h, "histogram:shadows"), widget(&h, "histogram:highlights"));
+ // a hovered floating scroll bar grows to its full width at the panel's right edge, over the content
+ let scroll = h.view.ctx.global_style().spacing.scroll;
+ let bar_left = hist.right() - scroll.bar_outer_margin - scroll.bar_width;
+ assert!(high.right() <= bar_left, "the highlight clipping button {high:?} is under the scroll bar (from x = {bar_left})");
+ // and the shadow one keeps the same inset from its edge
+ assert!(((low.left() - hist.left()) - (hist.right() - high.right())).abs() < 0.5, "{low:?} {high:?} in {hist:?}");
+ }