mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Perspective Crop: the options bar's Cancel and Commit show only during a session (#11978)
This commit is contained in:
1 parent
e6ba4aca42
commit
321e306a8f
2 files changed
+80
No files matched your search
@@ -0,0 +1,72 @@
|
||||
//! #11978: the Perspective Crop options bar shows its Cancel and Commit buttons only during a
|
||||
//! session (a quad, or corners being clicked), and they still commit and cancel.
|
||||
|
||||
use egui::vec2;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
const COMMIT: &str = "Commit current crop operation";
|
||||
const CANCEL: &str = "Cancel current crop operation";
|
||||
|
||||
/// A 200 × 150 document with the Perspective Crop tool chosen and no session.
|
||||
fn app() -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 150})).unwrap();
|
||||
app.ui.tool = Tool::PerspectiveCrop;
|
||||
app
|
||||
}
|
||||
|
||||
fn harness(app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {
|
||||
let mut h = Harness::builder().with_size(vec2(1400.0, 80.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
return;
|
||||
}
|
||||
crate::panels::options_bar(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio);
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn shows(h: &Harness<'static, PhotocraftApp>, label: &str) -> bool {
|
||||
h.query_by_label_contains(label).is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_session_neither_button_shows() {
|
||||
let h = harness(app());
|
||||
assert!(!shows(&h, COMMIT) && !shows(&h, CANCEL));
|
||||
assert!(h.query_by_label("Show Grid").is_some(), "the bar still ends with Show Grid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pending_quad_shows_both_and_commit_commits() {
|
||||
let mut app = app();
|
||||
app.ui.perspective_crop = Some([[20.0, 20.0], [180.0, 20.0], [180.0, 130.0], [20.0, 130.0]]);
|
||||
let mut h = harness(app);
|
||||
assert!(shows(&h, COMMIT) && shows(&h, CANCEL));
|
||||
h.get_by_label_contains(COMMIT).click();
|
||||
h.run_steps(3);
|
||||
let size = h.state().session.active().unwrap().doc.size;
|
||||
assert_eq!((size.width, size.height), (160, 110), "Commit cropped to the quad");
|
||||
assert!(!shows(&h, COMMIT) && !shows(&h, CANCEL), "gone after commit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicked_corners_show_both_and_cancel_cancels() {
|
||||
let mut app = app();
|
||||
app.pcrop.clicks = vec![[20.0, 20.0], [180.0, 25.0]];
|
||||
let mut h = harness(app);
|
||||
assert!(shows(&h, COMMIT) && shows(&h, CANCEL), "with clicked corners");
|
||||
h.get_by_label_contains(CANCEL).click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().pcrop.clicks.is_empty(), "Cancel dropped the corners");
|
||||
assert_eq!(h.state().session.active().unwrap().doc.size.width, 200, "nothing cropped");
|
||||
assert!(!shows(&h, COMMIT) && !shows(&h, CANCEL), "gone after cancel");
|
||||
}
|
||||
@@ -305,6 +305,10 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
crate::widgets::vline(ui, 22.0);
|
||||
crate::widgets::checkbox(ui, &mut app.ui.tool_options.perspective_crop_grid, tl!("Show Grid"));
|
||||
// Commit and Cancel show only during a session: a quad, clicked corners, or a drag (#11978).
|
||||
if !pending(app) {
|
||||
return;
|
||||
}
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let commit_tip = crate::i18n::fmt(tl!("Commit current crop operation ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))]);
|
||||
if crate::icons::button(ui, "check", 26.0, false, &commit_tip).clicked() {
|
||||
@@ -316,6 +320,10 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "perspective_crop_bar_buttons_tests.rs"]
|
||||
mod perspective_crop_bar_buttons_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user