Masking: drop the one-off overlay screenshot example and its png dev-dependency

Keeps CanvasMap::new and mask_overlay private to detail.rs again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-23 17:06:43 -04:00
co-authored by Claude Opus 5.5
parent 794e307c67
commit 4d3ea22e9c
4 changed files with 2 additions and 60 deletions
Generated
-1
View File
@@ -3525,7 +3525,6 @@ dependencies = [
"lightcraft-slideshow",
"lightcraft-testkit",
"log",
"png",
"serde",
"serde_json",
"toml",
-1
View File
@@ -35,7 +35,6 @@ lightcraft-denoise = { workspace = true, features = ["runtime"] }
lightcraft-codecs = { workspace = true }
lightcraft-faces = { workspace = true }
lightcraft-merge = { workspace = true }
png = { workspace = true }
[build-dependencies]
serde_json = { workspace = true }
@@ -1,56 +0,0 @@
//! Render a screenshot of the masking view with the all-masks overlay on: several visible masks,
//! each outlined, only the selected one draggable. Used to attach a visual to PR #2210.
//!
//! Run: `cargo run -p lightcraft-ui-egui --example mask_overlay_shot -- <out.png>`
use std::time::Duration;
use lightcraft_raster::Rgba8;
use serde_json::json;
use lightcraft_ui_egui::headless::Headless;
use lightcraft_ui_egui::{LightcraftApp, Services};
fn main() {
let out = std::env::args().nth(1).unwrap_or_else(|| "mask-overlay.png".into());
let t = Duration::from_secs(20);
let services = Services { png: None, ..Default::default() };
let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), services);
let mut h = Headless::new(app, [1200.0, 800.0], 1.0);
// Run a control command and stop with a clear message if it does not report ok, so the
// generated PNG never silently omits a mask it was meant to show (CodeRabbit review, line 30).
let mut run = |method: &str, params: serde_json::Value| {
let r = h.request(method, params, t);
assert_eq!(r["ok"], true, "mask_overlay_shot: `{method}` failed: {r}");
};
run("ui.set", json!({"view": "detail"}));
run("engine.execute", json!({"command": "panel.masking"}));
// A few visible masks; mask.add selects the newest, so the last one is selected.
for params in [
json!({"kind": "radial", "center": [0.3, 0.4], "rx": 0.12, "ry": 0.12}),
json!({"kind": "linear", "start": [0.65, 0.25], "end": [0.65, 0.6]}),
json!({"kind": "radial", "center": [0.7, 0.65], "rx": 0.1, "ry": 0.14, "angle": 30}),
] {
run("engine.execute", json!({"command": "mask.add", "params": params}));
}
run("engine.execute", json!({"command": "view.maskOverlayAll"}));
run("engine.execute", json!({"command": "view.maskPins", "params": {"show": false}}));
h.settle(Duration::from_secs(120));
let px = h.view.paint(&Default::default());
let rgba = Rgba8::from_fn(px.width(), px.height(), |x, y| {
let p = px.pixels[y * px.width() + x];
[p.r(), p.g(), p.b(), p.a()]
});
let file = std::fs::File::create(&out).expect("create png");
let mut enc = png::Encoder::new(file, rgba.width as u32, rgba.height as u32);
enc.set_color(png::ColorType::Rgba);
enc.set_depth(png::BitDepth::Eight);
let mut w = enc.write_header().expect("png header");
w.write_image_data(&rgba.as_bytes()).expect("encode png");
println!("wrote {out} ({}, {})", rgba.width, rgba.height);
}
+2 -2
View File
@@ -81,7 +81,7 @@ pub struct CanvasMap {
}
impl CanvasMap {
pub(crate) fn new(frame: &Frame, rect: Rect) -> CanvasMap {
fn new(frame: &Frame, rect: Rect) -> CanvasMap {
let k = 8.0f32;
let (w, h) = ((rect.width() * k).round().max(1.0) as usize, (rect.height() * k).round().max(1.0) as usize);
let to_norm = frame.out_to_norm(w, h);
@@ -1996,7 +1996,7 @@ fn color_range_pick(app: &mut LightcraftApp, ui: &egui::Ui, resp: &egui::Respons
/// The Masking tool on the photo: outlines and handles of the selected mask, a pin per mask
/// component (click selects its mask, drag moves the component), and brush painting. The mask
/// itself shows as a rendered overlay ([`view_overlay`]).
pub(crate) fn mask_overlay(app: &mut LightcraftApp, ui: &mut egui::Ui, resp: &egui::Response, map: &CanvasMap, d: &DevelopSettings) {
fn mask_overlay(app: &mut LightcraftApp, ui: &mut egui::Ui, resp: &egui::Response, map: &CanvasMap, d: &DevelopSettings) {
let long = (map.rect.width().max(map.rect.height())) as f64;
let active = app.session.active_mask;
let clip = app.canvas_rect.unwrap_or(map.rect);