Skip to content

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

Properties: a new adjustment or fill layer shows its settings, not its mask (#3369) (#3429)

David Manncee10331126f
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index fde3f0b2c..8937ea964 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -621,6 +621,7 @@ fn dispatch(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest)
}
if let Some(m) = mask_target {
app.ui.mask_target = m;
+ app.ui.properties_layer = None;
app.ui.vector_mask_target &= !m;
app.sync_mask_targets();
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 8e662d866..1290f089c 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -922,6 +922,9 @@ impl PhotocraftApp {
// Adding a layer mask targets it, as in Photoshop (#2166).
self.ui.mask_target = true;
self.ui.vector_mask_target = false;
+ // Properties still shows the new adjustment or fill layer's settings, not its mask,
+ // as in Photoshop (#3369): clicking the mask thumbnail switches it to the mask.
+ self.ui.properties_layer = if creates_adjustment_or_fill { self.session.active().and_then(|st| st.active_layer).map(|l| l.0) } else { None };
}
if r.is_ok() && id == "select.toWorkPath" {
// Make Work Path selects the new work path in the Paths panel, as in Photoshop.
@@ -1755,6 +1758,9 @@ impl PhotocraftApp {
if !self.ui.mask_target && st.channel_view.target == photocraft_engine::channel_cmds::ChannelTarget::LayerMask {
st.channel_view.target = photocraft_engine::channel_cmds::ChannelTarget::Composite;
}
+ if !self.ui.mask_target || self.ui.properties_layer != st.active_layer.map(|l| l.0) {
+ self.ui.properties_layer = None;
+ }
}
let mask = self.layer_mask_targeted();
self.session.tools.target_mask(mask);
diff --git a/crates/ui-egui/src/mask_props_ui.rs b/crates/ui-egui/src/mask_props_ui.rs
index 91a3f33bc..295310bf9 100644
--- a/crates/ui-egui/src/mask_props_ui.rs
+++ b/crates/ui-egui/src/mask_props_ui.rs
@@ -10,9 +10,10 @@ use crate::{PhotocraftApp, widgets};
/// Image › Adjustments › Invert, which inverts a targeted layer mask in place (#780).
const INVERT: &str = "image.adjustments.invert";
-/// The Layers panel targets the active layer's pixel mask (not its vector mask).
+/// The Layers panel targets the active layer's pixel mask (not its vector mask) and Properties
+/// shows it: a just-created adjustment or fill layer shows its own settings instead (#3369).
pub fn targeted(app: &PhotocraftApp, layer: &Layer) -> bool {
- app.ui.mask_target && !app.ui.vector_mask_target && layer.mask.is_some()
+ app.ui.mask_target && !app.ui.vector_mask_target && layer.mask.is_some() && app.ui.properties_layer != Some(layer.id.0)
}
/// The Layers panel targets the active layer's vector mask.
diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
index d6cebb379..58fb8687a 100644
--- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
@@ -603,3 +603,41 @@ fn selecting_mask_thumbnail_toggles_swatches_to_mask_colors_and_back() {
assert!(h.state().ui.mask_target, "new adjustment layer targets its mask");
assert_eq!(h.state().session.tools.foreground, grey);
}
+
+// #3369: a new adjustment or fill layer targets its mask, but Properties shows its settings
+// until the mask thumbnail is clicked, as in Photoshop.
+#[test]
+fn a_new_adjustment_or_fill_layer_shows_its_settings_until_the_mask_thumbnail_is_clicked() {
+ for (command, settings) in [("layer.newAdjustmentLayer.curves", Some("Reset to defaults")), ("layer.newFillLayer.solidColor", None)] {
+ let mut s = photocraft_engine::Session::new();
+ s.execute("file.new", json!({"width": 200, "height": 100})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let ctx = h.ctx.clone();
+ let (req, _rx) = crate::control::ControlRequest::new("ui.set", json!({"dock": {"collapsed": ["color", "history", "navigator"]}}));
+ crate::control::handle(h.state_mut(), &ctx, &req);
+ h.state_mut().run(command, json!({})).unwrap();
+ h.run_steps(6);
+ let id = h.state().session.active().unwrap().active_layer.unwrap().0;
+ assert!(h.state().ui.mask_target, "{command}: the new mask is targeted");
+ assert_eq!(crate::canvas::paint_target(h.state()), json!("mask"), "{command}: painting edits the mask");
+ assert!(h.query_all_by_label("Density").next().is_none(), "{command}: Properties shows the layer, not its mask");
+ if let Some(label) = settings {
+ assert!(h.query_all_by_label(label).next().is_some(), "{command}: its settings show");
+ }
+ // Clicking the row (not a thumbnail) keeps the settings.
+ let row = h.get_by_label(&layer(&h, id).name).rect().center();
+ click_with(&mut h, row, Modifiers::NONE);
+ assert!(h.state().ui.mask_target);
+ assert!(h.query_all_by_label("Density").next().is_none(), "{command}: a row click keeps the settings");
+ // The mask thumbnail switches Properties to the mask.
+ let r = mask_rect(&h, id, MaskKind::Pixel);
+ click_with(&mut h, r.center(), Modifiers::NONE);
+ h.run_steps(2);
+ assert!(h.state().ui.mask_target);
+ assert!(h.query_all_by_label("Density").next().is_some(), "{command}: the mask thumbnail shows the mask controls");
+ if let Some(label) = settings {
+ assert!(h.query_all_by_label(label).next().is_none());
+ }
+ }
+}
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 3afff0f39..b423b0503 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -2680,6 +2680,10 @@ fn layer_row(
app.ui.selected_path = Some("layer".into());
actions.push(("ui.vectorMaskTarget".into(), json!(true)));
} else if on_mask || (content_less && l.mask.is_some() && !on_thumb) {
+ if on_mask {
+ // The mask thumbnail also switches Properties to the mask (#3369).
+ app.ui.properties_layer = None;
+ }
actions.push(("ui.maskTarget".into(), json!(true)));
} else if on_thumb || !row.primary {
actions.push(("ui.maskTarget".into(), json!(false)));
@@ -3044,7 +3048,7 @@ fn layer_controls(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: &Layer) {
/// Docked Properties body (Pro theme).
fn properties_body(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
- let identity = app.session.active().map(|st| (st.doc.id, st.active_layer, app.ui.mask_target, app.ui.vector_mask_target));
+ let identity = app.session.active().map(|st| (st.doc.id, st.active_layer, app.ui.mask_target, app.ui.vector_mask_target, app.ui.properties_layer));
ui.push_id(("properties-target", identity), |ui| properties_body_inner(app, ui));
}
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 52d44b9b2..4cebc48d2 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -1006,6 +1006,11 @@ pub struct UiState {
/// tools edit it (#196). Never set together with `mask_target`.
#[serde(default)]
pub vector_mask_target: bool,
+ /// The adjustment or fill layer (id) whose own settings Properties shows although its mask
+ /// is targeted: set when that layer is created, as in Photoshop (#3369). Targeting the mask
+ /// thumbnail, the layer's pixels or another layer clears it.
+ #[serde(default)]
+ pub properties_layer: Option<u64>,
/// Brush Preset picker opened by a right-click on the canvas or the options-bar brush chip:
/// its screen position (points).
#[serde(default)]
@@ -1180,6 +1185,7 @@ impl Default for UiState {
symmetry_transform: None,
mask_target: false,
vector_mask_target: false,
+ properties_layer: None,
brush_picker: None,
brush_picker_list: crate::brush_picker::list_state(),
brush_picker_size: None,