mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
ui-panels: a prompt with no default answer opens with no button focused, so Enter answers nothing
This commit is contained in:
@@ -130,11 +130,6 @@ fn default_answer(answers: &[FooterButton]) -> Option<usize> {
|
||||
default_position(answers).filter(|at| answers[*at].is_enabled())
|
||||
}
|
||||
|
||||
/// Whether the answers include a default one, available or not.
|
||||
fn has_default(answers: &[FooterButton]) -> bool {
|
||||
default_position(answers).is_some()
|
||||
}
|
||||
|
||||
type Below<'a> = Box<dyn FnMut(&mut Ui) + 'a>;
|
||||
|
||||
/// What a prompt shows under its message, in this order: a tone line, paragraphs, a list of lines, a collapsible
|
||||
@@ -268,9 +263,9 @@ impl<'a> Prompt<'a> {
|
||||
pub fn show(self, ui: &mut Ui) -> PromptOutput {
|
||||
let Prompt { title, message, answers, extras, open, escape, alert } = self;
|
||||
let (escape_at, enter_at) = (escape_answer(&answers, escape), default_answer(&answers));
|
||||
// A blocked default answer leaves focus off the buttons: landing on the first other one would let Enter answer
|
||||
// with it (Discard under a blocked Recover).
|
||||
let initial = if enter_at.is_none() && has_default(&answers) { Initial::Keep } else { Initial::Default };
|
||||
// With no available default answer (none, or a blocked one) focus stays off the buttons: landing on the first
|
||||
// other one would let Enter answer with it (Discard under a blocked Recover, Cancel in a job window).
|
||||
let initial = if enter_at.is_some() { Initial::Default } else { Initial::Keep };
|
||||
let mut dialog = Dialog::prompt(title).buttons(answers).initial_focus(initial).close_on_enter(enter_at.is_some());
|
||||
if alert {
|
||||
let env = Env::of(ui);
|
||||
|
||||
@@ -273,6 +273,26 @@ fn a_job_window_shows_again_for_the_next_job_after_cancel() {
|
||||
assert!(fixture.by_label("Exporting").is_some(), "the window shows for the next job");
|
||||
}
|
||||
|
||||
/// A prompt with no default answer (a job window's Cancel and Continue in Background) opens with no button focused, so
|
||||
/// Enter answers nothing; Escape still answers Cancel.
|
||||
#[trial]
|
||||
fn a_prompt_without_a_default_answer_opens_with_no_button_focused() {
|
||||
let answered = Rc::new(Cell::new(None));
|
||||
let got = Rc::clone(&answered);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
if let Some(answer) = JobProgress::new("Exporting", "Page 1 of 3").can_hide(true).show(ui).answer {
|
||||
got.set(Some(answer));
|
||||
}
|
||||
});
|
||||
fixture.idle(6);
|
||||
assert!(fixture.by_label("Continue in Background").is_some(), "the window has a second answer");
|
||||
assert_eq!(fixture.focused(), None, "no button has the focus");
|
||||
fixture.key(egui::Key::Enter, Modifiers::NONE).idle(2);
|
||||
assert_eq!(answered.get(), None, "Enter answers nothing");
|
||||
fixture.key(egui::Key::Escape, Modifiers::NONE).idle(2);
|
||||
assert_eq!(answered.get(), Some(JobAnswer::Cancel));
|
||||
}
|
||||
|
||||
const BAND: PartKey = PartKey::new("band");
|
||||
|
||||
/// A style with no look.
|
||||
|
||||
Reference in New Issue
Block a user