PhotoCraft: An open-source, photo editor written by scratch in pure Rust
feat(ui): edit independent rectangle corner radii with narrow-panel controls and history tests
Nigel Ihza Firdausyd80455ad25fe
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex eca6a939f..6c5d8477d 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -25,6 +25,10 @@Layer VrstvaType TextSelect Výběr+ Top Left Vlevo nahoře+ Top Right Vpravo nahoře+ Bottom Left Vlevo dole+ Bottom Right Vpravo doleFilter FiltrView ZobrazeníWindow Oknodiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 400dd0c58..8aa8d9cc2 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -21,6 +21,10 @@Layer EbeneType TextSelect Auswahl+ Top Left Oben links+ Top Right Oben rechts+ Bottom Left Unten links+ Bottom Right Unten rechtsFilter FilterView AnsichtWindow Fensterdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex f967e48aa..7d3064a28 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -17,6 +17,10 @@Layer CapaType TextoSelect Selección+ Top Left Superior izquierda+ Top Right Superior derecha+ Bottom Left Inferior izquierda+ Bottom Right Inferior derechaFilter FiltroView VerWindow Ventanadiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 7fb027b23..13943838d 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -24,6 +24,10 @@Layer CalqueType TexteSelect Sélection+ Top Left En haut à gauche+ Top Right En haut à droite+ Bottom Left En bas à gauche+ Bottom Right En bas à droiteFilter FiltreView AffichageWindow Fenêtrediff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 5b76c883d..7c2360299 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -17,6 +17,10 @@Layer LayerType TeksSelect Seleksi+ Top Left Kiri atas+ Top Right Kanan atas+ Bottom Left Kiri bawah+ Bottom Right Kanan bawahFilter FilterView TampilanWindow Jendeladiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 4cfaf759d..0f2e2fd59 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -17,6 +17,10 @@Layer LivelloType TestoSelect Selezione+ Top Left In alto a sinistra+ Top Right In alto a destra+ Bottom Left In basso a sinistra+ Bottom Right In basso a destraFilter FiltroView VistaWindow Finestradiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 54680ac27..bdd0c3de7 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -21,6 +21,10 @@Layer レイヤーType 文字Select 選択+ Top Left 左上+ Top Right 右上+ Bottom Left 左下+ Bottom Right 右下Filter フィルターView 表示Window ウィンドウdiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 03d210529..9848a2d36 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -21,6 +21,10 @@Layer CamadaType TipoSelect Selecionar+ Top Left Superior esquerdo+ Top Right Superior direito+ Bottom Left Inferior esquerdo+ Bottom Right Inferior direitoFilter FiltroView VisualizarWindow Janeladiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex c43191e1d..7713eb62f 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -24,6 +24,10 @@Layer СлойType ТекстSelect Выделение+ Top Left Верхний левый+ Top Right Верхний правый+ Bottom Left Нижний левый+ Bottom Right Нижний правыйFilter ФильтрView ПросмотрWindow Окноdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 8d5be1c4a..aa19a3fbb 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -17,6 +17,10 @@Layer 图层Type 文字Select 选择+ Top Left 左上+ Top Right 右上+ Bottom Left 左下+ Bottom Right 右下Filter 滤镜View 视图Window 窗口diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 0285902e9..14ce30e30 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -25,6 +25,10 @@Layer 圖層Type 文字Select 選取+ Top Left 左上+ Top Right 右上+ Bottom Left 左下+ Bottom Right 右下Filter 濾鏡View 檢視Window 視窗diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rsindex 05fe4ce23..af81862e5 100644--- a/crates/ui-egui/src/vector_ui.rs+++ b/crates/ui-egui/src/vector_ui.rs@@ -602,6 +602,16 @@ fn swatch(ui: &mut egui::Ui, fill: Option<&photocraft_doc::Fill>, tip: &str) ->out}+/// One corner of the live rectangle, preserving the other three radii.+/// The engine takes the full [top-left, top-right, bottom-right, bottom-left] array.+fn corner_radii_patch(radii: [f64; 4], corner: usize, radius: f32) -> Value {+ let mut next = radii;+ if let Some(r) = next.get_mut(corner) {+ *r = f64::from(radius.max(0.0));+ }+ json!({"radii": next})+}+/// Properties panel for a shape layer: Appearance (fill, stroke) and live shape geometry.pub fn shape_properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: photocraft_doc::LayerId) {let Some(sh) = app.session.active().and_then(|s| s.doc.layer(id)).and_then(|l| match &l.content {@@ -669,28 +679,49 @@ pub fn shape_properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: photocra}photocraft_doc::vector::LiveShape::Line { .. } => {}}- ui.horizontal(|ui| match live {+ ui.vertical(|ui| match live {photocraft_doc::vector::LiveShape::Rect { radii, .. } => {- let mut r = radii[0] as f32;- if num(ui, tl!("Corner radius"), &mut r, 0.0..=100000.0, "px") {- edit = Some(json!({"radii": r, "coalesce": key("radius")}));+ // Keep the uniform workflow available after independent corner edits too.+ ui.horizontal(|ui| {+ let mut all = radii[0] as f32;+ if num(ui, tl!("Corner radius"), &mut all, 0.0..=100000.0, "px") {+ edit = Some(json!({"radii": all, "coalesce": key("radius-all")}));+ }+ });+ // Separate rows also fit the narrow Properties dock. The labels use the+ // localized corner names, rather than untranslated abbreviations.+ for (index, label) in [(0, tl!("Top Left")), (1, tl!("Top Right")), (3, tl!("Bottom Left")), (2, tl!("Bottom Right"))] {+ ui.horizontal(|ui| {+ let mut radius = radii[index] as f32;+ if num(ui, label, &mut radius, 0.0..=100000.0, "px") {+ let mut patch = corner_radii_patch(*radii, index, radius);+ patch["coalesce"] = json!(key(&format!("radius-{index}")));+ edit = Some(patch);+ }+ });}}photocraft_doc::vector::LiveShape::Polygon { sides, star_ratio, .. } => {- let mut n = *sides as f32;- if num(ui, tl!("Sides"), &mut n, 3.0..=100.0, "") {- edit = Some(json!({"sides": n.round() as u32, "coalesce": key("sides")}));- }- let mut sr = (*star_ratio * 100.0) as f32;- if num(ui, tl!("Star ratio"), &mut sr, 1.0..=100.0, "%") {- edit = Some(json!({"starRatio": sr as f64 / 100.0, "coalesce": key("star")}));- }+ ui.horizontal(|ui| {+ let mut n = *sides as f32;+ if num(ui, tl!("Sides"), &mut n, 3.0..=100.0, "") {+ edit = Some(json!({"sides": n.round() as u32, "coalesce": key("sides")}));+ }+ let mut sr = (*star_ratio * 100.0) as f32;+ if num(ui, tl!("Star ratio"), &mut sr, 1.0..=100.0, "%") {+ edit = Some(json!({"starRatio": sr as f64 / 100.0, "coalesce": key("star")}));+ }+ })+ .inner}photocraft_doc::vector::LiveShape::Line { weight, .. } => {- let mut w = *weight as f32;- if num(ui, tl!("Weight"), &mut w, 1.0..=10000.0, "px") {- edit = Some(json!({"weight": w, "coalesce": key("weight")}));- }+ ui.horizontal(|ui| {+ let mut w = *weight as f32;+ if num(ui, tl!("Weight"), &mut w, 1.0..=10000.0, "px") {+ edit = Some(json!({"weight": w, "coalesce": key("weight")}));+ }+ })+ .inner}_ => {}});@@ -1200,6 +1231,51 @@ mod tests {assert!(!legacy.dragging && !legacy.adjusting_last);}+ /// #1520: changing one corner through the Properties command must keep the other three+ /// independent, remain a live rectangle, and undo/redo as one geometry edit.+ #[test]+ fn live_rectangle_corner_radius_edit_preserves_other_corners_and_history() {+ let mut app = app();+ let created = app.run("shape.create", json!({"kind": "roundedRect", "rect": [10, 10, 150, 100], "radii": [5, 10, 15, 20]})).unwrap();+ let id = created["layer"].as_u64().unwrap();+ let get_radii = |app: &PhotocraftApp| {+ let st = app.session.active().unwrap();+ let shape = st.doc.layer(photocraft_doc::LayerId(id)).unwrap();+ match &shape.content {+ LayerContent::Shape(sh) => match &sh.live {+ Some(photocraft_doc::vector::LiveShape::Rect { radii, .. }) => *radii,+ _ => panic!("rectangle must remain a live shape"),+ },+ _ => panic!("expected shape layer"),+ }+ };+ assert_eq!(get_radii(&app), [5.0, 10.0, 15.0, 20.0]);+ let mut patch = corner_radii_patch(get_radii(&app), 1, 30.0);+ patch["layer"] = json!(id);+ app.run("shape.edit", patch).unwrap();+ assert_eq!(get_radii(&app), [5.0, 30.0, 15.0, 20.0]);+ app.run("edit.undo", json!({})).unwrap();+ assert_eq!(get_radii(&app), [5.0, 10.0, 15.0, 20.0]);+ app.run("edit.redo", json!({})).unwrap();+ assert_eq!(get_radii(&app), [5.0, 30.0, 15.0, 20.0]);+ for corner in 0..4 {+ let before = get_radii(&app);+ let radius = 35.0 + corner as f32;+ let mut expected = before;+ expected[corner] = f64::from(radius);+ let mut patch = corner_radii_patch(before, corner, radius);+ patch["layer"] = json!(id);+ app.run("shape.edit", patch).unwrap();+ assert_eq!(get_radii(&app), expected);+ app.run("edit.undo", json!({})).unwrap();+ assert_eq!(get_radii(&app), before);+ app.run("edit.redo", json!({})).unwrap();+ assert_eq!(get_radii(&app), expected);+ }+ app.run("shape.edit", json!({"layer": id, "radii": 12})).unwrap();+ assert_eq!(get_radii(&app), [12.0; 4]);+ }+/// #534: dragging in a shape's fill picker, opened from the Properties panel at the right edge/// of the window, keeps the picker in place (it flipped from side to side as its width/// followed the colour readouts, which moved it under the pointer).