Skip to content

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

Status bar: show document dimensions in the ruler unit (#2618)

Arthur Wagner2194c7c58f39
diff --git a/crates/ui-egui/src/chrome_ui.rs b/crates/ui-egui/src/chrome_ui.rs
index 86cd0b0c3..4d2cdf5b7 100644
--- a/crates/ui-egui/src/chrome_ui.rs
+++ b/crates/ui-egui/src/chrome_ui.rs
@@ -75,6 +75,10 @@ pub fn document_sizes(doc: &Document) -> (u64, u64) {
/// The status bar text for `key` (Photoshop wording).
pub fn status_info_text(doc: &Document, key: &str, tool: &str, profile: &str) -> String {
+ status_info_text_with_units(doc, key, tool, profile, &Default::default())
+}
+
+fn status_info_text_with_units(doc: &Document, key: &str, tool: &str, profile: &str, units: &photocraft_engine::prefs::UnitsAndRulers) -> String {
let bits = doc.depth.bits();
match key {
"sizes" => {
@@ -93,10 +97,18 @@ pub fn status_info_text(doc: &Document, key: &str, tool: &str, profile: &str) ->
let n = doc.layer_count();
crate::i18n::trn(crate::i18n::current(), n as u64, "{n} Layer", "{n} Layers")
}
- _ => crate::i18n::fmt(
+ _ if units.rulers == photocraft_engine::prefs::Unit::Pixels => crate::i18n::fmt(
tl!("{w} px x {h} px ({ppi} ppi)"),
&[("w", &doc.size.width.to_string()), ("h", &doc.size.height.to_string()), ("ppi", &widgets::fmt_num(doc.resolution_dpi as f64))],
),
+ _ => {
+ let dpi = doc.resolution_dpi as f64;
+ let (w, h) = (doc.size.width as f64, doc.size.height as f64);
+ crate::i18n::fmt(
+ tl!("{w} {unit} x {h} {unit} ({ppi} ppi)"),
+ &[("w", &units.format(w, dpi, w)), ("h", &units.format(h, dpi, h)), ("unit", units.rulers.suffix()), ("ppi", &widgets::fmt_num(dpi))],
+ )
+ }
}
}
@@ -128,7 +140,13 @@ pub fn status_bar_pro(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
status_message(app, ui, &t);
return;
};
- let text = status_info_text(&st.doc, &app.ui.chrome.status_info, tl!(app.ui.tool.label()), &profile_name(&st.doc));
+ let text = status_info_text_with_units(
+ &st.doc,
+ &app.ui.chrome.status_info,
+ tl!(app.ui.tool.label()),
+ &profile_name(&st.doc),
+ &app.session.prefs().units_and_rulers,
+ );
let mut pct = app.ui.views[i].zoom * 100.0;
if widgets::value_field(ui, &mut pct, crate::zoom_levels::percent_range(&app.ui.views[i]), "%", 64.0).changed() {
app.ui.views[i].zoom = crate::zoom_levels::clamp(pct / 100.0, app.ui.views[i].doc_size);
@@ -241,6 +259,65 @@ mod tests {
assert!(status_info_text(&d, "profile", "", "sRGB IEC61966-2.1").ends_with("(8bpc)"));
}
+ #[test]
+ fn status_dimensions_follow_ruler_units_and_document_resolution() {
+ use photocraft_engine::prefs::{PointSize, Unit, UnitsAndRulers};
+ let mut d = doc();
+ d.resolution_dpi = 300.0;
+ for (unit, expected) in [
+ (Unit::Pixels, "2400 px x 1500 px (300 ppi)"),
+ (Unit::Inches, "8 in x 5 in (300 ppi)"),
+ (Unit::Centimeters, "20.32 cm x 12.7 cm (300 ppi)"),
+ (Unit::Millimeters, "203.2 mm x 127 mm (300 ppi)"),
+ (Unit::Points, "576 pt x 360 pt (300 ppi)"),
+ (Unit::Picas, "48 pica x 30 pica (300 ppi)"),
+ (Unit::Percent, "100 % x 100 % (300 ppi)"),
+ ] {
+ let units = UnitsAndRulers { rulers: unit, ..Default::default() };
+ assert_eq!(status_info_text_with_units(&d, "dimensions", "", "", &units), expected);
+ for (key, _) in STATUS_INFO.iter().filter(|(key, _)| *key != "dimensions") {
+ assert_eq!(status_info_text_with_units(&d, key, "Brush Tool", "sRGB", &units), status_info_text(&d, key, "Brush Tool", "sRGB"));
+ }
+ }
+ d.resolution_dpi = 240.0;
+ let units = UnitsAndRulers { rulers: Unit::Points, point_size: PointSize::Traditional, ..Default::default() };
+ assert_eq!(status_info_text_with_units(&d, "dimensions", "", "", &units), "722.7 pt x 451.7 pt (240 ppi)");
+ }
+
+ #[test]
+ fn status_bar_updates_dimensions_after_a_ruler_preference_change() {
+ use egui_kittest::{Harness, kittest::Queryable};
+ let mut failures = Vec::new();
+ for theme in [crate::theme::ThemeKind::Pro, crate::theme::ThemeKind::ProMedium] {
+ for width in [800.0, 1200.0] {
+ let builder = Harness::builder().with_size(vec2(width, 600.0)).with_max_steps(64);
+ let mut h = builder.build_eframe(move |cc| {
+ PhotocraftApp::setup_context(&cc.egui_ctx, theme);
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("prefs.set", json!({"path": "interface.theme", "value": theme.id()})).unwrap();
+ app.ui.theme = theme;
+ app
+ });
+ h.state_mut().run("file.new", json!({"width": 1920, "height": 1080, "resolution": 72})).unwrap();
+ h.state_mut().sync_views();
+ h.run_steps(4);
+ assert_eq!(h.state().ui.theme, theme, "the fixture renders the requested theme");
+ assert!(h.query_by_label("1920 px x 1080 px (72 ppi)").is_some());
+ h.state_mut().run("prefs.set", json!({"path": "unitsAndRulers.rulers", "value": "inches"})).unwrap();
+ h.run_steps(4);
+ if h.query_by_label("26.667 in x 15 in (72 ppi)").is_none() || h.query_by_label("1920 px x 1080 px (72 ppi)").is_some() {
+ failures.push(format!("{theme:?}, width={width}: inches"));
+ }
+ h.state_mut().run("prefs.set", json!({"path": "unitsAndRulers.rulers", "value": "cm"})).unwrap();
+ h.run_steps(4);
+ if h.query_by_label("67.73 cm x 38.1 cm (72 ppi)").is_none() {
+ failures.push(format!("{theme:?}, width={width}: centimeters"));
+ }
+ }
+ }
+ assert!(failures.is_empty(), "the status bar must follow the preference immediately: {failures:?}");
+ }
+
#[test]
fn status_profile_describes_rgb_gray_and_custom_profiles_without_mutating_the_document() {
let mut rgb = doc();
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 80b7a8975..089c1defb 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1767,6 +1767,7 @@
Invalid {mode} profile Neplatný profil {mode}
Unnamed {mode} profile Bezejmenný profil {mode}
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Rozlišení: {dpi} pixelů/palec
Doc: {w} × {h} px Dok.: {w} × {h} px
Frame {current} / {total} Snímek {current} / {total}
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 0ac393103..0093e5e80 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1740,6 +1740,7 @@
Invalid {mode} profile Ungültiges {mode}-Profil
Unnamed {mode} profile Unbenanntes {mode}-Profil
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Auflösung: {dpi} Pixel/Zoll
Doc: {w} × {h} px Dok: {w} × {h} px
Frame {current} / {total} Frame {current} / {total}
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index 4c71091ae..2febabd35 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3342,6 +3342,7 @@ cameraRaw Yellow Κίτρινο
open source ανοιχτού κώδικα
{size} (was {old}) {size} (ήταν {old})
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
…and {n} more …και {n} ακόμη
125% 125%
150% 150%
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index b8466f507..2ffa67738 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -1750,6 +1750,7 @@
Invalid {mode} profile Perfil {mode} no válido
Unnamed {mode} profile Perfil {mode} sin nombre
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Resolución: {dpi} píxeles/pulgada
Doc: {w} × {h} px Doc: {w} × {h} px
Frame {current} / {total} Fotograma {current} / {total}
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 34e0a3eb9..8d45285e2 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -1725,6 +1725,7 @@
Scratch: {size} Travail : {size}
Untagged {mode} {mode} sans profil
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppp)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppp)
Resolution: {dpi} pixels/inch Résolution : {dpi} pixels/pouce
Doc: {w} × {h} px Doc : {w} × {h} px
Frame {current} / {total} Image {current} / {total}
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index 28199e299..f1f2141f6 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -1719,6 +1719,7 @@
Scratch: {size} Scratch: {size}
Untagged {mode} {mode} Tanpa Tag
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Resolusi: {dpi} piksel/inci
Doc: {w} × {h} px Dok: {w} × {h} px
Frame {current} / {total} Frame {current} / {total}
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 10a483984..d44966a43 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -1748,6 +1748,7 @@
Invalid {mode} profile Profilo {mode} non valido
Unnamed {mode} profile Profilo {mode} senza nome
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Risoluzione: {dpi} pixel/pollice
Doc: {w} × {h} px Doc: {w} × {h} px
Frame {current} / {total} Fotogramma {current} / {total}
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 3e7318741..956b3cdc6 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -1754,6 +1754,7 @@
Invalid {mode} profile 無効な {mode} プロファイル
Unnamed {mode} profile 名前のない {mode} プロファイル
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch 解像度: {dpi} ピクセル/インチ
Doc: {w} × {h} px ドキュメント: {w} × {h} px
Frame {current} / {total} フレーム {current} / {total}
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 5d45ef534..d6f92a35a 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1717,6 +1717,7 @@
Scratch: {size} 스크래치: {size}
Untagged {mode} 프로파일 없는 {mode}
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch 해상도: {dpi}픽셀/인치
Doc: {w} × {h} px 문서: {w} × {h} px
Frame {current} / {total} 프레임 {current} / {total}
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index aef8f7451..02d8fd372 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -1731,6 +1731,7 @@
Invalid {mode} profile Ongeldig {mode}-profiel
Unnamed {mode} profile Naamloos {mode}-profiel
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Resolutie: {dpi} pixels/inch
Doc: {w} × {h} px Doc: {w} × {h} px
Frame {current} / {total} Frame {current} / {total}
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index a40977248..250d990aa 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -1747,6 +1747,7 @@
Invalid {mode} profile Nieprawidłowy profil {mode}
Unnamed {mode} profile Profil {mode} bez nazwy
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Rozdzielczość: {dpi} pikseli/cal
Doc: {w} × {h} px Dok.: {w} × {h} px
Frame {current} / {total} Klatka {current} / {total}
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 8beedbbdd..898fa4069 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -1724,6 +1724,7 @@
Scratch: {size} Trabalho: {size}
Untagged {mode} {mode} sem marcação
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch Resolução: {dpi} pixels/polegada
Doc: {w} × {h} px Doc: {w} × {h} px
Frame {current} / {total} Quadro {current} / {total}
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index e1e26696c..e5213edf1 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -647,6 +647,7 @@
Resolution: Разрешение:
Resolution: {dpi} pixels/inch Разрешение: {dpi} пикс./дюйм
{w} px x {h} px ({ppi} ppi) {w} px × {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} × {h} {unit} ({ppi} ppi)
Pixels: Пикселы:
Pixel Length: Длина в пикселах:
Logical Length: Логическая длина:
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 175dd7b3a..d1a88b326 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -627,6 +627,7 @@
Resolution: Роздільність:
Resolution: {dpi} pixels/inch Роздільність: {dpi} пікселів/дюйм
{w} px x {h} px ({ppi} ppi) {w} пкс x {h} пкс ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Pixels: Пікселі:
Pixel Length: Довжина в пікселях:
Logical Length: Логічна довжина:
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 3d5bd4f2b..cc97f3749 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1763,6 +1763,7 @@
Invalid {mode} profile 无效的 {mode} 配置文件
Unnamed {mode} profile 未命名的 {mode} 配置文件
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch 分辨率:{dpi} 像素/英寸
Doc: {w} × {h} px 文档:{w} × {h} px
Frame {current} / {total} 帧 {current} / {total}
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 274a06ea1..c85006bbd 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1755,6 +1755,7 @@
Invalid {mode} profile 無效的 {mode} 描述檔
Unnamed {mode} profile 未命名的 {mode} 描述檔
{w} px x {h} px ({ppi} ppi) {w} px x {h} px ({ppi} ppi)
+ {w} {unit} x {h} {unit} ({ppi} ppi) {w} {unit} x {h} {unit} ({ppi} ppi)
Resolution: {dpi} pixels/inch 解析度:{dpi} 像素/英吋
Doc: {w} × {h} px 文件:{w} × {h} px
Frame {current} / {total} 影格 {current} / {total}
diff --git a/docs/ui-design.md b/docs/ui-design.md
index 46fc6a344..f4a8ac19a 100644
--- a/docs/ui-design.md
+++ b/docs/ui-design.md
@@ -82,6 +82,11 @@ The app's top bar (`panels::title_bar`) starts with the brand mark (the app icon
## Menus
+The Pro status bar's Document Dimensions readout follows Preferences › Units & Rulers › Rulers,
+including changes made from a ruler's context menu. It uses the document resolution for physical
+units, each side's own extent for percentages and the selected point-size convention for points
+and picas. The readout retains the document's pixels-per-inch value.
+
`menu_catalog.rs` holds Photoshop's menu tree (standard command names, order, separators, default shortcuts). Items whose id matches an engine or UI command are live; others render disabled until implemented. Give new commands the catalogue's id (for example `image.imageSize`) and they light up in the right place automatically.
Menus never run off the window: the menu bar's menus and submenus scroll with arrows (`menu_nav::level`), and long right-click menus (Layers, canvas tools, Channels, Paths, document tabs) wrap their rows in `widgets::menu_scroll`, so they move up to fit and scroll only when taller than the visible window.