Protect input categories by default and refine crop zoom
Gitea/canvas-pilot/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-18 15:52:41 +01:00
parent f954551711
commit 7e80311797
5 changed files with 68 additions and 11 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.9.66"
version = "0.9.67"
dependencies = [
"base64 0.22.1",
"craft-dwg",

View File

@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
resolver = "3"
[workspace.package]
version = "0.9.66"
version = "0.9.67"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"

View File

@ -148,7 +148,7 @@ impl Editor {
}
if let std::collections::btree_map::Entry::Vacant(entry)=self.inputs.drafts.entry(id) {
match InputDraft::read(snapshot,id){Ok(draft)=>{entry.insert(draft);},Err(e)=>{ui.label(e);return;}}
match InputDraft::read(snapshot,id){Ok(mut draft)=>{let groups: std::collections::BTreeSet<_> = draft.fields.iter().map(|f|f.group).collect(); for group in groups {draft.keep_group(group,true);} entry.insert(draft);},Err(e)=>{ui.label(e);return;}}
}
let state=&mut self.inputs;
let draft=state.drafts.get_mut(&id).unwrap();
@ -307,6 +307,19 @@ fn crop_hit(rect: Rect, pos: Pos2) -> Option<[i8; 2]> {
])
}
fn set_crop_zoom(
draft: &mut InputDraft,
percent: f64,
current: f64,
pivot: [f64; 2],
) -> Result<(), String> {
if percent == 100.0 {
draft.set_crop(Crop::default())
} else {
draft.zoom_crop(percent / current, pivot)
}
}
fn crop_editor(
ui: &mut egui::Ui,
draft: &mut InputDraft,
@ -341,8 +354,8 @@ fn crop_editor(
}
changed |= ui
.add(
egui::Slider::new(&mut zoom, 100.0..=maximum)
.logarithmic(true)
egui::Slider::new(&mut zoom, 100.0..=500.0)
.clamping(egui::SliderClamping::Never)
.suffix("%")
.max_decimals(1),
)
@ -354,8 +367,10 @@ fn crop_editor(
zoom = zoom.clamp(100.0, maximum);
if changed
&& (zoom - current).abs() > 0.0001
&& let Err(error) = draft.zoom_crop(
zoom / current,
&& let Err(error) = set_crop_zoom(
draft,
zoom,
current,
[pivot[0] as f64 / 2.0, pivot[1] as f64 / 2.0],
)
{
@ -529,6 +544,36 @@ fn crop_editor(
mod tests {
use super::*;
#[test]
fn input_categories_start_protected_and_full_zoom_clears_asymmetric_crop() {
let mut app = input_app();
let ctx = egui::Context::default();
super::super::tests::frame(&mut app, &ctx, vec![]);
let draft = app.inputs.drafts.get_mut(&1).unwrap();
assert!(
draft
.fields
.iter()
.all(|field| draft.keeps_group(field.group))
);
assert!(!draft.dirty());
draft.keep_group("Crop", false);
draft
.set_crop(Crop {
left: 1.,
right: 0.,
top: 0.,
bottom: 0.,
})
.unwrap();
let native = draft.native.unwrap();
let retained = draft.crop().remaining(native).unwrap();
let current = 100. * (native[0] * native[1] / (retained[0] * retained[1])).sqrt();
set_crop_zoom(draft, 100., current, [0.5, 0.5]).unwrap();
assert_eq!(draft.crop(), Crop::default());
set_crop_zoom(draft, 600., 100., [0.5, 0.5]).unwrap();
assert_eq!(draft.crop().remaining(native).unwrap(), [320., 180.]);
}
#[test]
fn enum_labels_are_readable_without_changing_wire_values() {
for (wire, display) in [
("16_9", "16:9"),
@ -649,6 +694,7 @@ mod tests {
fn keep_crop_disables_editor_and_survives_undo() {
let mut app = input_app();
let ctx = egui::Context::default();
super::super::tests::click_text(&mut app, &ctx, "Keep device values");
super::super::tests::click_text(&mut app, &ctx, "Reset crop");
super::super::tests::click_text(&mut app, &ctx, "Keep device values");
assert!(app.inputs.drafts[&1].keeps_group("Crop"));
@ -669,6 +715,7 @@ mod tests {
let mut app = input_app();
let layers = app.layout.layers().clone();
let ctx = egui::Context::default();
super::super::tests::click_text(&mut app, &ctx, "Keep device values");
super::super::tests::click_text(&mut app, &ctx, "Reset crop");
assert_eq!(app.inputs.drafts[&1].crop(), Crop::default());
super::super::tests::click_text(&mut app, &ctx, "Undo input edit");

View File

@ -4,6 +4,14 @@
## Unreleased
### v0.9.67
- Input editor categories now start with **Keep device values** enabled.
- Crop zoom uses a 100–500% slider with manual entry beyond its range, subject
to device limits. Selecting 100% clears both crop axes exactly, avoiding a
residual crop after asymmetric edits.
### v0.9.66
- Reopening a project now resumes saved preview auto-refresh when its matching

View File

@ -323,12 +323,14 @@ validation and verified readback.
- **Keep device values:** each category has this toggle. Check it to discard that
category’s draft edits, disable its controls and leave it untouched when sending.
Crop protection also disables the visual crop editor. Uncheck to edit again.
Categories start editable; unchanged fields are never sent. Protection is retained
when discarding edits, and cleared when reloading the input.
All categories start protected. Uncheck only the categories you want to edit;
unchanged fields are never sent. Protection is retained when discarding edits,
and all categories return to protected when reloading the input.
- **Input crop:** drag edges/corners or move the retained box. Crop zoom reduces
or expands the retained region around the selected pivot using the **− slider +**
percentage control; it does not add a
second zoom stage. Numeric edges use native device crop coordinates.
percentage control. The slider spans **100–500%**; click its numeric value to
enter a percentage beyond that range, within device limits. **100%** clears
all crop edges exactly. This does not add a second zoom stage. Numeric edges use native device crop coordinates.
- **View zoom:** changes only the editor view; wheel zooms and middle drag pans.
Reset crop, Undo input edit and Escape during a drag help recover an edit.
- **Aspect**, **Color** and **Processing** expose adapter-specific settings.