Show pending changes consistently on all Apply buttons
This commit is contained in:
parent
3908647328
commit
d0195893a8
|
|
@ -136,7 +136,7 @@ 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 ui.button("Apply output resolution").clicked() {
|
||||
if apply_button(ui,"Apply output resolution", d.size != self.layout.formats().output.map(f64::from)).clicked() {
|
||||
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(AMBER,&d.error); }
|
||||
|
|
@ -224,7 +224,10 @@ impl Editor {
|
|||
Err(e)=>{ ui.colored_label(AMBER,e); },
|
||||
_=>{}
|
||||
}
|
||||
if ui.add_enabled(reviewed.is_ok(),egui::Button::new("Apply source / input / layer formats")).clicked() {
|
||||
let pending = d.source_id != self.layout.formats().source_for[i]
|
||||
|| d.source != self.layout.formats().sources[d.source_id]
|
||||
|| d.size != [g.width, g.height];
|
||||
if apply_button(ui,"Apply source / input / layer formats", reviewed.is_ok() && pending).clicked() {
|
||||
let result=self.corner.geometry_on(x,y,d.size[0],d.size[1],self.layout.formats().output).and_then(|g|self.layout.configure(i,d.source_id,d.source,g,true));
|
||||
match result { Ok(_)=>{self.sync();d=FormatDraft::new(&self.layout,i);},Err(e)=>d.error=e }
|
||||
}
|
||||
|
|
@ -241,7 +244,9 @@ impl Editor {
|
|||
ui.label(format!("Offsets in output px: X ±{:.1}, Y ±{:.1}. Positive moves content right/down.",limit[0],limit[1]));
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
let apply=ui.button("Apply crop").clicked();
|
||||
let current_framing=self.layout.formats().mapping(i,current).unwrap().framing;
|
||||
let pending=d.framing != current_framing;
|
||||
let apply=apply_button(ui,"Apply crop",pending).clicked();
|
||||
let recenter=ui.button("Recenter").clicked();
|
||||
let reset=ui.button("Reset crop").clicked();
|
||||
if recenter { d.framing=self.layout.formats().mapping(i,current).unwrap().framing; d.framing.offset=[0.0;2]; }
|
||||
|
|
@ -405,6 +410,30 @@ mod tests {
|
|||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn unchanged_output_apply_does_not_reset_camera_and_reapplies_after_undo() {
|
||||
let mut app = Editor {
|
||||
zoom: 2.0,
|
||||
pan: Vec2::new(10.0, 20.0),
|
||||
..Default::default()
|
||||
};
|
||||
let ctx = egui::Context::default();
|
||||
app.output_draft = Some(OutputDraft::new(app.layout.formats().output));
|
||||
click_text(&mut app, &ctx, "Apply output resolution");
|
||||
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");
|
||||
assert_eq!(app.layout.formats().output, [1280, 720]);
|
||||
app.zoom = 3.0;
|
||||
click_text(&mut app, &ctx, "Apply output resolution");
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_dialog_rejects_fractional_pixels_and_preserves_layer_geometry() {
|
||||
let mut app = Editor::default();
|
||||
|
|
|
|||
|
|
@ -350,6 +350,21 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn fields_pending(&self) -> bool {
|
||||
let Some(i) = self.layout.selected() else {
|
||||
return false;
|
||||
};
|
||||
let g = self.layout.layers()[i];
|
||||
let [x, y] = self.corner.offsets_on(g, self.layout.formats().output);
|
||||
self.fields
|
||||
.iter()
|
||||
.zip([x, y, g.width, g.height])
|
||||
.any(|(text, value)| {
|
||||
text.trim().parse::<f64>().map_or(true, |parsed| {
|
||||
parsed != value && parsed != number(value).parse::<f64>().unwrap()
|
||||
})
|
||||
})
|
||||
}
|
||||
fn apply_fields(&mut self) {
|
||||
let values: Result<Vec<f64>, _> = self
|
||||
.fields
|
||||
|
|
@ -364,7 +379,7 @@ impl Editor {
|
|||
let [x, y] = self.corner.offsets_on(g, self.layout.formats().output);
|
||||
let original = [x, y, g.width, g.height];
|
||||
for j in 0..4 {
|
||||
if self.fields[j] == number(original[j]) {
|
||||
if v[j] == number(original[j]).parse::<f64>().unwrap() {
|
||||
v[j] = original[j];
|
||||
}
|
||||
}
|
||||
|
|
@ -599,7 +614,7 @@ impl Editor {
|
|||
let mut preview=self.layout.clone();
|
||||
let valid=p.apply(&mut preview);
|
||||
if let Err(e)=&valid {ui.colored_label(AMBER,e);}
|
||||
if ui.add_enabled(valid.is_ok(),egui::Button::new("Apply mapped values").fill(PURPLE)).clicked() {
|
||||
if apply_button(ui,"Apply 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}
|
||||
}
|
||||
}
|
||||
|
|
@ -839,8 +854,20 @@ impl Editor {
|
|||
enter = true;
|
||||
}
|
||||
}
|
||||
ink.button(0.0, 530.0, w, "Apply position / size", false);
|
||||
if click(ui, &ink, [0.0, 530.0, w, 34.0], "apply-fields") || enter {
|
||||
let pending = self.fields_pending();
|
||||
let apply = ui
|
||||
.scope_builder(
|
||||
egui::UiBuilder::new().max_rect(Rect::from_min_size(
|
||||
ink.point(0.0, 530.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) {
|
||||
self.apply_fields();
|
||||
}
|
||||
if !self.error.is_empty() {
|
||||
|
|
@ -1971,6 +1998,13 @@ fn alignment_icon(
|
|||
response.on_hover_text(title)
|
||||
}
|
||||
|
||||
fn apply_button(ui: &mut egui::Ui, label: &str, pending: bool) -> egui::Response {
|
||||
let button = egui::Button::new(label)
|
||||
.min_size(ui.spacing().interact_size)
|
||||
.fill(if pending { PURPLE } else { FIELD });
|
||||
ui.add_enabled(pending, button)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ToolbarIcon {
|
||||
Output,
|
||||
|
|
@ -2973,6 +3007,32 @@ mod tests {
|
|||
click_shift(&mut app, &ctx, row.center());
|
||||
assert_eq!(app.layout.selected(), Some(1));
|
||||
}
|
||||
#[test]
|
||||
fn position_pending_state_preserves_precision_and_clears_after_apply_or_revert() {
|
||||
let mut app = Editor::default();
|
||||
let mut g = app.layout.layers()[1];
|
||||
g.width = 640.12345;
|
||||
app.layout.apply(1, g).unwrap();
|
||||
app.sync();
|
||||
let original = app.fields.clone();
|
||||
assert!(!app.fields_pending());
|
||||
app.fields[2] = "640.1000".into();
|
||||
assert!(!app.fields_pending());
|
||||
app.fields[0] = "invalid".into();
|
||||
assert!(app.fields_pending());
|
||||
app.fields = original.clone();
|
||||
assert!(!app.fields_pending());
|
||||
app.fields[0] = "150".into();
|
||||
assert!(app.fields_pending());
|
||||
app.apply_fields();
|
||||
assert!(!app.fields_pending());
|
||||
assert_eq!(app.layout.layers()[1].width, g.width);
|
||||
app.layout.undo();
|
||||
app.sync();
|
||||
assert!(!app.fields_pending());
|
||||
assert_eq!(app.fields, original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canvas_context_menu_selects_target_preserves_groups_and_opens_properties() {
|
||||
for grouped in [false, true] {
|
||||
|
|
|
|||
|
|
@ -354,3 +354,8 @@ center, keeping the opposite edge’s midpoint fixed. Disable it to change just
|
|||
one axis. Corner handles still keep the
|
||||
opposite corner fixed. Crop preservation, lock protection, Escape and Undo apply
|
||||
to both kinds of resize handles.
|
||||
|
||||
Apply buttons are muted and disabled when their values already match the layout.
|
||||
Pending changes make Apply solid purple. This applies to position/size, output
|
||||
resolution, source/input/layer formats, crop framing, and mapped imports. Each
|
||||
section tracks its own values; reverting an edit clears its pending state.
|
||||
|
|
|
|||
Loading…
Reference in New Issue