diff --git a/crates/midra-layout/src/format_ui.rs b/crates/midra-layout/src/format_ui.rs index 3c7a696..eb0036e 100644 --- a/crates/midra-layout/src/format_ui.rs +++ b/crates/midra-layout/src/format_ui.rs @@ -289,7 +289,22 @@ impl Editor { self.output_draft = Some(d); } } + pub(super) fn sync_crop_tab_mode(&mut self) { + let active = self.property_tab == PropertyTab::Crop + && self + .format_draft + .as_ref() + .is_some_and(|d| !d.closing && self.layout.selected() == Some(d.layer)); + if active || self.crop_tab_editing { + self.edit_content = active; + } + self.crop_tab_editing = active; + } pub(super) fn formats_window(&mut self, ctx: &egui::Context) { + self.formats_window_contents(ctx); + self.sync_crop_tab_mode(); + } + fn formats_window_contents(&mut self, ctx: &egui::Context) { let position_reference = self.position_reference(); let Some(mut d) = self.format_draft.take() else { return; @@ -415,9 +430,6 @@ impl Editor { } }); if !ui.input(|input| input.pointer.primary_down()) { d.crop_before = None; } - if ui.add(egui::Button::new(if self.edit_content { "Done adjusting crop" } else { "Adjust layer crop" }).selected(self.edit_content)).clicked() { - self.edit_content = !self.edit_content; - } let (_,rect)=ui.allocate_space(Vec2::new(ui.available_width(),170.0)); let preview_rect=fit_rect(rect,[current.width,current.height]); paint_pattern(ui.painter(),preview_rect,self.layout.formats().sources[self.layout.formats().source_for[i]],self.layout.formats().advanced[i]); @@ -846,6 +858,38 @@ mod tests { assert_eq!(*app.layout.layers(), before); } + #[test] + fn crop_tab_owns_crop_mode_until_closed_including_pending_close() { + let ctx = egui::Context::default(); + let mut app = Editor { + property_tab: PropertyTab::Crop, + ..Default::default() + }; + app.format_draft = Some(FormatDraft::new(&app.layout, 1)); + frame(&mut app, &ctx, vec![]); + assert!(app.edit_content); + // Closing with pending edits stops crop mode while awaiting a decision. + let d = app.format_draft.as_mut().unwrap(); + d.size = [800.0, 450.0]; + d.closing = true; + frame(&mut app, &ctx, vec![]); + assert!(!app.edit_content); + click_text(&mut app, &ctx, "Discard"); + assert!(app.format_draft.is_none()); + assert!(!app.edit_content); + // Reopening the remembered Crop tab reactivates the tool. + app.format_draft = Some(FormatDraft::new(&app.layout, 1)); + frame(&mut app, &ctx, vec![]); + assert!(app.edit_content); + app.format_draft = None; + frame(&mut app, &ctx, vec![]); + assert!(!app.edit_content); + // Standalone crop editing still works without a properties window. + app.edit_content = true; + frame(&mut app, &ctx, vec![]); + assert!(app.edit_content); + } + #[test] fn unrelated_sync_preserves_source_draft_but_refreshes_clean_properties() { let mut app = Editor::default(); @@ -880,6 +924,7 @@ mod tests { ] { click_text(&mut app, &ctx, title); assert_eq!(app.property_tab, tab); + assert_eq!(app.edit_content, tab == PropertyTab::Crop); let output = frame(&mut app, &ctx, vec![]); let headings: Vec<_> = output .shapes diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index 71b9b77..5f5013f 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -70,6 +70,7 @@ pub struct Editor { property_tab: PropertyTab, output_draft: Option, edit_content: bool, + crop_tab_editing: bool, show_pattern: bool, show_toolbar_icon_names: bool, reference: Option, @@ -280,6 +281,7 @@ impl Default for Editor { property_tab: PropertyTab::default(), output_draft: None, edit_content: false, + crop_tab_editing: false, show_pattern: false, show_toolbar_icon_names: false, reference: None, @@ -1997,6 +1999,7 @@ impl Editor { (area.center() - center * scale + self.pan * scale, scale) } fn workspace(&mut self, ui: &mut egui::Ui) { + self.sync_crop_tab_mode(); let palette = theme::palette(ui.ctx()); let r = ui.max_rect(); let ink = Ink::new(ui, r); diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 2fcb3e6..67f8641 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -458,6 +458,10 @@ Moving/alignment preserves crops. Resizing keeps content zoom and the retained center where possible, automatically shifting the crop when needed to fit the new size. Source/input changes do the same when applied in Layer properties. No recentering or extra acceptance is needed. Undo restores both size and crop. +**Layer properties → Crop** activates visual crop editing while the tab is open. +Switching to Source/Layer or closing the window turns it off; no extra button is needed. +The standalone inspector and context-menu crop controls remain available. + **Adjust layer crop** changes the crop values inside the layer while keeping its visible box fixed; **Reset crop** returns to the minimum centered crop. diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index c9cdef3..9b685ed 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Layer properties’ Crop tab automatically enables visual crop editing and disables it on leaving/closing; remove its redundant toggle button. + - Ctrl/Pivot now works on crop/zoom handles, keeping the source pixel under the saved gravity point fixed; crop limits prevent empty borders. - Group grid snapping tools and snapping options in a toolbar dropdown; the label shows the active grid. Pivot remains independently accessible.