PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Options bar: the airbrush, smoothing options and symmetry buttons work (#1177) (#1214)
Chris Waldenacddca58b86e
diff --git a/crates/ui-egui/src/brush_panel_tests.rs b/crates/ui-egui/src/brush_panel_tests.rsindex 4c3244514..7c58ff842 100644--- a/crates/ui-egui/src/brush_panel_tests.rs+++ b/crates/ui-egui/src/brush_panel_tests.rs@@ -286,6 +286,56 @@ fn options_bar_edits_are_one_set_brush_per_gesture() {assert_eq!(s.tools.brush, h.state().session.tools.brush);}+#[test]+fn airbrush_smoothing_options_and_symmetry_buttons_work() {+ // #1177: in the default (Photoshop) theme these options-bar buttons did nothing.+ use egui_kittest::kittest::Queryable;+ let mut h = app_harness();+ let brush = |h: &Harness<'static, PhotocraftApp>| h.state().session.tools.brush.clone();++ // The airbrush toggles Build-up, one setBrush each click.+ let was = brush(&h).build_up;+ h.get_by_label("Enable airbrush-style build-up effects").click();+ h.run_steps(3);+ assert_eq!(brush(&h).build_up, !was);+ let (id, p) = last_journal(h.state()).unwrap();+ assert_eq!((id.as_str(), &p["brush"]), ("tools.setBrush", &json!({"buildUp": !was})));++ // The gear opens Photoshop's four smoothing options, each editing the brush.+ assert!(h.query_by_label("Pulled String Mode").is_none());+ h.get_by_label("Set additional smoothing options").click();+ h.run_steps(3);+ let before = brush(&h).smoothing;+ for label in ["Pulled String Mode", "Stroke Catch-up", "Catch-up on Stroke End", "Adjust for Zoom"] {+ h.get_by_label(label).click();+ h.run_steps(3);+ }+ let after = brush(&h).smoothing;+ assert_eq!(+ (after.pulled_string, after.catch_up, after.catch_up_on_end, after.adjust_for_zoom),+ (!before.pulled_string, !before.catch_up, !before.catch_up_on_end, !before.adjust_for_zoom)+ );+ assert_eq!(after.amount, before.amount);++ // Symmetry: the menu lists the document's paths and turns symmetry on and off.+ h.state_mut().run("file.new", json!({"width": 80, "height": 60})).unwrap();+ h.state_mut().run("path.set", json!({"name": "work", "path": {"subpaths": [{"closed": false, "knots": [[40, 0], [40, 60]]}]}})).unwrap();+ h.run_steps(3);+ h.get_by_label("Set painting symmetry options").click();+ h.run_steps(3);+ h.get_by_label("Work Path").click();+ h.run_steps(3);+ let source = |h: &Harness<'static, PhotocraftApp>| h.state().session.active().unwrap().symmetry_path.as_ref().map(|a| a.source.clone());+ assert_eq!(source(&h).as_deref(), Some("work"));+ assert_eq!(last_journal(h.state()).unwrap(), ("paint.symmetryFromPath".to_string(), json!({"name": "work"})));+ h.get_by_label("Set painting symmetry options").click();+ h.run_steps(3);+ h.get_by_label("Symmetry Off").click();+ h.run_steps(3);+ assert_eq!(source(&h), None);+ assert!(h.state().ui.status.is_empty(), "{}", h.state().ui.status);+}+#[test]fn mixer_brush_options_update_the_persisted_mixer_settings() {use egui_kittest::kittest::Queryable;diff --git a/crates/ui-egui/src/brush_picker.rs b/crates/ui-egui/src/brush_picker.rsindex cb4a22803..166a5bbbb 100644--- a/crates/ui-egui/src/brush_picker.rs+++ b/crates/ui-egui/src/brush_picker.rs@@ -81,7 +81,7 @@ pub fn settings_toggle(app: &mut PhotocraftApp, ui: &mut egui::Ui) {}/// An icon button's accessible name (icon buttons have only a tooltip).-fn named(resp: egui::Response, label: &str) -> egui::Response {+pub(crate) fn named(resp: egui::Response, label: &str) -> egui::Response {resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, label));resp}diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 3715ee5de..8e1490eef 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -1357,6 +1357,7 @@Set background color Nastavit barvu pozadíSet foreground color Nastavit barvu popředíSet painting symmetry options Nastavit možnosti symetrie malby+ Symmetry Off Symetrie vypnutaSet shape fill type Nastavit typ výplně tvaruSet shape stroke type Nastavit typ tahu tvaruSet the text color Nastavit barvu textudiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 6a7fbc227..707d381c9 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -1340,6 +1340,7 @@Set background color Hintergrundfarbe festlegenSet foreground color Vordergrundfarbe festlegenSet painting symmetry options Symmetrieoptionen für das Malen festlegen+ Symmetry Off Symmetrie ausSet shape fill type Fülltyp der Form festlegenSet shape stroke type Konturtyp der Form festlegenSet the text color Textfarbe festlegendiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 8ca4a2dee..96d7a7061 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -1342,6 +1342,7 @@Set background color Establecer el color de fondoSet foreground color Establecer el color frontalSet painting symmetry options Establecer opciones de simetría de pintura+ Symmetry Off Simetría desactivadaSet shape fill type Establecer el tipo de relleno de la formaSet shape stroke type Establecer el tipo de trazo de la formaSet the text color Establecer el color del textodiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 217652931..142fa35cd 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -1329,6 +1329,7 @@Set background color Définir la couleur d'arrière-planSet foreground color Définir la couleur de premier planSet painting symmetry options Définir les options de symétrie de peinture+ Symmetry Off Symétrie désactivéeSet shape fill type Définir le type de remplissage de la formeSet shape stroke type Définir le type de contour de la formeSet the text color Définir la couleur du textediff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex f9dd18379..7b51bfd1d 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -1323,6 +1323,7 @@Set background color Atur warna backgroundSet foreground color Atur warna foregroundSet painting symmetry options Atur opsi simetri lukisan+ Symmetry Off Simetri MatiSet shape fill type Atur jenis isian bentukSet shape stroke type Atur jenis stroke bentukSet the text color Atur warna teksdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex bdd3b0c44..e5af7eb23 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -1340,6 +1340,7 @@Set background color Imposta colore sfondoSet foreground color Imposta colore primo pianoSet painting symmetry options Imposta opzioni simmetria pittura+ Symmetry Off Simmetria disattivataSet shape fill type Imposta tipo riempimento formaSet shape stroke type Imposta tipo traccia formaSet the text color Imposta colore testodiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 58f6ad83c..4f1bc752b 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -1347,6 +1347,7 @@Set background color 背景色を設定Set foreground color 描画色を設定Set painting symmetry options 対称描画のオプションを設定+ Symmetry Off 対称オフSet shape fill type シェイプの塗りの種類を設定Set shape stroke type シェイプの線の種類を設定Set the text color 文字色を設定diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex 43c3280ee..e9901017f 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -1324,6 +1324,7 @@Set background color 배경색 설정Set foreground color 전경색 설정Set painting symmetry options 페인팅 대칭 옵션 설정+ Symmetry Off 대칭 끔Set shape fill type 모양 채우기 유형 설정Set shape stroke type 모양 획 유형 설정Set the text color 텍스트 색상 설정diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex cb7b78425..14ec627f6 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -1328,6 +1328,7 @@Set background color Definir cor de fundoSet foreground color Definir cor de primeiro planoSet painting symmetry options Definir opções de simetria de pintura+ Symmetry Off Simetria desativadaSet shape fill type Definir tipo de preenchimento da formaSet shape stroke type Definir tipo de traçado da formaSet the text color Definir a cor do textodiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 1527780be..4e3d244ad 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -1637,6 +1637,7 @@Measure ИзмеритьHeal ВосстановлениеOff Выкл+ Symmetry Off Без симметрииHeal Off Восстановление выклHeal On Восстановление вклHeal Auto Автовосстановлениеdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 8010e31db..bc468720b 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -1352,6 +1352,7 @@Set background color 设置背景色Set foreground color 设置前景色Set painting symmetry options 设置绘画对称选项+ Symmetry Off 关闭对称Set shape fill type 设置形状填充类型Set shape stroke type 设置形状描边类型Set the text color 设置文字颜色diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 326ad7024..a09392f71 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -1348,6 +1348,7 @@Set background color 設定背景色Set foreground color 設定前景色Set painting symmetry options 設定繪畫對稱選項+ Symmetry Off 關閉對稱Set shape fill type 設定形狀填滿類型Set shape stroke type 設定形狀筆畫類型Set the text color 設定文字顏色diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 236de6799..7b292f33a 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -522,15 +522,18 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {b.pressure_opacity = !b.pressure_opacity;}percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 62.0);- let _ = icons::button(ui, "sparkles", 24.0, false, tl!("Enable airbrush-style build-up effects"));+ let airbrush = icons::button(ui, "sparkles", 24.0, b.build_up, tl!("Enable airbrush-style build-up effects"));+ if crate::brush_picker::named(airbrush, tl!("Enable airbrush-style build-up effects")).clicked() {+ b.build_up = !b.build_up;+ }opt_label(ui, tl!("Smoothing"));smoothing_field(ui, b, 58.0);- let _ = icons::button(ui, "settings", 24.0, false, tl!("Set additional smoothing options"));+ smoothing_options(ui, b);widgets::vline(ui, 22.0);if icons::button(ui, "circle-dot", 24.0, b.pressure_size, tl!("Always use pressure for size")).clicked() {b.pressure_size = !b.pressure_size;}- let _ = icons::button(ui, "arrow-left-right", 24.0, false, tl!("Set painting symmetry options"));+ symmetry_menu(app, ui);}// Pencil: Photoshop's options (no hardness or flow: the pencil is always hard).Tool::Pencil => {@@ -2465,6 +2468,68 @@ fn smoothing_field(ui: &mut egui::Ui, b: &mut photocraft_engine::BrushSettings,}}+/// Options-bar gear beside Smoothing: Photoshop's smoothing options popup, edited on the brush+/// like the Smoothing % (so they stay per tool and reach the live stroke and the commit).+fn smoothing_options(ui: &mut egui::Ui, b: &mut photocraft_engine::BrushSettings) {+ let resp = icons::button(ui, "settings", 24.0, false, tl!("Set additional smoothing options"));+ let resp = crate::brush_picker::named(resp, tl!("Set additional smoothing options"));+ egui::Popup::from_toggle_button_response(&resp).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| {+ let s = &mut b.smoothing;+ widgets::checkbox(ui, &mut s.pulled_string, tl!("Pulled String Mode"));+ widgets::checkbox(ui, &mut s.catch_up, tl!("Stroke Catch-up"));+ widgets::checkbox(ui, &mut s.catch_up_on_end, tl!("Catch-up on Stroke End"));+ widgets::checkbox(ui, &mut s.adjust_for_zoom, tl!("Adjust for Zoom"));+ });+}++/// The symmetry menu's rows: `paint.symmetryFromPath` name and label for each path the Paths+/// panel lists (saved paths, the Work Path, the selected layer's shape path or vector mask).+fn symmetry_choices(app: &PhotocraftApp) -> Vec<(String, String)> {+ use crate::vector_ui::PathRow;+ let Some(st) = app.session.active() else { return Vec::new() };+ crate::vector_ui::path_rows(&st.doc, st.active_layer)+ .into_iter()+ .map(|row| match row.kind {+ PathRow::Saved => (row.name.clone(), row.name),+ PathRow::Work => ("work".to_string(), tl!("Work Path").to_string()),+ PathRow::Layer => ("layer".to_string(), row.name),+ })+ .collect()+}++/// Options-bar painting symmetry: Symmetry Off, or mirror Brush and Eraser strokes across one of+/// the document's paths (`paint.symmetryFromPath`). The button is lit while symmetry is on.+fn symmetry_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {+ let t = Tokens::get(ui.ctx());+ let current = app.session.active().and_then(|st| st.symmetry_path.as_ref()).map(|axis| axis.source.clone());+ let choices = symmetry_choices(app);+ let resp = icons::button(ui, "arrow-left-right", 24.0, current.is_some(), tl!("Set painting symmetry options"));+ let resp = crate::brush_picker::named(resp, tl!("Set painting symmetry options"));+ egui::Popup::menu(&resp).show(|ui| {+ ui.set_min_width(200.0);+ let mut run = None;+ if ui.add(egui::Button::selectable(current.is_none(), tl!("Symmetry Off"))).clicked() {+ run = current.is_some().then(|| ("paint.symmetryDisable", json!({})));+ ui.close();+ }+ ui.separator();+ if choices.is_empty() {+ ui.label(RichText::new(tl!("Draw with the Pen tool (P) or make a work path from a selection.")).color(t.text_faint));+ }+ for (name, label) in &choices {+ if ui.add(egui::Button::selectable(current.as_ref() == Some(name), label)).clicked() {+ run = Some(("paint.symmetryFromPath", json!({ "name": name })));+ ui.close();+ }+ }+ if let Some((id, params)) = run+ && let Err(e) = app.run(id, params)+ {+ app.ui.status = e;+ }+ });+}+/// Options-bar brush chip; opens Photoshop's Brush Preset picker (size, hardness, the preset/// library). Returns what the picker asked for beyond the size and hardness edits in `b`.fn brush_preset_chip(