Skip to content

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

Merge main into #1734 (effect-row eyes from #1664 kept beside the fx drag)

Claude0b958be52a49
diff --cc crates/ui-egui/src/panels.rs
index 694c0be45,3c5f075eb..18bb47216
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@@ -2761,62 -2772,9 +2787,63 @@@ fn layer_drag_and_drop
}
}
+/// An fx row being dragged: the layer it belongs to and the effect index (`None` = the "Effects"
+/// row, all of them).
+type FxDrag = (u64, Option<usize>);
+
+fn fx_drag_key() -> egui::Id {
+ egui::Id::new("fx-drag")
+}
+
+/// Start dragging the effects of `layer`: one (`effect`) or all of them.
+fn start_fx_drag(ctx: &egui::Context, layer: LayerId, effect: Option<usize>) {
+ ctx.data_mut(|d| d.insert_temp::<FxDrag>(fx_drag_key(), (layer.0, effect)));
+}
+
+/// While effects are dragged: their name by the pointer, and the copy cursor while ⌥ is held.
+fn fx_drag_feedback(ctx: &egui::Context, doc: &photocraft_doc::Document) {
+ let Some((from, effect)) = ctx.data(|d| d.get_temp::<FxDrag>(fx_drag_key())) else { return };
+ let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return };
+ let label = match effect {
+ Some(i) => doc.layer(LayerId(from)).and_then(|l| l.effects.items.get(i)).map_or("", |e| e.label()),
+ None => "Effects",
+ };
+ crate::layer_transfer::ghost(ctx, p, label);
+ if ctx.input(|i| i.modifiers.alt) {
+ ctx.set_cursor_icon(egui::CursorIcon::Copy);
+ }
+}
+
+/// The command for dropping effects of layer `from` on `target`: they move there, or with ⌥ held
+/// on release are copied (Photoshop). `effect` is one effect row, or all effects when `None`.
+fn fx_drop_action(from: u64, effect: Option<usize>, target: LayerId, copy: bool) -> (String, Value) {
+ let mut payload = json!({"from": from, "to": target.0, "copy": copy});
+ if let Some(o) = payload.as_object_mut()
+ && let Some(i) = effect
+ {
+ o.insert("effect".into(), json!(i));
+ }
+ ("layer.layerStyle.transferEffects".into(), payload)
+}
+
+/// A layer row accepts the fx row being dragged: outlined while the pointer is over it, dropped
+/// on release.
+fn fx_drop(ctx: &egui::Context, ui: &egui::Ui, l: &Layer, rect: Rect, actions: &mut Vec<(String, Value)>) {
+ let Some((from, effect)) = ctx.data(|d| d.get_temp::<FxDrag>(fx_drag_key())) else { return };
+ let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return };
+ if from == l.id.0 || !rect.contains(p) {
+ return;
+ }
+ let t = Tokens::get(ctx);
+ ui.painter().rect_stroke(rect.shrink(1.0), t.radius_sm, Stroke::new(2.0, t.accent), StrokeKind::Inside);
+ if ctx.input(|i| i.pointer.any_released()) {
+ actions.push(fx_drop_action(from, effect, l.id, ctx.input(|i| i.modifiers.alt)));
+ }
+}
+
- /// Photoshop shows a layer's effects as indented sub-rows ("Effects", then each effect).
- fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usize) {
+ /// Photoshop shows a layer's effects as indented sub-rows ("Effects", then each effect). The eye
+ /// on "Effects" shows or hides them all, the eye on an effect's row just that one (#1622).
+ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usize, actions: &mut Vec<(String, Value)>) {
let t = Tokens::get(ui.ctx());
let indent = 30.0 + depth as f32 * 14.0 + 34.0;
let mut rows: Vec<(String, bool, Option<&'static str>)> = vec![("Effects".into(), l.effects.enabled, None)];