mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 19:36:16 +00:00
Merge pull request #9341 from dotCooCoo/fix/learn-reopen-click
Learn: a click or Enter on the skill or tutorial opened before opens it again
This commit is contained in:
@@ -73,10 +73,12 @@ fn run(app: &mut VectorcraftApp, cmd: &str, params: Value) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The key a collection's last selection change set, if any: a click on a row or a tab.
|
||||
/// The key a collection's last pick chose, if any: a click on a row or a tab, a click on the row or tab already
|
||||
/// selected, or Enter on one.
|
||||
fn picked<K, E>(events: Vec<CollectionEvent<K, E>>) -> Option<K> {
|
||||
events.into_iter().rev().find_map(|event| match event {
|
||||
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => keys.into_iter().last(),
|
||||
CollectionEvent::Picked { key, .. } | CollectionEvent::Activate(key) => Some(key),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -158,8 +160,6 @@ fn skill_list(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let rings: Vec<(&'static catalog::Skill, SkillRing)> =
|
||||
catalog::SKILLS.iter().map(|s| (s, SkillRing { done: progress.done(s), total: s.tutorials.len() })).collect();
|
||||
let source = keyed(&keys, |key: &&'static str| *key);
|
||||
// PLAN: a single-select list keeps its last pick highlighted and reports no change when the same key is
|
||||
// picked again; the keys differ between the levels, but the list is the framework's to reset on a new view.
|
||||
// A few skills: the list is as tall as its rows, so Reset progress shows under them.
|
||||
let out = List::new(tl!("Skills")).select(SelectMode::Single).natural_height(true).show_items(ui, &source, &mut |key, _| {
|
||||
let row = ListRow::new(*key);
|
||||
|
||||
@@ -400,6 +400,55 @@ fn the_tabs_rows_and_back_run_their_commands() {
|
||||
press(&mut app, "Back", View { tab: Tab::Skills, skill: None, tutorial: None });
|
||||
}
|
||||
|
||||
/// A click on the skill or the tutorial that was opened before, after Back, opens it again.
|
||||
#[test]
|
||||
fn a_click_on_the_skill_or_tutorial_opened_before_opens_it_again() {
|
||||
let mut app = app();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let (skill, tutorial) = catalog::tutorial("gradient").unwrap();
|
||||
let open_skill = View { tab: Tab::Skills, skill: Some(skill.id), tutorial: None };
|
||||
let open_tutorial = View { tutorial: Some(tutorial.id), ..open_skill.clone() };
|
||||
let skills = View { tab: Tab::Skills, skill: None, tutorial: None };
|
||||
for (name, view) in [
|
||||
("Skills", skills.clone()),
|
||||
(skill.title, open_skill.clone()),
|
||||
(tutorial.title, open_tutorial.clone()),
|
||||
("Back", open_skill.clone()),
|
||||
(tutorial.title, open_tutorial.clone()),
|
||||
("Back", open_skill.clone()),
|
||||
("Back", skills.clone()),
|
||||
(skill.title, open_skill.clone()),
|
||||
] {
|
||||
click(&mut app, &ctx, name, show);
|
||||
assert_eq!(app.ui.learn, view, "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Enter on the tutorial that was opened before, after Back and Tab into the list, opens it again.
|
||||
#[test]
|
||||
fn enter_on_the_tutorial_opened_before_opens_it_again() {
|
||||
let mut app = app();
|
||||
let ctx = app.ui_ctx.clone().expect("a window");
|
||||
let (_, tutorial) = catalog::tutorial("gradient").unwrap();
|
||||
app.run("learn.show", json!({"tutorial": tutorial.id})).unwrap();
|
||||
let opened = app.ui.learn.clone();
|
||||
let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
|
||||
click(&mut app, &ctx, "Back", show);
|
||||
click(&mut app, &ctx, tutorial.title, show);
|
||||
assert_eq!(app.ui.learn, opened, "a click opens it");
|
||||
click(&mut app, &ctx, "Back", show);
|
||||
let focused = |app: &mut VectorcraftApp, events| {
|
||||
let input = egui::RawInput { events, screen_rect: Some(SCREEN), ..Default::default() };
|
||||
let update = crate::testing::part_frame(app, &ctx, input, show).platform_output.accesskit_update?;
|
||||
update.nodes.into_iter().find(|(id, _)| *id == update.focus).and_then(|(_, n)| n.label().map(str::to_owned))
|
||||
};
|
||||
let on_row = (0..10).any(|_| focused(&mut app, vec![key(egui::Key::Tab)]).as_deref() == Some(tutorial.title));
|
||||
assert!(on_row, "Tab reaches the tutorial's row");
|
||||
frame(&mut app, &ctx, vec![key(egui::Key::Enter)], show);
|
||||
frame(&mut app, &ctx, vec![], show);
|
||||
assert_eq!(app.ui.learn, opened, "Enter opens it");
|
||||
}
|
||||
|
||||
/// `learn.tab` switches tabs and keeps what the Skills tab had open; `learn.skill` opens a skill's
|
||||
/// tutorials and answers the skill as `learn.list` lists it; `learn.back` goes up one level and
|
||||
/// keeps the view on the list of skills and on the For you tab.
|
||||
|
||||
Reference in New Issue
Block a user