Skip to content

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

Workspace: wire Auto-Collapse Iconic Panels (#204) (#3880)

Reynold Hu6c7328b7093a
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index beef58c92..cffc39bcc 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -1051,7 +1051,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"general.colorPicker",
"general.animatedZoom",
"general.zoomResizesWindows",
- "workspace.autoCollapseIconPanels",
"workspace.autoShowHiddenPanels",
"workspace.enableFloatingDocumentWindowDocking",
"fileHandling.saveInBackground",
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index 089fb6cd2..6115e06a3 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -424,6 +424,26 @@ fn rects_id() -> egui::Id {
egui::Id::new("dock-group-rects")
}
+/// The group expanded from its collapsed tab strip (see [`show`]), if any: with Preferences ▸
+/// Workspace ▸ Auto-Collapse Iconic Panels on, the first click outside it collapses it again.
+fn peek_id() -> egui::Id {
+ egui::Id::new("dock-peek")
+}
+
+fn auto_collapse_peek(app: &mut PhotocraftApp, ctx: &egui::Context) {
+ let Some(g) = ctx.data(|d| d.get_temp::<Option<Group>>(peek_id())).flatten() else { return };
+ let Some(p) = ctx.input(|i| i.pointer.any_pressed().then(|| i.pointer.press_origin()).flatten()) else {
+ return;
+ };
+ let inside = last_rects(ctx).into_iter().find(|(x, _)| *x == g).is_some_and(|(_, r)| r.contains(p));
+ if !inside {
+ app.ui.dock.set_collapsed(g, true);
+ ctx.data_mut(|d| {
+ d.insert_temp(peek_id(), None::<Group>);
+ });
+ }
+}
+
/// A group's tab strip as drawn last frame (screen points), for tests and automation.
#[derive(Clone, Debug, PartialEq)]
pub struct StripRects {
@@ -451,6 +471,14 @@ fn strips_id() -> egui::Id {
/// group's tab content.
pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut body: impl FnMut(&mut PhotocraftApp, &mut egui::Ui, Group, usize)) {
let t = Tokens::get(ui.ctx());
+ let auto_collapse = app.session.prefs().workspace.auto_collapse_icon_panels;
+ if auto_collapse {
+ auto_collapse_peek(app, ui.ctx());
+ } else {
+ ui.ctx().data_mut(|d| {
+ d.insert_temp(peek_id(), None::<Group>);
+ });
+ }
let strip = if t.pro { 28.0 } else { 40.0 };
let order: Vec<Group> = app.ui.dock.order().into_iter().filter(|g| shown.contains(g)).collect();
let area = ui.available_rect_before_wrap();
@@ -458,6 +486,7 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bod
let locked = app.session.prefs().workspace_locked;
let rects = rects_after_layout(&heights, area);
let mut actions: Vec<Action> = Vec::new();
+ let mut peek_after: Option<Group> = None;
let mut tab_drops: Vec<(Group, usize, Pos2)> = Vec::new();
let mut dragging: Option<Group> = None;
let mut strips: Vec<StripRects> = Vec::with_capacity(rects.len());
@@ -525,6 +554,11 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bod
}
if resp.strip.double_clicked() || resp.tab_double_clicked || (collapsed && resp.tab_clicked) {
actions.push(Action::ToggleCollapse(g));
+ // A single click on a collapsed strip's tab expands the group as a peek: the next
+ // click outside closes it again, with Auto-Collapse Iconic Panels on.
+ if collapsed && resp.tab_clicked && !resp.tab_double_clicked && auto_collapse {
+ peek_after = Some(g);
+ }
}
// The strip uses visible indices; reorder in original ones.
if !locked
@@ -663,6 +697,13 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bod
}
}
}
+ if let Some(g) = peek_after
+ && !app.ui.dock.is_collapsed(g)
+ {
+ ui.ctx().data_mut(|d| {
+ d.insert_temp(peek_id(), Some(g));
+ });
+ }
for (panel, anchor, before) in panel_moves {
let params = if before { json!({"panel":panel,"anchor":anchor,"before":anchor}) } else { json!({"panel":panel,"anchor":anchor}) };
if let Err(error) = app.run("window.panel.move", params) {
diff --git a/crates/ui-egui/src/dock_tests.rs b/crates/ui-egui/src/dock_tests.rs
index b5ade1d58..beb6b913d 100644
--- a/crates/ui-egui/src/dock_tests.rs
+++ b/crates/ui-egui/src/dock_tests.rs
@@ -350,6 +350,43 @@ fn a_single_tab_click_expands_a_collapsed_panel() {
}
}
+/// Auto-Collapse Iconic Panels: a group expanded by clicking a tab on its collapsed strip
+/// closes again when the next click lands outside it; with the preference off it stays open.
+#[test]
+fn auto_collapse_icon_panels_closes_a_peeked_panel_on_an_outside_click() {
+ for auto in [true, false] {
+ let (mut app, _, _) = app_with_layers();
+ app.session.prefs.edit(|p| p.workspace.auto_collapse_icon_panels = auto);
+ app.ui.dock.set_collapsed(Group::Color, true);
+ let mut h = harness(app, vec2(1200.0, 800.0), ThemeKind::ProMedium);
+ let collapsed_height = rect_of(&h, Group::Color).height();
+ let tab = last_strips(&h.ctx).iter().find(|s| s.group == Group::Color).unwrap().tabs[0].1.center();
+ h.event(egui::Event::PointerMoved(tab));
+ h.run_steps(1);
+ h.event(egui::Event::PointerButton { pos: tab, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
+ h.step();
+ h.event(egui::Event::PointerButton { pos: tab, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
+ h.run_steps(3);
+ assert!(!h.state().ui.dock.is_collapsed(Group::Color), "auto={auto}: the tab click expands the panel");
+ let rect = rect_of(&h, Group::Color);
+ // A click inside the panel leaves it open; one outside (the canvas) closes it again.
+ for p in [rect.center(), Pos2::new(rect.left() / 2.0, rect.center().y)] {
+ h.event(egui::Event::PointerMoved(p));
+ h.run_steps(1);
+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
+ h.step();
+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
+ h.run_steps(3);
+ }
+ assert_eq!(h.state().ui.dock.is_collapsed(Group::Color), auto, "auto={auto}: outside closes it when enabled");
+ if auto {
+ assert_eq!(rect_of(&h, Group::Color).height(), collapsed_height);
+ } else {
+ assert!(rect_of(&h, Group::Color).height() > collapsed_height);
+ }
+ }
+}
+
#[test]
fn double_clicking_a_tab_collapses_and_dragging_a_strip_reorders() {
let (app, _, _) = app_with_layers();
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 46f62ffd4..78a086454 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 6 | 13 | 8 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 28 | 14 | 1 | |
-| [Workspace and UI](#workspace-and-ui) | 13 | 5 | 5 | settings that do nothing: 28 of 156 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 13 | 5 | 5 | settings that do nothing: 27 of 156 (target 0) |
| [Type](#type) | 4 | 2 | 3 | |
| [Automation](#automation) | 4 | 2 | 5 | 631 of 631 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |
@@ -176,9 +176,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 28 of 156** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
+**Settings that do nothing: 27 of 156** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
-Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
+Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|