mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #16110: Clear pending Crop state after canvas Enter
This commit is contained in:
commit
ff602e1977
4 files changed
+56
-11
No files matched your search
@@ -21,7 +21,7 @@ pub(crate) fn show_frame(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: egui:
|
||||
Some(app.canvas_tools.crop.tool.show_frame(ui, rect, &run.input(&ctx)))
|
||||
}
|
||||
|
||||
/// Applies what the pass reported to the document and the crop options.
|
||||
pub(crate) fn finish(app: &mut PhotocraftApp, output: CropOutput) {
|
||||
crate::crop_ui::finish(app, output);
|
||||
/// Applies what the pass reported while the live Crop tool is still held by the canvas rig.
|
||||
pub(crate) fn finish(app: &mut PhotocraftApp, tool: &mut CropTool, output: CropOutput) {
|
||||
crate::crop_ui::finish(app, tool, output);
|
||||
}
|
||||
@@ -670,7 +670,7 @@ fn with_rig<R>(
|
||||
if let Some(tool) = crop_tool {
|
||||
tools.crop.tool = tool;
|
||||
}
|
||||
crop::finish(app, output);
|
||||
crop::finish(app, &mut tools.crop.tool, output);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
@@ -65,10 +65,14 @@ pub(crate) fn document(app: &PhotocraftApp) -> Option<CropDocument> {
|
||||
Some(CropDocument::new(CropDocKey::new(st.doc.id.0), size, f64::from(st.doc.resolution_dpi)).selection(bounds))
|
||||
}
|
||||
|
||||
/// Maps what a pass of the tool reported to the app.
|
||||
pub(crate) fn finish(app: &mut PhotocraftApp, output: CropOutput) {
|
||||
/// Maps what a canvas pass reported and acknowledges the crop on the tool that emitted it.
|
||||
pub(crate) fn finish(app: &mut PhotocraftApp, tool: &mut CropTool, output: CropOutput) {
|
||||
for event in output.events {
|
||||
handle_event(app, event);
|
||||
if let CropEvent::Apply(commit) = event {
|
||||
tool.applied(apply_commit(app, &commit));
|
||||
} else {
|
||||
handle_event(app, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +126,11 @@ pub(crate) fn toggle_straighten(app: &mut PhotocraftApp) {
|
||||
/// Runs one event of the tool. True for an `Apply` that cropped the document.
|
||||
pub(super) fn handle_event(app: &mut PhotocraftApp, event: impl Into<Option<CropEvent>>) -> bool {
|
||||
match event.into() {
|
||||
Some(CropEvent::Apply(commit)) => apply_commit(app, &commit),
|
||||
Some(CropEvent::Apply(commit)) => {
|
||||
let accepted = apply_commit(app, &commit);
|
||||
app.canvas_tools.crop.tool.applied(accepted);
|
||||
accepted
|
||||
}
|
||||
Some(CropEvent::Discard(key)) => {
|
||||
upright_view(app, key);
|
||||
false
|
||||
@@ -137,7 +145,7 @@ pub(super) fn handle_event(app: &mut PhotocraftApp, event: impl Into<Option<Crop
|
||||
}
|
||||
}
|
||||
|
||||
/// `image.crop` for `commit`; the tool is told whether the document took it.
|
||||
/// Runs `image.crop` for `commit` and returns whether the document accepted it.
|
||||
fn apply_commit(app: &mut PhotocraftApp, commit: &CropCommit) -> bool {
|
||||
let rect = commit.frame.rect;
|
||||
let px = |v: f64| v.round().max(1.0) as u64;
|
||||
@@ -164,13 +172,11 @@ fn apply_commit(app: &mut PhotocraftApp, commit: &CropCommit) -> bool {
|
||||
if let Some(view) = app.session.active_index().and_then(|i| app.ui.views.get_mut(i)) {
|
||||
view.place(craft::ui::canvas::ViewCommands::FitOnScreen);
|
||||
}
|
||||
app.canvas_tools.crop.tool.applied(true);
|
||||
true
|
||||
}
|
||||
Err(error) => {
|
||||
app.ui.status = error;
|
||||
app.ui.status_error = true;
|
||||
app.canvas_tools.crop.tool.applied(false);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +176,44 @@ fn the_bars_preset_dropdown_is_the_options_bars() {
|
||||
assert_eq!(h.get_all_by_value("1 : 1 (Square)").count(), 2, "the options bar shows the same preset");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_options_bar_ratio_list_takes_escape_and_enter_before_the_crop() {
|
||||
let mut h = harness();
|
||||
control(&mut h, "ui.set", json!({"panels": {"context_task_bar": false}}));
|
||||
draw_frame(&mut h, [100.0, 50.0], [300.0, 250.0]);
|
||||
assert!(pending(h.state()), "the drawn square crop is pending");
|
||||
let before = frame_rect(&h).expect("the pending frame");
|
||||
let size = |h: &Harness| h.state().session.active().map(|s| (s.doc.size.width, s.doc.size.height));
|
||||
let history = |h: &Harness| h.state().session.active().expect("the crop document").history.past_len();
|
||||
let steps = history(&h);
|
||||
let square = "1 : 1 (Square)";
|
||||
|
||||
// Escape dismisses the list. Enter accepts its first row, the selected free Ratio.
|
||||
// Neither key should reach the pending crop while the list is open (#7386).
|
||||
for key in [egui::Key::Escape, egui::Key::Enter] {
|
||||
assert!(!has(&h, square), "the square row is only in the open list");
|
||||
let at = h.get_by_value("Ratio").rect().center();
|
||||
click_at(&mut h, at);
|
||||
assert!(has(&h, square), "the options bar ratio list opened");
|
||||
h.key_press(key);
|
||||
h.run_steps(12);
|
||||
assert!(!has(&h, square), "{key:?} closed the ratio list");
|
||||
assert!(pending(h.state()), "{key:?} left the crop pending");
|
||||
assert_eq!(frame_rect(&h), Some(before), "{key:?} left the frame alone");
|
||||
assert_eq!(size(&h), Some((400, 300)), "{key:?} did not crop the document");
|
||||
}
|
||||
|
||||
// A closed dropdown still has focus. Click inside the frame to return focus to the canvas.
|
||||
let at = h.state().last_canvas_rect.center();
|
||||
click_at(&mut h, at);
|
||||
assert_eq!(frame_rect(&h), Some(before), "the click only moved focus");
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(6);
|
||||
assert_eq!(size(&h), Some((200, 200)), "Enter on the canvas commits the pending crop");
|
||||
assert_eq!(history(&h), steps + 1, "Enter adds one document history step");
|
||||
assert!(!pending(h.state()), "Enter clears the pending Crop session once the document accepts the crop");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspect_reports_a_bar_hidden_before_the_next_draw_as_hidden() {
|
||||
let mut h = harness();
|
||||
@@ -244,6 +282,7 @@ fn cancel_and_done_only_while_a_crop_is_pending() {
|
||||
let at = widget(&h, "Done");
|
||||
click_at(&mut h, at);
|
||||
assert_eq!(h.state().session.active().map(|s| (s.doc.size.width, s.doc.size.height)), Some((220, 170)), "Done crops");
|
||||
assert!(!pending(h.state()), "Done also clears the pending Crop session");
|
||||
}
|
||||
|
||||
/// The active document's stored zoom.
|
||||
|
||||
Reference in new issue
Block a user