mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-20 17:06:42 +00:00
Crop: the Fill help keeps the crop's keys, and a cleared ratio side commits zero (#10888)
Three findings from the review of #11490. - A cleared ratio field with blank_when_zero now parses as zero instead of falling into the arithmetic hold, so deleting a side unsets it rather than restoring the old value. - The Fill help's info button remembers its rect, so Esc and Enter in the frame the help opens go to the help: the shortcut pass runs before the options bar draws, and Esc used to cancel the pending crop first. - Hiding the options bar (F twice, or Home) closes the Fill help, so its flag no longer keeps Enter and Esc away from the crop underneath. Tests in tests/it/crop_options_bar_chrome.rs; all three fail without the fixes.
This commit is contained in:
1 parent
851423af56
commit
72ed4e8303
5 files changed
+106
-4
No files matched your search
@@ -297,6 +297,9 @@ impl PhotocraftApp {
|
||||
let home = self.home_screen_up();
|
||||
if ((chrome && self.ui.panels.options_bar) || tabbed_in) && !home {
|
||||
panels::options_bar(self, ui);
|
||||
} else {
|
||||
// Its Fill help modal is gone with the bar: do not let a stale flag hold the crop's keys.
|
||||
panels::options_bar::close_fill_help(ui.ctx());
|
||||
}
|
||||
if chrome && self.ui.panels.status_bar && !home {
|
||||
panels::status_bar(self, ui);
|
||||
|
||||
@@ -819,7 +819,7 @@ fn handle_registry_and_tool_keys(app: &mut PhotocraftApp, ctx: &egui::Context, f
|
||||
// An open options bar popup (the Crop Ratio list, the overlay and gear menus) takes the keys
|
||||
// first: Esc closes it, and neither key reaches the crop beneath (#7386). Its id is kept in
|
||||
// memory from the last frame; `ctx.any_popup_open` only sees this frame's, drawn later.
|
||||
if (!app.ui.polygon.is_empty() || app.ui.crop_rect.is_some()) && !egui::Popup::is_any_open(ctx) && !crate::panels::options_bar::fill_help_open(ctx) {
|
||||
if (!app.ui.polygon.is_empty() || app.ui.crop_rect.is_some()) && !egui::Popup::is_any_open(ctx) && !crate::panels::options_bar::fill_help_takes_keys(ctx) {
|
||||
if pressed(Key::Enter) {
|
||||
if !app.ui.polygon.is_empty() {
|
||||
crate::canvas::commit_polygon(app);
|
||||
|
||||
@@ -15,6 +15,28 @@ pub(crate) fn fill_help_open(ctx: &egui::Context) -> bool {
|
||||
ctx.data(|d| d.get_temp::<bool>(fill_help_id())).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Where the Fill ⓘ was last drawn, so a click on it can take Escape in the frame the help opens
|
||||
/// (the shortcut pass runs before the options bar draws, #10888).
|
||||
fn fill_help_rect_id() -> egui::Id {
|
||||
egui::Id::NULL.with("crop-fill-help-rect")
|
||||
}
|
||||
|
||||
/// Whether the Fill help wants this frame's Enter and Escape: it is open, or its ⓘ is clicked in
|
||||
/// the frame the help opens, where Esc must not cancel the crop underneath.
|
||||
pub(crate) fn fill_help_takes_keys(ctx: &egui::Context) -> bool {
|
||||
if fill_help_open(ctx) {
|
||||
return true;
|
||||
}
|
||||
ctx.data(|d| d.get_temp::<egui::Rect>(fill_help_rect_id()))
|
||||
.is_some_and(|r| ctx.input(|i| i.pointer.any_click() && i.pointer.interact_pos().is_some_and(|p| r.contains(p))))
|
||||
}
|
||||
|
||||
/// Closes the Fill help when the options bar stops drawing: its flag would otherwise keep Enter and
|
||||
/// Escape away from the crop (#10888).
|
||||
pub(crate) fn close_fill_help(ctx: &egui::Context) {
|
||||
ctx.data_mut(|d| d.insert_temp(fill_help_id(), false));
|
||||
}
|
||||
|
||||
// Custom controls also need to bring keyboard focus into a scroll viewport.
|
||||
pub(super) fn reveal_focused_control(ui: &egui::Ui) {
|
||||
// read_response reprocesses pointer events. Reading a popup's newly focused field
|
||||
@@ -631,7 +653,9 @@ fn selection_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool:
|
||||
/// The Fill ⓘ button and the "Fill options" help modal it opens (#10888).
|
||||
fn crop_fill_help(ui: &mut egui::Ui) {
|
||||
let help_id = fill_help_id();
|
||||
if icons::button(ui, "info", 24.0, false, tl!("Displays pop-up help for the fill methods")).clicked() {
|
||||
let button = icons::button(ui, "info", 24.0, false, tl!("Displays pop-up help for the fill methods"));
|
||||
ui.data_mut(|d| d.insert_temp(fill_help_rect_id(), button.rect));
|
||||
if button.clicked() {
|
||||
ui.data_mut(|d| d.insert_temp(help_id, true));
|
||||
}
|
||||
if !ui.data(|d| d.get_temp::<bool>(help_id)).unwrap_or(false) {
|
||||
|
||||
@@ -543,10 +543,18 @@ fn number_edit(
|
||||
s.to_owned()
|
||||
};
|
||||
let s = ready.as_str();
|
||||
let v = if hold_typed { zoom_number(s, units) } else { parse_num_in(s, units) };
|
||||
// A cleared field that draws its zero blank means zero, not "keep what was there" (#10888).
|
||||
let blank = blank_when_zero && s.trim().is_empty();
|
||||
let v = if hold_typed {
|
||||
zoom_number(s, units)
|
||||
} else if blank {
|
||||
Some(0.0)
|
||||
} else {
|
||||
parse_num_in(s, units)
|
||||
};
|
||||
// Whether the text being typed is a number at all, for [`typed_text_parses`].
|
||||
ctx.data_mut(|d| d.insert_temp(id.with("parses"), v.is_some()));
|
||||
if ctx.memory(|m| m.has_focus(id)) && plain(s).is_none() {
|
||||
if ctx.memory(|m| m.has_focus(id)) && !blank && plain(s).is_none() {
|
||||
// Still typing arithmetic: hold it, and stop applying keystrokes once it parses.
|
||||
ctx.data_mut(|d| d.insert_temp(held, v.is_some()));
|
||||
return None;
|
||||
|
||||
@@ -132,6 +132,73 @@ fn crop_controls_carry_the_reference_tooltips() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clearing_a_blank_zero_field_commits_zero() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(120.0, 60.0)).with_max_steps(4).with_accessibility_check(false).build_ui_state(
|
||||
|ui, v: &mut f32| {
|
||||
photocraft_ui_egui::widgets::value_field_prec_blank(ui, v, 0.0..=99_999.0, "", 54.0, 3);
|
||||
},
|
||||
1.5f32,
|
||||
);
|
||||
h.run();
|
||||
h.get_by_role(egui::accesskit::Role::SpinButton).click();
|
||||
h.run_steps(2);
|
||||
// Select all and delete, as a user clearing a ratio side does.
|
||||
for (key, pressed, modifiers) in [
|
||||
(egui::Key::A, true, egui::Modifiers::COMMAND),
|
||||
(egui::Key::A, false, egui::Modifiers::COMMAND),
|
||||
(egui::Key::Backspace, true, egui::Modifiers::NONE),
|
||||
(egui::Key::Backspace, false, egui::Modifiers::NONE),
|
||||
] {
|
||||
h.event(egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers });
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert_eq!(*h.state(), 0.0, "a cleared side is zero, not the value it had");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hiding_the_options_bar_releases_the_fill_help() {
|
||||
let mut h = app();
|
||||
h.run_steps(4);
|
||||
photocraft_ui_egui::crop_ui::ensure_frame(h.state_mut());
|
||||
photocraft_ui_egui::crop_ui::nudge(h.state_mut(), 1.0, 0.0);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Displays pop-up help for the fill methods").click();
|
||||
h.run_steps(2);
|
||||
assert!(drawn(&h).iter().any(|t| t == "Fill options"), "the help opened");
|
||||
|
||||
// F hides the chrome and with it the bar; the help goes too and must not keep the crop's keys.
|
||||
h.state_mut().ui.panels.options_bar = false;
|
||||
h.run_steps(2);
|
||||
assert!(!drawn(&h).iter().any(|t| t == "Fill options"), "the modal goes with the bar");
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().ui.crop_rect.is_none(), "Enter commits the crop again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn esc_in_the_frame_the_fill_help_opens_leaves_the_crop() {
|
||||
let mut h = app();
|
||||
h.run_steps(4);
|
||||
photocraft_ui_egui::crop_ui::ensure_frame(h.state_mut());
|
||||
photocraft_ui_egui::crop_ui::nudge(h.state_mut(), 1.0, 0.0);
|
||||
h.run_steps(2);
|
||||
let before = h.state().ui.crop_rect;
|
||||
|
||||
// Esc and the click on the Fill ⓘ land in one frame: the shortcut pass runs first, so the click
|
||||
// must claim Esc before it cancels the crop underneath.
|
||||
let at = h.get_by_label("Displays pop-up help for the fill methods").rect().center();
|
||||
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
|
||||
h.input_mut().events.extend([
|
||||
egui::Event::PointerMoved(at),
|
||||
egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE },
|
||||
button(true),
|
||||
button(false),
|
||||
]);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.crop_rect, before, "the crop frame and its history survive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_free_ratio_sides_draw_nothing_at_zero() {
|
||||
fn field(value: f32) -> Vec<String> {
|
||||
|
||||
Reference in new issue
Block a user