Skip to content

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

Smart Filters: document the functions next to the ones the PR changes

abc2cb25b79243f1ea
diff --git a/crates/engine/src/fx_view_cmds.rs b/crates/engine/src/fx_view_cmds.rs
index 76bbc781e..af550a367 100644
--- a/crates/engine/src/fx_view_cmds.rs
+++ b/crates/engine/src/fx_view_cmds.rs
@@ -10,10 +10,12 @@ use crate::{EngineError, Result, Session};
const ID: &str = "layer.setEffectsExpanded";
+/// A `layer.setEffectsExpanded` parameter error.
fn bad(msg: impl Into<String>) -> EngineError {
EngineError::BadParams { cmd: ID.into(), msg: msg.into() }
}
+/// The command is available while some layer has effects or Smart Filters to disclose.
fn has_effects(s: &Session) -> std::result::Result<(), String> {
let d = s.active().ok_or("no document open")?;
if d.doc.walk().iter().any(|(_, _, l)| has_children(l)) { Ok(()) } else { Err("no layer has effects or smart filters".into()) }
@@ -24,6 +26,7 @@ fn has_children(l: &Layer) -> bool {
!l.effects.items.is_empty() || matches!(&l.content, LayerContent::Smart(sm) if !sm.smart_filters.is_empty())
}
+/// An optional boolean param: `None` when absent or null, an error when it is anything but true or false.
fn opt_bool(p: &Value, key: &str) -> Result<Option<bool>> {
match p.get(key) {
None | Some(Value::Null) => Ok(None),
@@ -64,6 +67,7 @@ fn set_expanded(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({"expanded": expanded, "layers": targets.len()}))
}
+/// Register `layer.setEffectsExpanded`: view state, so it is not journaled and adds no undo step.
pub fn specs() -> Vec<CommandSpec> {
vec![CommandSpec {
id: ID,
@@ -93,6 +97,7 @@ mod tests {
(s, a, b)
}
+ /// Whether the layer's effects list is shown, i.e. it is not in the document's collapsed set.
fn open(s: &Session, id: u64) -> bool {
!s.active().unwrap().fx_collapsed.contains(&LayerId(id))
}
@@ -120,6 +125,7 @@ mod tests {
assert!(s.active().unwrap().fx_collapsed.is_empty());
}
+ /// Toggling one layer or all of them flips only the disclosure state: no history step, no duplicates, and the document stays clean.
#[test]
fn toggles_one_layer_or_all_without_history() {
let (mut s, a, b) = session();
diff --git a/crates/engine/src/smart_cmds/tests.rs b/crates/engine/src/smart_cmds/tests.rs
index 3666a4818..f955a21ee 100644
--- a/crates/engine/src/smart_cmds/tests.rs
+++ b/crates/engine/src/smart_cmds/tests.rs
@@ -77,6 +77,7 @@ fn non_normal_coverage_changes_retain_source_over_semantics() {
}
}
+/// A `depth`-bit document with one empty layer.
fn session(depth: u64) -> Session {
let mut s = Session::new();
s.execute("file.new", json!({"width": W, "height": H, "depth": depth})).unwrap();
diff --git a/crates/engine/tests/photoshop_oracles.rs b/crates/engine/tests/photoshop_oracles.rs
index 1b3e37d3e..b1f0a133a 100644
--- a/crates/engine/tests/photoshop_oracles.rs
+++ b/crates/engine/tests/photoshop_oracles.rs
@@ -93,6 +93,7 @@ fn screen_motion_blur_retains_input_coverage() {
assert!(error <= PASS_TOL, "Screen/Motion Blur error {error}, {bad}% pixels exceed 2/255");
}
+/// Re-render every Photoshop oracle in the corpus with PhotoCraft's filters and compare it with Photoshop's own merged composite.
#[test]
fn photoshop_oracles_rerendered() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus/photoshop");
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 584d0928d..893401ba8 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -2330,6 +2330,7 @@ impl PhotocraftApp {
id
}
+ /// The cached thumbnail of `mask`, the layer mask of layer `id`.
pub fn mask_thumb(&mut self, ctx: &egui::Context, doc: &Document, id: photocraft_doc::LayerId, mask: &photocraft_doc::LayerMask) -> egui::TextureId {
self.mask_thumb_kind(ctx, doc, id, mask, mask_thumbs_ui::THUMB_MASK)
}
diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs
index 1d8e6d68c..8afc3578e 100644
--- a/crates/ui-egui/src/smart_ui.rs
+++ b/crates/ui-egui/src/smart_ui.rs
@@ -206,6 +206,7 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &Document, l
/// Filters row, all of them). Also what a click selects.
pub(crate) type FilterDrag = (u64, Option<usize>);
+/// Memory key of the smart filter row being dragged.
pub(crate) fn drag_key() -> egui::Id {
egui::Id::new("smart-filter-drag")
}