PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Clarify integer and float bit-depth labels (#324) (#428)
Alex Gorevski50d52a084897
diff --git a/crates/ui-egui/src/doc_props_ui.rs b/crates/ui-egui/src/doc_props_ui.rsindex 8a28a2dac..544ce7cf3 100644--- a/crates/ui-egui/src/doc_props_ui.rs+++ b/crates/ui-egui/src/doc_props_ui.rs@@ -190,8 +190,9 @@ pub fn properties(app: &mut PhotocraftApp, ui: &mut egui::Ui) {ui.horizontal(|ui| {ui.add_space(label_w + 8.0);let mut d = depth;- let opts: Vec<(SampleType, &str)> = DEPTHS.iter().map(|(d, l, _)| (*d, *l)).collect();- if widgets::dropdown(ui, "doc-props-depth", &mut d, &opts, 150.0)+ let opts: Vec<(SampleType, &str, &str)> =+ DEPTHS.iter().map(|(d, l, _)| (*d, *l, if *d == SampleType::F32 { "Floating point" } else { "Integer" })).collect();+ if widgets::dropdown_with_tooltips(ui, "doc-props-depth", &mut d, &opts, 150.0)&& let Some((_, _, id)) = DEPTHS.iter().find(|(x, _, _)| *x == d){run.push(((*id).to_string(), Value::Null));@@ -315,4 +316,17 @@ mod tests {assert!(photocraft_engine::commands::find(id).is_some(), "{id} is not an engine command");}}++ #[test]+ fn image_mode_depth_labels_match_sample_types_and_are_translated() {+ assert_eq!(+ DEPTHS.iter().map(|(sample, label, _)| (*sample, *label)).collect::<Vec<_>>(),+ [(SampleType::U8, "8 Bits/Channel"), (SampleType::U16, "16 Bits/Channel"), (SampleType::F32, "32 Bits/Channel"),]+ );+ for lang in crate::i18n::Lang::all().filter(|lang| lang.code() != "en") {+ for (_, label, id) in DEPTHS {+ assert_ne!(crate::i18n::tr_id(lang, id, label), *label, "{}: {label}", lang.code());+ }+ }+ }}diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 7f3fe278c..f2307f69e 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -181,8 +181,13 @@Lab Color Barvy LabMultichannel Vícekanálový8 Bits/Channel 8 bitů/kanál+ 8 bit 8 bitů+ Integer Celé číslo16 Bits/Channel 16 bitů/kanál+ 16 bit 16 bitů32 Bits/Channel 32 bitů/kanál+ 32 bit (float) 32 bitů (float)+ Floating point Číslo s plovoucí desetinnou čárkouColor Table… Tabulka barev…Bitmap… Bitmapa…Duotone… Dvoutón…diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 8e399e4b3..9a08d45a8 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -173,8 +173,13 @@Lab Color Color LabMultichannel Multicanal8 Bits/Channel 8 bits/canal+ 8 bit 8 bits+ Integer Entero16 Bits/Channel 16 bits/canal+ 16 bit 16 bits32 Bits/Channel 32 bits/canal+ 32 bit (float) 32 bits (float)+ Floating point Punto flotanteColor Table… Tabla de colores…Bitmap… Mapa de bits…Duotone… Duotono…diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 6ee1b67d0..7bfa5f8d0 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -177,8 +177,13 @@Lab Color Lab カラーMultichannel マルチチャンネル8 Bits/Channel 8 ビット/チャンネル+ 8 bit 8 ビット+ Integer 整数16 Bits/Channel 16 ビット/チャンネル+ 16 bit 16 ビット32 Bits/Channel 32 ビット/チャンネル+ 32 bit (float) 32 ビット(float)+ Floating point 浮動小数点Color Table… カラーテーブル…Bitmap… ビットマップ…Duotone… ダブルトーン…diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex f8beb7247..9755a5e0f 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -106,6 +106,11 @@16 Bits/Channel 16 бит/канал32 Bits/Channel 32 бита/канал8 Bits/Channel 8 бит/канал+ 8 bit 8 бит+ Integer Целое число+ 16 bit 16 бит+ 32 bit (float) 32 бит (float)+ Floating point С плавающей точкойMode РежимGrayscale Градации серогоRGB Color RGBdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 181f71d6e..021d78e69 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -175,8 +175,13 @@Lab Color Lab 颜色Multichannel 多通道8 Bits/Channel 8 位/通道+ 8 bit 8 位+ Integer 整数16 Bits/Channel 16 位/通道+ 16 bit 16 位32 Bits/Channel 32 位/通道+ 32 bit (float) 32 位(浮点)+ Floating point 浮点数Color Table… 颜色表…Bitmap… 位图…Duotone… 双色调…diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex a6198321e..caa7fa654 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -181,8 +181,13 @@Lab Color Lab 色彩Multichannel 多重色版8 Bits/Channel 8 位元/色版+ 8 bit 8 位元+ Integer 整數16 Bits/Channel 16 位元/色版+ 16 bit 16 位元32 Bits/Channel 32 位元/色版+ 32 bit (float) 32 位元(浮點)+ Floating point 浮點數Color Table… 色彩表…Bitmap… 點陣圖…Duotone… 雙色調…diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex d4dd34e02..d8381d75f 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -844,6 +844,11 @@ fn render_level_rows(ui: &mut egui::Ui, items: &[&MenuItem], depth: usize, click}let hit = nav.row(ui, depth - 1, it.enabled, Some(&it.id), |ui, _| {let r = ui.add_enabled(it.enabled, b);+ let r = match it.id.as_str() {+ "image.mode.bits8" | "image.mode.bits16" => r.on_hover_text(crate::i18n::tr(lang, "Integer")),+ "image.mode.bits32" => r.on_hover_text(crate::i18n::tr(lang, "Floating point")),+ _ => r,+ };let hit = r.clicked();(r, hit)});diff --git a/crates/ui-egui/src/new_doc_ui.rs b/crates/ui-egui/src/new_doc_ui.rsindex a2cf04978..d30cb5ea1 100644--- a/crates/ui-egui/src/new_doc_ui.rs+++ b/crates/ui-egui/src/new_doc_ui.rs@@ -73,6 +73,8 @@ pub const CATEGORIES: &[(&str, &[Preset])] = &[),];+const DEPTH_OPTIONS: &[(u64, &str, &str)] = &[(8, "8 bit", "Integer"), (16, "16 bit", "Integer"), (32, "32 bit (float)", "Floating point")];+/// Width/Height units: (key, label, units per inch; 0 = pixels).pub const UNITS: &[(&str, &str, f32)] =&[("px", "Pixels", 0.0), ("in", "Inches", 1.0), ("cm", "Centimeters", 2.54), ("mm", "Millimeters", 25.4), ("pt", "Points", 72.0), ("pica", "Picas", 6.0)];@@ -280,7 +282,8 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {f.insert("mode".into(), json!(mode));}let mut depth = f.get("depth").and_then(Value::as_u64).unwrap_or(8);- if widgets::dropdown(ui, "nd-depth", &mut depth, &[(8u64, "8 bit"), (16, "16 bit"), (32, "32 bit")], 120.0) {+ let depth_options: Vec<(u64, &str, &str)> = DEPTH_OPTIONS.iter().map(|(bits, label, tooltip)| (*bits, *label, *tooltip)).collect();+ if widgets::dropdown_with_tooltips(ui, "nd-depth", &mut depth, &depth_options, 120.0) {f.insert("depth".into(), json!(depth));}});@@ -312,6 +315,16 @@ mod tests {assert_eq!(to_unit(640.0, "px", 72.0), 640.0);}+ #[test]+ fn new_document_depth_labels_and_tooltips_are_translated() {+ for lang in crate::i18n::Lang::all().filter(|lang| lang.code() != "en") {+ for (_, label, tooltip) in DEPTH_OPTIONS {+ assert_ne!(crate::i18n::tr(lang, label), *label, "{}: {label}", lang.code());+ assert_ne!(crate::i18n::tr(lang, tooltip), *tooltip, "{}: {tooltip}", lang.code());+ }+ }+ }+#[test]fn preset_sets_size_resolution_and_create_params_drop_ui_keys() {let mut f = crate::state::UiState::new_document_fields();diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 8644833d1..b8fba1dae 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -417,6 +417,23 @@ pub fn swatch_popup(swatch: &Response) -> egui::Popup<'static> {.align_alternatives(&[egui::RectAlign::TOP_START])}+pub fn dropdown_with_tooltips<T: PartialEq + Clone>(ui: &mut Ui, id: &str, current: &mut T, options: &[(T, &str, &str)], width: f32) -> bool {+ let label = options.iter().find(|(v, _, _)| v == current).map(|(_, l, _)| tl!(l)).unwrap_or("—");+ let mut changed = false;+ let response = egui::ComboBox::from_id_salt(id).selected_text(label).width(width).height(420.0).icon(chevron_icon).show_ui(ui, |ui| {+ for (v, l, tip) in options {+ if ui.selectable_label(v == current, tl!(l)).on_hover_text(tl!(tip)).clicked() {+ *current = v.clone();+ changed = true;+ }+ }+ });+ if let Some((_, _, tip)) = options.iter().find(|(v, _, _)| v == current) {+ let _ = response.response.on_hover_text(tl!(tip));+ }+ changed+}+/// Paint a small checkerboard (transparency) in `rect`.pub fn checker(painter: &egui::Painter, rect: Rect, cell: f32) {painter.rect_filled(rect, 0.0, Color32::from_gray(250));