Skip to content

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

Workspace: wire Enable Narrow Options Bar (#204) (#3870)

Reynold Hudcc9f86aa582
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index 208cee016..beef58c92 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -341,6 +341,14 @@ impl Default for Workspace {
}
}
+impl Workspace {
+ /// Preferences ▸ Workspace ▸ Enable Narrow Options Bar: the options bar drops to its compact
+ /// height, as in Photoshop, so the document gets more room (see `panels::options_bar`).
+ pub fn narrow_options_bar(&self) -> bool {
+ self.enable_narrow_options_bar
+ }
+}
+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Tools {
@@ -1046,7 +1054,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"workspace.autoCollapseIconPanels",
"workspace.autoShowHiddenPanels",
"workspace.enableFloatingDocumentWindowDocking",
- "workspace.enableNarrowOptionsBar",
"fileHandling.saveInBackground",
"fileHandling.maximizePsdCompatibility",
"performance.cacheLevels",
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index d908af7af..0f6a1b83b 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -852,10 +852,22 @@ fn reveal_focused_control(ui: &egui::Ui) {
// ----------------------------------------------------------------------------- options bar
+/// Options bar height: Preferences ▸ Workspace ▸ Enable Narrow Options Bar trims it, as in
+/// Photoshop, leaving the document more room.
+fn options_bar_height(pro: bool, narrow: bool) -> f32 {
+ match (pro, narrow) {
+ (true, false) => 36.0,
+ (true, true) => 30.0,
+ (false, false) => 42.0,
+ (false, true) => 34.0,
+ }
+}
+
pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
+ let narrow = app.session.prefs().workspace.narrow_options_bar();
egui::Panel::top("options_bar")
- .exact_size(if t.pro { 36.0 } else { 42.0 })
+ .exact_size(options_bar_height(t.pro, narrow))
.frame(egui::Frame::NONE.fill(t.chrome).inner_margin(egui::Margin::symmetric(10, 0)))
.show(ui, |ui| {
ui.style_mut().spacing.scroll = egui::style::ScrollStyle { bar_width: 4.0, ..egui::style::ScrollStyle::floating() };
@@ -5556,6 +5568,34 @@ mod compact_visual_regressions {
}
}
+ #[test]
+ fn the_narrow_options_bar_preference_shortens_the_bar() {
+ assert_eq!(options_bar_height(true, false), 36.0);
+ assert_eq!(options_bar_height(true, true), 30.0);
+ assert_eq!(options_bar_height(false, false), 42.0);
+ assert_eq!(options_bar_height(false, true), 34.0);
+ let ctx = egui::Context::default();
+ crate::theme::install_fonts(&ctx);
+ crate::theme::apply(&ctx, crate::theme::ThemeKind::ALL[0]);
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
+ let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 900.0));
+ let run = |app: &mut PhotocraftApp| {
+ let mut top = 0.0;
+ let mut out = ctx.run_ui(input_at_scale(screen, 1.0), |ui| {
+ options_bar(app, ui);
+ top = ui.available_rect_before_wrap().top();
+ });
+ out.textures_delta.clear();
+ top
+ };
+ let normal = run(&mut app);
+ assert_eq!(normal, options_bar_height(Tokens::get(&ctx).pro, false));
+ app.session.execute("prefs.set", json!({"path": "workspace.enableNarrowOptionsBar", "value": true})).unwrap();
+ let narrow = run(&mut app);
+ assert_eq!(narrow, options_bar_height(Tokens::get(&ctx).pro, true));
+ assert!(narrow < normal, "narrow {narrow} must trim the bar under {normal}");
+ }
+
#[test]
fn narrow_tool_options_can_scroll_to_the_last_control() {
for kind in crate::theme::ThemeKind::ALL {
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 01296e373..fb430469a 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: 29 of 155 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 13 | 5 | 5 | settings that do nothing: 28 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: 29 of 155** (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: 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.
-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`, `workspace.enable_narrow_options_bar`, `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_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`.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|