Skip to content

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

Justify buttons: grey when any formatted type layer is point text

Hector Villarrealb862323a8e1a
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rs
index bb4780d5e..441048c0a 100644
--- a/crates/ui-egui/src/type_tool.rs
+++ b/crates/ui-egui/src/type_tool.rs
@@ -2365,7 +2365,16 @@ fn type_sections(app: &mut PhotocraftApp, ui: &mut egui::Ui, character: bool, pa
let cw = cell_width(full, items.len());
// Justification needs a paragraph box: on point text Photoshop greys the four justify
// buttons (#7713).
- let point = target(app).is_some_and(|(layer, _)| box_shape(app, LayerId(layer)).is_none());
+ // The panel formats the layer being typed in, else every selected type layer.
+ let point = match formatting_params(app) {
+ Some(p) => p.get("layers").and_then(serde_json::Value::as_array).map_or_else(
+ || p.get("layer").and_then(serde_json::Value::as_u64).into_iter().collect::<Vec<_>>(),
+ |ids| ids.iter().filter_map(serde_json::Value::as_u64).collect(),
+ ),
+ None => Vec::new(),
+ }
+ .into_iter()
+ .any(|layer| box_shape(app, LayerId(layer)).is_none());
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 2.0;
for (key, tip, a) in items {
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rs
index 368a725ac..168409760 100644
--- a/crates/ui-egui/src/type_tool_tests.rs
+++ b/crates/ui-egui/src/type_tool_tests.rs
@@ -2159,4 +2159,23 @@ fn justify_buttons_are_greyed_on_point_text() {
}
assert!(!h.get_by_label("Center text").accesskit_node().is_disabled(), "alignment itself stays available");
}
+ // A selection of a paragraph and a point type layer formats both: justify is greyed.
+ let mut app = new_app();
+ let point = app.run("type.create", json!({"text": "point", "size": 24, "x": 300, "y": 420})).unwrap()["layer"].as_u64().unwrap();
+ let boxed =
+ app.run("type.create", json!({"text": "boxed text", "size": 24, "x": 300, "y": 300, "box": [300, 300, 240, 180]})).unwrap()["layer"].as_u64().unwrap();
+ app.run("layer.select", json!({"layer": point})).unwrap();
+ app.run("layer.select", json!({"layer": boxed, "mode": "add"})).unwrap();
+ assert_eq!(app.session.active().unwrap().selected_layers().len(), 2);
+ let mut h = Harness::builder().with_size(vec2(320.0, 700.0)).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ crate::type_tool::character_panel(app, ui, true);
+ }
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run_steps(4);
+ assert!(h.get_by_label("Justify all").accesskit_node().is_disabled(), "one of the formatted layers is point text");
}