Add per-category protection for device input settings

This commit is contained in:
Dandaedre 2026-11-18 14:57:57 +01:00
parent 9ac81b7a36
commit b3845ef1c6
6 changed files with 112 additions and 6 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.9.58"
version = "0.9.59"
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.58"
version = "0.9.59"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"

View File

@ -5,7 +5,7 @@ use crate::{
formats::Crop,
};
use serde_json::{Value, json};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
#[derive(Clone, Debug)]
pub enum Kind {
@ -30,6 +30,7 @@ pub struct InputDraft {
pub values: BTreeMap<String, Value>,
original: BTreeMap<String, Value>,
observed: Vec<(String, Value)>,
kept_groups: BTreeSet<String>,
}
impl InputDraft {
pub fn read(snapshot: &Snapshot, input: u32) -> Result<Self, String> {
@ -331,10 +332,33 @@ impl InputDraft {
values: original.clone(),
original,
observed,
kept_groups: BTreeSet::new(),
})
}
pub fn dirty(&self) -> bool {
self.values != self.original
self.fields.iter().any(|f| {
!self.keeps_group(f.group) && self.values.get(&f.path) != self.original.get(&f.path)
})
}
pub fn keeps_group(&self, group: &str) -> bool {
self.kept_groups.contains(group)
}
/// Keep means no writes, never restoring stale device values.
pub fn keep_group(&mut self, group: &str, keep: bool) {
if keep {
self.kept_groups.insert(group.to_owned());
} else {
self.kept_groups.remove(group);
}
self.restore_kept_groups();
}
pub fn restore_kept_groups(&mut self) {
for field in &self.fields {
if self.keeps_group(field.group) {
self.values
.insert(field.path.clone(), self.original[&field.path].clone());
}
}
}
pub fn reset(&mut self) {
self.values = self.original.clone();
@ -460,6 +484,9 @@ impl InputDraft {
.iter()
.find(|f| &f.path == path)
.ok_or("Unknown input setting")?;
if self.keeps_group(field.group) {
continue;
}
let valid = match &field.kind {
Kind::Number(min, max) => {
after.as_i64().is_some_and(|v| (*min..=*max).contains(&v))
@ -527,6 +554,47 @@ mod tests {
}
}
#[test]
fn kept_categories_never_send_and_discard_their_edits() {
let s = snapshot();
let mut d = InputDraft::read(&s, 1).unwrap();
let brightness = d
.fields
.iter()
.find(|f| f.label == "Brightness")
.unwrap()
.path
.clone();
d.values.insert(brightness.clone(), json!(10));
d.keep_group("Color", true);
assert_eq!(d.values[&brightness], json!(0));
assert!(!d.dirty());
// Even a stale undo value cannot bypass the send boundary.
d.values.insert(brightness.clone(), json!(20));
assert!(d.changes(&s).unwrap().is_empty());
assert!(!d.dirty());
d.zoom_crop(2., [0.5, 0.5]).unwrap();
assert!(
d.changes(&s)
.unwrap()
.iter()
.all(|c| !c.path.iter().any(|p| p == "color"))
);
d.restore_kept_groups();
d.keep_group("Color", false);
d.values.insert(brightness, json!(15));
assert!(
d.changes(&s)
.unwrap()
.iter()
.any(|c| c.path.iter().any(|p| p == "color"))
);
d.keep_group("Crop", true);
assert_eq!(d.crop(), Crop::default());
d.reset();
assert!(!d.dirty());
assert!(d.keeps_group("Crop"));
}
#[test]
fn aquilon_uses_aspect_bounds_and_unsigned_color_ranges() {
let mut s = snapshot();
s.profile = Profile::Aquilon6;

View File

@ -161,7 +161,7 @@ impl Editor {
let mut undoing=false;
ui.add_enabled_ui(state.pending.is_none() && !self.device.busy(),|ui|{
ui.horizontal(|ui|{
if ui.button("Undo input edit").clicked() && let Some(previous)=state.undo.entry(id).or_default().pop(){draft.values=previous;undoing=true;state.edit_start=None;}
if ui.button("Undo input edit").clicked() && let Some(previous)=state.undo.entry(id).or_default().pop(){draft.values=previous;draft.restore_kept_groups();undoing=true;state.edit_start=None;}
if ui.button("Discard draft").clicked(){draft.reset();}
if ui.button("Reload selected input").clicked(){refresh=true;}
capture=ui.add_enabled(capture_idle && inputs.iter().any(|i|i.id==id && i.enabled),egui::Button::new("Capture input")).clicked();
@ -169,7 +169,7 @@ impl Editor {
ui.columns(2,|columns|{
let ui=&mut columns[0];
ui.heading("Input crop");
crop_editor(ui,draft,&mut state.pivot,(&mut state.view_zoom,&mut state.view_pan),&mut state.drag,&mut state.message,state.capture.as_ref().zip(state.capture_geometry).map(|(r,g)|(r.texture.id(),g)));
ui.add_enabled_ui(!draft.keeps_group("Crop"), |ui| { crop_editor(ui,draft,&mut state.pivot,(&mut state.view_zoom,&mut state.view_pan),&mut state.drag,&mut state.message,state.capture.as_ref().zip(state.capture_geometry).map(|(r,g)|(r.texture.id(),g))); });
ui.separator();
ui.label("Device capture · processed preview");
ui.small("Unavailable pixels use the sizing pattern. Aquilon captures fill only the known region; the unchanged capture is shown below. No raw pixels are reconstructed.");
@ -178,6 +178,13 @@ impl Editor {
for group in ["Aspect","Crop","Color","Processing","Keying","LUT"] {
if !draft.fields.iter().any(|f|f.group==group){continue;}
egui::CollapsingHeader::new(group).default_open(matches!(group,"Aspect"|"Crop")).show(ui,|ui|{
let mut keep = draft.keeps_group(group);
if ui.checkbox(&mut keep,"Keep device values").on_hover_text("Leave this category untouched when sending. Checking discards its draft edits.").changed() {
draft.keep_group(group,keep);
state.review=false;
if group=="Crop" {state.drag=None;}
}
ui.add_enabled_ui(!keep, |ui| {
for field in &draft.fields {
if field.group!=group{continue;}
let value=draft.values.get_mut(&field.path).unwrap();
@ -197,6 +204,7 @@ impl Editor {
}
});
}
});
});
}
ui.small("LUT controls require an allocated resource. Signal/HDCP and resource allocation remain in WebRCS.");
@ -644,6 +652,25 @@ mod tests {
app
}
#[test]
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, "Reset crop");
super::super::tests::click_text(&mut app, &ctx, "Keep device values");
assert!(app.inputs.drafts[&1].keeps_group("Crop"));
assert_eq!(app.inputs.drafts[&1].crop().left, 24.);
super::super::tests::click_text(&mut app, &ctx, "Reset crop");
assert_eq!(app.inputs.drafts[&1].crop().left, 24.);
super::super::tests::click_text(&mut app, &ctx, "Undo input edit");
assert_eq!(app.inputs.drafts[&1].crop().left, 24.);
assert!(!app.inputs.drafts[&1].dirty());
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());
assert!(!app.device.input_sending);
assert!(app.inputs.pending.is_none());
}
#[test]
fn shared_input_reset_and_undo_do_not_modify_layers_or_send() {
let mut app = input_app();
let layers = app.layout.layers().clone();

View File

@ -4,6 +4,12 @@
## Unreleased
### v0.9.59
- Added “Keep device values” per input-settings category. Protected categories
discard draft edits, disable editing and never contribute device writes, including
after Undo. Crop protection also disables the visual crop editor.
### v0.9.58
- Made shared input crop handles easier to grab, with larger targets, resize

View File

@ -320,6 +320,11 @@ Program and layers outside the project. Nothing is sent while dragging, selectin
an input, capturing an image or opening the window. Use **Review input changes**,
then **Send input settings** to apply the edited fields and verify them.
- **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.
- **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