Skip to content

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

Paragraph panel: grey the justify buttons on point text (#7713)

Hector Villarrealc8907e2cd280
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rs
index d07b8bb16..bb4780d5e 100644
--- a/crates/ui-egui/src/type_tool.rs
+++ b/crates/ui-egui/src/type_tool.rs
@@ -2057,9 +2057,20 @@ fn toggle_cell(ui: &mut egui::Ui, w: f32, on: bool, tip: &str, paint: impl FnOnc
if on {
ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.0, t.accent_border), egui::StrokeKind::Inside);
}
- paint(ui, r, if on { t.text } else { t.text_dim });
+ let enabled = ui.is_enabled();
+ paint(
+ ui,
+ r,
+ if !enabled {
+ t.text_faint
+ } else if on {
+ t.text
+ } else {
+ t.text_dim
+ },
+ );
let tip = tip.to_string();
- resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, on, &tip));
+ resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, enabled, on, &tip));
resp.on_hover_text(tl!(&tip)).clicked()
}
@@ -2352,14 +2363,23 @@ fn type_sections(app: &mut PhotocraftApp, ui: &mut egui::Ui, character: bool, pa
("justifyAll", tl!("Justify all"), A::JustifyAll),
];
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());
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 2.0;
for (key, tip, a) in items {
- let clicked = toggle_cell(ui, cw, para.align == a, tip, |ui, r, col| {
- // The glyph keeps its size; the cell grows around it.
- let g = egui::Rect::from_center_size(r.center(), egui::vec2(12.0, 10.0));
- align_glyph(ui.painter(), g, a, if para.align == a { col } else { t.icon });
- });
+ let justify = !matches!(a, A::Left | A::Center | A::Right);
+ let clicked = ui
+ .add_enabled_ui(!(point && justify), |ui| {
+ toggle_cell(ui, cw, para.align == a, tip, |ui, r, col| {
+ // The glyph keeps its size; the cell grows around it.
+ let g = egui::Rect::from_center_size(r.center(), egui::vec2(12.0, 10.0));
+ let col = if !ui.is_enabled() || para.align == a { col } else { t.icon };
+ align_glyph(ui.painter(), g, a, col);
+ })
+ })
+ .inner;
if clicked {
apply(app, ui.ctx(), json!({"align": key}));
}
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rs
index 20e59a01d..368a725ac 100644
--- a/crates/ui-egui/src/type_tool_tests.rs
+++ b/crates/ui-egui/src/type_tool_tests.rs
@@ -2130,3 +2130,33 @@ fn type_mask_shift_adds_and_alt_subtracts_without_a_layer_row() {
assert!(at(&app, stem.0, stem.1) < 0.01, "⌥ subtracts the glyphs");
assert!(at(&app, 1050, 150) > 0.99, "and keeps the rest");
}
+
+/// #7713: justification needs a paragraph box. On point text the Paragraph panel's four justify
+/// buttons are greyed, as in Photoshop; on paragraph text they work.
+#[test]
+fn justify_buttons_are_greyed_on_point_text() {
+ use egui_kittest::kittest::{NodeT, Queryable};
+ let justify = ["Justify last left", "Justify last centered", "Justify last right", "Justify all"];
+ for (paragraph, enabled) in [(false, false), (true, true)] {
+ let mut app = new_app();
+ let mut p = json!({"text": "one two three four", "size": 24, "x": 300, "y": 420});
+ if paragraph {
+ p["box"] = json!([300, 300, 240, 180]);
+ }
+ app.run("type.create", p).unwrap();
+ 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);
+ for tip in justify {
+ assert_eq!(!h.get_by_label(tip).accesskit_node().is_disabled(), enabled, "{tip} on {}", if paragraph { "paragraph text" } else { "point text" });
+ }
+ assert!(!h.get_by_label("Center text").accesskit_node().is_disabled(), "alignment itself stays available");
+ }
+}