Remove redundant Apply controls from automatic editor changes

This commit is contained in:
Dandaedre 2026-11-14 14:24:15 +01:00
parent e6809eb021
commit a0dd8dfb20
5 changed files with 119 additions and 105 deletions

View File

@ -147,7 +147,7 @@ pub(super) struct OutputDraft {
aspect: Aspect,
locked: bool,
error: String,
closing: bool,
observed_size: [f64; 2],
}
impl OutputDraft {
pub(super) fn pending(&self, layout: &Layout) -> bool {
@ -166,7 +166,7 @@ impl OutputDraft {
.unwrap_or(Aspect::Custom),
locked: false,
error: String::new(),
closing: false,
observed_size: output.map(f64::from),
}
}
}
@ -251,8 +251,12 @@ impl Editor {
let Some(mut d) = self.output_draft.take() else {
return;
};
if d.error.is_empty() && d.size == d.observed_size && d.pending(&self.layout) {
let locked = d.locked;
d = OutputDraft::new(self.layout.formats().output);
d.locked = locked;
}
let mut open = true;
let previous_size = d.size;
egui::Window::new("Output format / viewport resolution").open(&mut open).default_width(470.0).show(ctx,|ui| {
ui.horizontal_wrapped(|ui| {for (name,value) in [("HD",[1280.0,720.0]),("Full HD",[1920.0,1080.0]),("UHD 4K",[3840.0,2160.0])] {
if ui.button(name).clicked() {d.size=value;d.aspect=Aspect::SixteenNine;}
@ -271,7 +275,8 @@ impl Editor {
}
ui.label(format!("Proposed output: {:.1} × {:.1} px. Linked dimensions round the other side to whole pixels.",d.size[0],d.size[1]));
ui.label("Changing output preserves layer positions and sizes. Custom dimensions are planning sizes, not verified device modes.");
if apply_button(ui,"Apply output resolution", d.size != self.layout.formats().output.map(f64::from)).clicked() || d.size != previous_size {
if d.size != d.observed_size {
d.observed_size = d.size;
match midra_layout::formats::resolution_from_values(d.size).and_then(|size|self.layout.set_output(size)) { Ok(())=>{ self.zoom=1.0;self.pan=Vec2::ZERO;self.sync(); d.error.clear(); },Err(e)=>d.error=e }
}
if !d.error.is_empty() { ui.colored_label(theme::palette(ui.ctx()).amber,&d.error); }
@ -284,31 +289,7 @@ impl Editor {
if ui.button("1:1 display pixels").clicked() {self.camera_one_to_one=true;}
});
});
if !open && d.size != self.layout.formats().output.map(f64::from) {
d.closing = true;
}
if d.closing {
match pending_close(ctx, "output-close", &d.error) {
Some(true) => match midra_layout::formats::resolution_from_values(d.size)
.and_then(|size| self.layout.set_output(size))
{
Ok(()) => {
self.zoom = 1.0;
self.pan = Vec2::ZERO;
self.sync();
return;
}
Err(e) => {
d.error = e;
d.closing = false;
open = true;
}
},
Some(false) => return,
None => {}
}
}
if open || d.closing {
if open {
self.output_draft = Some(d);
}
}
@ -430,7 +411,7 @@ impl Editor {
_=>{}
}
let pending = d.pending(&self.layout);
if apply_button(ui,"Apply source / input / layer formats", pending).clicked() {
if apply_button(ui,"Apply source changes", pending).clicked() {
match d.apply(&mut self.layout, position_reference, self.keep_aspect_ratio) { Ok(())=>{self.sync();d=FormatDraft::new(&self.layout,i);},Err(e)=>d.error=e }
}
ui.small("Source changes require Apply. Switching tabs keeps pending source edits.");
@ -659,7 +640,7 @@ mod tests {
[1280, 720]
);
let output = frame(&mut app, &ctx, vec![]);
assert!(!output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == "Apply source / input / layer formats")));
assert!(!output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == "Apply source changes")));
app.layout.undo();
assert_eq!(app.layout.layers(), &before);
}
@ -1034,7 +1015,7 @@ mod tests {
}
#[test]
fn unchanged_output_apply_does_not_reset_camera_and_reapplies_after_undo() {
fn output_auto_applies_edits_without_resetting_camera_on_idle_or_undo() {
let mut app = Editor {
zoom: 2.0,
pan: Vec2::new(10.0, 20.0),
@ -1042,19 +1023,20 @@ mod tests {
};
let ctx = egui::Context::default();
app.output_draft = Some(OutputDraft::new(app.layout.formats().output));
click_text(&mut app, &ctx, "Apply output resolution");
super::super::tests::frame(&mut app, &ctx, vec![]);
assert_eq!(app.zoom, 2.0);
assert_eq!(app.pan, Vec2::new(10.0, 20.0));
app.output_draft.as_mut().unwrap().size = [1280.0, 720.0];
click_text(&mut app, &ctx, "Apply output resolution");
super::super::tests::frame(&mut app, &ctx, vec![]);
assert_eq!(app.layout.formats().output, [1280, 720]);
app.zoom = 3.0;
click_text(&mut app, &ctx, "Apply output resolution");
super::super::tests::frame(&mut app, &ctx, vec![]);
assert_eq!(app.zoom, 3.0);
app.layout.undo();
click_text(&mut app, &ctx, "Apply output resolution");
assert_eq!(app.layout.formats().output, [1280, 720]);
assert_eq!(app.zoom, 1.0);
super::super::tests::frame(&mut app, &ctx, vec![]);
assert_eq!(app.layout.formats().output, [1920, 1080]);
assert_eq!(app.zoom, 3.0);
assert_eq!(app.output_draft.as_ref().unwrap().size, [1920.0, 1080.0]);
}
#[test]
@ -1064,11 +1046,11 @@ mod tests {
let before = app.layout.layers().clone();
app.output_draft = Some(OutputDraft::new([1920, 1080]));
app.output_draft.as_mut().unwrap().size = [1920.5, 1080.0];
click_text(&mut app, &ctx, "Apply output resolution");
super::super::tests::frame(&mut app, &ctx, vec![]);
assert!(!app.output_draft.as_ref().unwrap().error.is_empty());
assert_eq!(app.layout.formats().output, [1920, 1080]);
app.output_draft.as_mut().unwrap().size = [2560.0, 1600.0];
click_text(&mut app, &ctx, "Apply output resolution");
super::super::tests::frame(&mut app, &ctx, vec![]);
assert_eq!(app.layout.formats().output, [2560, 1600]);
assert_eq!(*app.layout.layers(), before);
assert_eq!(
@ -1093,7 +1075,7 @@ mod tests {
d.source.input_crop = Crop::centered([1920.0, 1080.0], d.input_size).unwrap();
d.size = [300.0, 250.0];
app.format_draft = Some(d);
click_text(&mut app, &ctx, "Apply source / input / layer formats");
click_text(&mut app, &ctx, "Apply source changes");
assert_eq!(app.layout.formats().input(1).unwrap(), [1920.0, 1000.0]);
let g = app.layout.layers()[1];
assert_eq!([g.width, g.height], [300.0, 250.0]);

View File

@ -49,7 +49,6 @@ pub struct Editor {
position_layer_point: Option<PositionPoint>,
fields: [String; 4],
field_rects: [Rect; 4],
fields_closing: bool,
fields_edited: bool,
error: String,
paste: Option<Paste>,
@ -261,7 +260,6 @@ impl Default for Editor {
position_layer_point: None,
fields: Default::default(),
field_rects: [Rect::NOTHING; 4],
fields_closing: false,
fields_edited: false,
error: String::new(),
paste: None,
@ -936,7 +934,7 @@ impl Editor {
let mut preview=self.layout.clone();
let valid=p.apply(&mut preview);
if let Err(e)=&valid {ui.colored_label(palette.amber,e);}
if apply_button(ui,"Apply mapped values", valid.is_ok() && (preview.layers()!=self.layout.layers() || preview.formats()!=self.layout.formats())).clicked() {
if apply_button(ui,"Import mapped values", valid.is_ok() && (preview.layers()!=self.layout.layers() || preview.formats()!=self.layout.formats())).clicked() {
match p.apply(&mut self.layout) {Ok(())=>{self.sync();close=true;},Err(e)=>p.error=e}
}
}
@ -970,7 +968,7 @@ impl Editor {
let (r, _) = ui.allocate_exact_size(
Vec2::new(
ui.available_width(),
1136.0
1091.0
+ if self.position_layer_point.is_some() {
136.0
} else {
@ -1381,34 +1379,22 @@ impl Editor {
);
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 160.0 + measure_extra)));
let pending = self.fields_pending();
let apply = ui
.scope_builder(
egui::UiBuilder::new().max_rect(Rect::from_min_size(
ink.point(0.0, 558.0),
Vec2::new(w, 34.0),
)),
|ui| {
ui.spacing_mut().interact_size = Vec2::new(w, 34.0);
apply_button(ui, "Apply position / size", pending).clicked()
},
)
.inner;
if apply || (enter && pending) {
if enter && pending {
self.apply_fields();
}
if !self.error.is_empty() {
ui.put(
Rect::from_min_size(ink.point(0.0, 603.0), Vec2::new(w, 55.0)),
Rect::from_min_size(ink.point(0.0, 558.0), Vec2::new(w, 55.0)),
egui::Label::new(egui::RichText::new(&self.error).color(palette.amber)).wrap(),
);
} else if let Some(message) = output_bounds_warning(g, self.layout.formats().output) {
ui.put(
Rect::from_min_size(ink.point(0.0, 603.0), Vec2::new(w, 55.0)),
Rect::from_min_size(ink.point(0.0, 558.0), Vec2::new(w, 55.0)),
egui::Label::new(egui::RichText::new(message).size(12.0).color(palette.amber))
.wrap(),
);
}
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 184.0 + measure_extra)));
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 139.0 + measure_extra)));
ink.line([0.0, 640.0], [w, 640.0], palette.line);
ink.text(
0.0,
@ -3110,12 +3096,11 @@ impl Editor {
})
{
self.apply_fields();
self.fields_closing = self.fields_pending();
}
let blocked = self.files.new_requested
|| self.files.new_after_save
|| self.files.new_ready
|| self.fields_closing
|| (self.fields_edited && self.fields_pending())
|| self
.format_draft
.as_ref()
@ -3270,19 +3255,6 @@ impl Editor {
self.device_window(ctx);
self.layers_window(ctx);
self.theme_window(ctx);
if self.fields_closing {
match pending_close(ctx, "fields-close", &self.error) {
Some(true) => {
self.apply_fields();
self.fields_closing = false;
}
Some(false) => {
self.sync();
self.fields_closing = false;
}
None => {}
}
}
}
}
@ -4904,7 +4876,7 @@ mod tests {
}
#[test]
fn leaving_numeric_fields_commits_before_selection_changes_and_invalid_edits_prompt() {
fn leaving_numeric_fields_commits_and_invalid_edits_stay_inline() {
let ctx = egui::Context::default();
let mut app = Editor::default();
frame(&mut app, &ctx, vec![]);
@ -4932,7 +4904,7 @@ mod tests {
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
);
frame(&mut app, &ctx, vec![mouse(pos, false)]);
assert!(app.fields_closing);
assert!(!app.error.is_empty());
assert_eq!(*app.layout.layers(), before);
assert_eq!(app.fields[0], "invalid");
}
@ -5939,7 +5911,7 @@ mod tests {
.shapes
.iter()
.find_map(|s| match &s.shape {
egui::epaint::Shape::Text(t) if t.galley.job.text == "Apply mapped values" => {
egui::epaint::Shape::Text(t) if t.galley.job.text == "Import mapped values" => {
Some(t.pos + Vec2::new(20.0, 6.0))
}
_ => None,
@ -6028,7 +6000,7 @@ mod tests {
.shapes
.iter()
.find_map(|s| match &s.shape {
egui::epaint::Shape::Text(t) if t.galley.job.text == "Apply mapped values" => {
egui::epaint::Shape::Text(t) if t.galley.job.text == "Import mapped values" => {
Some(t.pos + Vec2::new(30.0, 6.0))
}
_ => None,
@ -6322,7 +6294,7 @@ mod tests {
)],
);
assert!(!app.paste.as_ref().unwrap().include_outline);
for text in ["Include outline in bounds", "Apply mapped values"] {
for text in ["Include outline in bounds", "Import mapped values"] {
let output = frame(&mut app, &ctx, vec![]);
let pos = output
.shapes

View File

@ -207,6 +207,7 @@ impl Editor {
let mut refresh = false;
let mut sync = false;
let mut reorder = None;
let mut commit_names = false;
egui::Window::new("Layers & folders").enabled(!self.format_draft.as_ref().is_some_and(|d| d.pending(&self.layout))).open(&mut open).default_width(740.0).show(ctx, |ui| {
ui.horizontal(|ui| {
add = ui.add_enabled(self.layout.layers().len() < 256, egui::Button::new("Add layer")).clicked();
@ -237,8 +238,10 @@ impl Editor {
});
let selected = self.layout.selection_mask()[i];
if ui.selectable_label(selected, format!("{id:02}")).clicked() { self.layout.toggle(i); sync = true; }
ui.add_sized([170.0,24.0], egui::TextEdit::singleline(name).char_limit(128));
ui.add_sized([140.0,24.0], egui::TextEdit::singleline(folder).char_limit(128));
let name_response = ui.add_sized([170.0,24.0], egui::TextEdit::singleline(name).id(egui::Id::new(("layer-name", *id))).char_limit(128));
let folder_response = ui.add_sized([140.0,24.0], egui::TextEdit::singleline(folder).id(egui::Id::new(("layer-folder", *id))).char_limit(128));
commit_names |= name_response.lost_focus() || folder_response.lost_focus()
|| ((name_response.has_focus() || folder_response.has_focus()) && ui.input(|i| i.key_pressed(egui::Key::Enter)));
let (_, rect) = ui.allocate_space(Vec2::splat(28.0));
if layer_state_icon(ui, rect, ui.id().with(("show", *id)), false, !self.layout.visible(i)).clicked() { self.layout.set_visible(i, !self.layout.visible(i)); sync = true; }
let (_, rect) = ui.allocate_space(Vec2::splat(28.0));
@ -248,12 +251,20 @@ impl Editor {
});
});
ui.weak("Folder names organize the layer list locally; they do not create hardware layers. IDs remain stable when layers are removed.");
let changed = self.layer_ui.drafts.iter().enumerate().any(|(i, (_, name, folder))| self.layout.layer_info(i).name != name.trim() || self.layout.layer_info(i).folder != folder.trim());
if apply_button(ui, "Apply names & folders", changed).clicked() {
match self.layout.rename_layers(&self.layer_ui.drafts) { Ok(()) => { self.layer_ui.error.clear(); self.sync(); }, Err(e) => self.layer_ui.error = e }
}
ui.small("Names and folders save on Enter or when leaving the field. Undo restores previous values.");
if !self.layer_ui.error.is_empty() { ui.colored_label(ui.visuals().error_fg_color, &self.layer_ui.error); }
});
if (commit_names || !open || add || remove || refresh || reorder.is_some())
&& self.names_pending()
{
match self.layout.rename_layers(&self.layer_ui.drafts) {
Ok(()) => {
self.layer_ui.error.clear();
self.sync();
}
Err(error) => self.layer_ui.error = error,
}
}
if (!open || add || remove || refresh) && self.names_pending() {
self.layer_ui.closing = true;
self.layer_ui.deferred = if add {
@ -361,7 +372,7 @@ mod tests {
}
#[test]
fn manager_reorders_without_applying_pending_names_and_undo_keeps_alignment_identity() {
fn manager_commits_names_before_reordering_and_undo_keeps_alignment_identity() {
use super::super::tests::click_text;
let ctx = egui::Context::default();
let mut app = Editor {
@ -372,12 +383,11 @@ mod tests {
app.layer_ui.drafts[0].1 = "Camera".into();
click_text(&mut app, &ctx, "↓");
assert_eq!(app.layout.layer_info(1).id, 2);
assert_eq!(app.layout.layer_info(1).name, "Slides");
assert_eq!(app.layout.layer_info(1).name, "Camera");
assert_eq!(app.layer_ui.drafts[1].1, "Camera");
assert_eq!(app.align_target, AlignTarget::Layer(1));
assert!(app.names_pending());
assert!(!app.names_pending());
assert!(!app.layer_ui.closing);
click_text(&mut app, &ctx, "Apply names & folders");
assert_eq!(app.layout.layer_info(1).name, "Camera");
app.layout.undo();
app.layout.undo();
@ -473,6 +483,50 @@ mod tests {
);
}
#[test]
fn names_and_folders_commit_on_enter_or_focus_loss_and_undo() {
use super::super::tests::{frame, mouse};
for enter in [false, true] {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.manage_layers();
frame(&mut app, &ctx, vec![]);
let before = app.layout.layer_info(1).clone();
let field_id =
egui::Id::new((if enter { "layer-name" } else { "layer-folder" }, before.id));
ctx.memory_mut(|m| m.request_focus(field_id));
frame(&mut app, &ctx, vec![]);
if enter {
app.layer_ui.drafts[1].1 = "Camera".into();
} else {
app.layer_ui.drafts[1].2 = "Cameras".into();
}
frame(&mut app, &ctx, vec![]);
assert_eq!(app.layout.layer_info(1), &before);
let events = if enter {
vec![egui::Event::Key {
key: egui::Key::Enter,
physical_key: None,
pressed: true,
repeat: false,
modifiers: egui::Modifiers::NONE,
}]
} else {
let pos = Pos2::new(20.0, 15.0);
vec![egui::Event::PointerMoved(pos), mouse(pos, true)]
};
let output = frame(&mut app, &ctx, events);
assert!(!output.shapes.iter().any(|shape| matches!(&shape.shape, egui::Shape::Text(t) if t.galley.text() == "Apply names & folders")));
if enter {
assert_eq!(app.layout.layer_info(1).name, "Camera");
} else {
assert_eq!(app.layout.layer_info(1).folder, "Cameras");
}
assert!(!app.names_pending());
app.layout.undo();
assert_eq!(app.layout.layer_info(1), &before);
}
}
#[test]
fn closing_batch_names_applies_or_discards_without_losing_identity() {
let ctx = egui::Context::default();

View File

@ -40,7 +40,7 @@ cargo run --locked -p midra-layout
Zoom applies to the resulting layer size; existing crop offsets clamp if
necessary. Mixed batches keep destination zoom where the source lacks it.
At least one available value must be enabled.
5. Click **Apply mapped values** to update the entire selection in one undo step.
5. Click **Import mapped values** to update the entire selection in one undo step.
Cancel leaves all layers unchanged. Invalid geometry
blocks the whole batch, without partial changes.
@ -128,7 +128,7 @@ clipboard testing against a running draw.io instance remains to be done.
- Arrow keys move the selection by **1 px**; Shift-arrow moves it by **10 px**.
- Under **Measure position from**, choose a corner or the center marker. Center offsets measure layer center from screen center (positive right/down); zero centers the layer. Switching reference changes the displayed
offsets without moving the layer. Position and size edits apply when you leave
a field or press Enter; **Apply position / size** is also available. Resizing preserves that
a field or press Enter. Resizing preserves that
reference point's offsets. Invalid values leave the document unchanged.
- **Escape** cancels a drag or restores uncommitted numeric fields. In the paste
dialog it asks whether to Apply or Discard detected values. Group drags cancel atomically.
@ -507,15 +507,19 @@ The three right-click properties entries open their matching tab directly.
Switching tabs retains pending Source edits, which require Apply. Layer size and
Crop changes apply immediately; each continuous drag is one Undo step.
Closing a window with unapplied source/layer formats, invalid output values,
layer names/folders, a rename, or mapped Midra imports asks **Would you like to
apply changes?**, with **Apply** and **Discard**. Invalid Apply returns to the
editor with the draft and error intact. Escape or clicking outside clipboard/SVG
review asks the same question; its explicit Cancel button discards the review.
Adding/removing layers while batch names are pending also resolves those names
first. Pending property/name edits temporarily disable the main workspace to
prevent a selection change from replacing the draft. Switching property tabs
keeps drafts, including when live crop controls are used.
Position/size edits commit on Enter or focus loss, output resolution changes
apply as edited, and names/folders commit on Enter or focus loss (also before
closing or changing the layer list). These controls have no Apply button.
Invalid geometry stays unchanged and errors appear inline. Closing output
settings discards invalid uncommitted values without a confirmation dialog.
Source edits remain staged; **Apply source changes** commits them. Closing with
pending Source edits, a rename, invalid batch names/folders, or mapped Midra
imports asks **Would you like to apply changes?**, with **Apply** and **Discard**.
Invalid Apply keeps the draft and error. Clipboard/SVG review uses **Import mapped
values**; Escape or clicking outside asks Apply/Discard, while Cancel discards.
Pending property/name edits temporarily disable the main workspace to preserve
the edited layer. Switching property tabs keeps pending Source edits.
Reference display, camera, theme and preference controls already apply immediately.
Device destination links also save to the local document immediately. Device
@ -634,8 +638,8 @@ active in memory and offer **Retry saving options**. No project data, images or
clipboard contents are stored here. The [settings interface](interfaces/midra-layout-settings.md)
documents the file and compatibility rules.
**Keep aspect ratio when resizing** is also available directly above
**Apply position / size** in the selected layer's right panel and in the layer
**Keep aspect ratio when resizing** is also available below the position/size
fields in the selected layer's right panel and in the layer
right-click menu (including multiple selections). These controls share the
Options setting and save changes automatically. They do not apply or discard
pending size/position edits. Crop zoom remains proportional.
@ -699,7 +703,7 @@ status reflects the last successful read, not continuous polling.
## Layer management
Use **Layers → Manage layers & folders…** or **Manage…** above the inspector list.
Add layers, select one or more to remove, and apply names/folder labels. These
Add layers, select one or more to remove, and edit names/folder labels. Names and folders commit on Enter or focus loss. These
changes support Undo/Redo; at least one layer must remain. Folder filtering helps
manage the list without changing stacking order. Lock/Show remain local, undoable flags.
Use each row’s **↑ / ↓** buttons in **Layers & folders** to reorder immediately,

View File

@ -4,6 +4,8 @@
## Unreleased
- Remove redundant position/size and output Apply buttons and their close prompts; names/folders commit on Enter or focus loss with Undo. Rename staged source and clipboard/SVG actions to “Apply source changes” and “Import mapped values”; Midra sends remain explicit.
- Add ImageGen application artwork in PNG, Windows ICO and macOS ICNS formats. Embed native icons and support Linux/BSD desktop entries and macOS app launchers; native Windows/macOS visual checks remain required. Include artwork for the Python device probe.
- Fix the crop-alignment regression test’s Clippy range-loop warning so CI passes with warnings denied; retain both offset assertions.