PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Integration: merge main
aiongg2496742eaa36
diff --cc crates/ui-egui/src/filter_dialog.rsindex 4803ed193,7880579b0..e8c838ebc--- a/crates/ui-egui/src/filter_dialog.rs+++ b/crates/ui-egui/src/filter_dialog.rs@@@ -1142,13 -1138,37 +1165,42 @@@ pub(crate) fn preview_document_for_targs.select_layer(id).ok()?;}s.active_mut()?.channel_view.target = target;+ s.execute(command, p).ok()?;+ s.active().map(|d| crate::proxy::proxy_document(&d.doc, reduce_k))+ }++ /// Whether `command` is a Smart Filter edit (its parameters or its blending) rather than a filter run on its own.+ fn is_smart_edit(command: &str) -> bool {+ matches!(command, "layer.smartFilter.setParams" | "layer.smartFilter.blendingOptions")+ }++ /// Each stage constrains the proxy factor; an unscalable filter keeps full-resolution preview.+ pub(crate) fn smart_preview_factor(doc: &Document, command: &str, params: &Value, k: u32) -> u32 {+ if !is_smart_edit(command) {+ return preview_factor(command, params, k);+ }+ let Some(layer) = params.get("layer").and_then(Value::as_u64).and_then(|id| doc.layer(photocraft_doc::LayerId(id))) else { return 1 };+ let photocraft_doc::LayerContent::Smart(sm) = &layer.content else { return 1 };+ let mut factor = sm.smart_filters.iter().fold(k, |k, f| preview_factor(&f.command, &f.params, k));+ if command == "layer.smartFilter.setParams"+ && let Some(index) = params.get("index").and_then(Value::as_u64).and_then(|i| usize::try_from(i).ok())+ && let Some(f) = sm.smart_filters.get(index)+ && let Some(p) = params.get("params")+ {+ factor = preview_factor(&f.command, p, factor);+ }+ factor+ }++ /// Scale the pixel-sized parameters of `command` down by the preview proxy factor `k`, keeping each above its minimum and negative lengths negative.+ fn scale_preview_params(command: &str, params: &mut Value, k: u32) {- if k > 1+ if command == photocraft_engine::plugin_cmds::RUN {+ // A plug-in declares its pixel lengths (`"unit": "px"` in its manifest), and only those+ // are scaled: a 12 px shift previewed 4 times too wide at k = 4, and a unitless param that+ // happens to be called `size` or `radius` must not be divided (#7524).- photocraft_engine::plugin_cmds::scale_for_preview(&mut p, run_k);- } else if run_k > 1- && let Some(o) = p.as_object_mut()++ photocraft_engine::plugin_cmds::scale_for_preview(params, k);++ } else if k > 1+ && let Some(o) = params.as_object_mut(){let spec = photocraft_engine::commands::find(command).map(|c| parse_spec(c.params)).unwrap_or_default();for (key, v) in o.iter_mut() {diff --cc crates/ui-egui/src/smart_ui.rsindex df6ce33d2,edb4e84b2..5522aaecc--- a/crates/ui-egui/src/smart_ui.rs+++ b/crates/ui-egui/src/smart_ui.rs@@@ -168,13 -207,19 +207,25 @@@ pub fn filter_rows(app: &mut Photocraft{open_editor(app, ui.ctx(), l.id.0, sm, i);}+ if let (Some(i), Some(r)) = (index, blend) {+ let blend_resp = ui.interact(r, ui.id().with(("sf-blend", l.id.0, i)), Sense::click());+ icons::paint(ui, r, "sliders-horizontal", 13.0, if blend_resp.hovered() { t.text } else { t.icon });+ let label = crate::i18n::fmt(tl!("Blending Options ({filter})"), &[("filter", &name)]);+ blend_resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, &label));+ if blend_resp.double_clicked()+ && let Err(e) = crate::smart_filter_dialog::open(app, l.id, i)+ {+ crate::notices::error(app, e);+ }+ blend_resp.on_hover_text(label);+ }}+ // Every row of `l` is drawn, so a filter of it selected (now, after this pass's clicks) is on+ // screen: see [`forget_hidden`].+ if ui.ctx().data(|d| d.get_temp::<FilterDrag>(selected_key(doc))).is_some_and(|(layer, _)| layer == l.id.0) {+ let pass = ui.ctx().cumulative_pass_nr();+ ui.ctx().data_mut(|d| d.insert_temp(drawn_key(doc), pass));+ }}/// Smart filter rows being dragged: the smart object and the filter index (`None` = the Smart@@@ -376,43 -371,29 +428,37 @@@ pub fn open_editor(app: &mut Photocraft}return;}+ // And Liquify, which re-opens with the filter's recorded strokes.+ if f.command == photocraft_engine::distort_cmds::LIQUIFY {+ if let Err(e) = crate::liquify_ui::open_smart_filter(app, ctx, photocraft_doc::LayerId(layer), index) {+ app.ui.status = e;+ app.ui.status_error = true;+ }+ return;+ }- // An adjustment recorded on the smart object (Brightness/Contrast, Levels…) re-opens its own- // Image › Adjustments editor, like the filters above.- if crate::adjust_dialog::has_dialog(&f.command) {- if let Some(id) = crate::adjust_dialog::open(app, &f.command) {- edit_filter(app, id, layer, index, &f.params);+ let target = match crate::smart_filter_dialog::target(app, photocraft_doc::LayerId(layer), index) {+ Ok(target) => target,+ Err(e) => {+ crate::notices::error(app, e);+ return;}+ };+ let Some(id) = crate::adjust_dialog::open(app, &f.command).or_else(|| {+ let id = crate::filter_dialog::has_dialog(&f.command).then(|| crate::filter_dialog::open(app, &f.command)).flatten()?;+ // The filter dialog opens on the user's last-used values; a recorded filter that lacks a+ // key must show (and save) the schema default instead.+ let mut fields = app.ui.dialog_mut(id)?.fields.clone();+ crate::filter_dialog::reset_fields(app, &mut fields);+ app.ui.dialog_mut(id)?.fields = fields;+ Some(id)+ }) else {return;- }- if !crate::filter_dialog::has_dialog(&f.command) {- return;- }- let Some(id) = crate::filter_dialog::open(app, &f.command) else { return };- edit_filter(app, id, layer, index, &f.params);- }-- /// Hands the open dialog `id` the smart filter's recorded `params` and makes OK update that- /// filter (`layer.smartFilter.setParams`, see [`confirm_command`]) instead of adding another.- fn edit_filter(app: &mut PhotocraftApp, id: u64, layer: u64, index: usize, params: &Value) {+ };if let Some(d) = app.ui.dialog_mut(id) {- // A filter's live preview runs `layer.smartFilter.setParams` on the proxy, as OK does- // (`canvas::ensure_filter_preview`, #6324). An adjustment's previews on the layer and- // would stack a second copy of it on the smart object.- if d.fields.contains_key("__adjust") {- d.fields.remove("__preview");- }- d.fields.insert("__smartFilter".into(), json!({"layer": layer, "index": index}));- if let Value::Object(p) = params {+ d.fields.insert("__smartFilter".into(), target);+ if let Value::Object(p) = &f.params {for (k, v) in p {- if d.fields.contains_key(k) {+ if !k.starts_with("__") {d.fields.insert(k.clone(), v.clone());}}