diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 1684ad2b39..c79ca22470 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -2030,6 +2030,37 @@ fn description_line_rects(ctx: &egui::Context) -> DescriptionRects { DescriptionRects { column, line } } +/// Scrolls the field list with the wheel until the last text `label` in `texts` lies wholly inside +/// the list, above the spacing and the gap over the description line, and stays put there (the +/// wheel scrolls smoothly over several frames) → the texts of the last frame. +fn scroll_into_view(a: &mut VectorcraftApp, ctx: &egui::Context, mut texts: Vec<(String, egui::Rect)>, label: &str) -> Vec<(String, egui::Rect)> { + let wheel = egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: egui::vec2(0.0, -40.0), + phase: egui::TouchPhase::Move, + modifiers: Default::default(), + source: egui::MouseWheelSource::Unknown, + }; + let at = |texts: &[(String, egui::Rect)]| texts.iter().rev().find(|(t, _)| t == label).map(|(_, r)| *r); + let inside = |r: Option| { + let DescriptionRects { column, line } = description_line_rects(ctx); + let bottom = line.min.y - DESCRIPTION_GAP - ctx.global_style().spacing.item_spacing.y; + let list = egui::Rect::from_min_max(column.min, egui::pos2(column.max.x, bottom)); + r.is_some_and(|r| list.contains_rect(r)) + }; + for _ in 0..80 { + let shown = inside(at(&texts)); + let next = description_frame(a, ctx, if shown { vec![] } else { vec![wheel.clone()] }).0; + let still = shown && at(&next) == at(&texts); + texts = next; + if still { + break; + } + } + assert!(inside(at(&texts)), "`{label}` lies wholly inside the field list: {texts:?}"); + texts +} + /// A row with no sentence leaves the description line empty, also after another category's row /// was described, and the dialog keeps its size. #[test] @@ -2517,7 +2548,7 @@ fn hovering_a_plugins_and_scratch_disks_row_shows_its_description() { }; let rows = [ ("Additional Plug-ins Folder:", "pluginsFolder"), - ("Plug-in Instruction Budget", "pluginInstructionBudget"), + ("Plug-in Instruction", "pluginInstructionBudget"), ("Primary:", "scratchPrimary"), ("Secondary:", "scratchSecondary"), ]; @@ -2614,31 +2645,10 @@ fn hovering_a_user_interface_row_shows_its_description() { ("Language:", "interfaceLanguage"), ]; let sentences: Vec<_> = rows.iter().map(|(_, key)| descriptions::description(key).unwrap_or_else(|| panic!("`{key}` has a sentence"))).collect(); - // The Language row is under the bottom of the list: the wheel scrolls it wholly into view. - let wheel = egui::Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -40.0), - phase: egui::TouchPhase::Move, - modifiers: Default::default(), - source: egui::MouseWheelSource::Unknown, - }; + // The Language row is under the bottom of the list: the wheel scrolls it into view. let mut texts = texts; for (i, (label, _)) in rows.iter().enumerate() { - for _ in 0..20 { - if texts.iter().any(|(t, _)| t == label) { - break; - } - texts = whole_texts_frame(&mut a, &ctx, vec![wheel.clone()]); - } - // The wheel scrolls smoothly over several frames: wait until the row stays put. - for _ in 0..60 { - let next = description_frame(&mut a, &ctx, vec![]).0; - let still = row(&next, label) == row(&texts, label); - texts = next; - if still { - break; - } - } + texts = scroll_into_view(&mut a, &ctx, texts, label); description_frame(&mut a, &ctx, vec![egui::Event::PointerMoved(row(&texts, label))]); let (after, _) = description_frame(&mut a, &ctx, vec![]); for (j, sentence) in sentences.iter().enumerate() { @@ -2705,30 +2715,9 @@ fn hovering_a_performance_row_shows_its_description() { } let sentences: Vec<_> = rows.iter().map(|(_, key)| descriptions::description(key).unwrap_or_else(|| panic!("`{key}` has a sentence"))).collect(); // The last rows can be under the bottom of the list: the wheel scrolls them into view. - let wheel = egui::Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -40.0), - phase: egui::TouchPhase::Move, - modifiers: Default::default(), - source: egui::MouseWheelSource::Unknown, - }; let mut texts = texts; for (i, (label, _)) in rows.iter().enumerate() { - for _ in 0..20 { - if texts.iter().any(|(t, _)| t == label) { - break; - } - texts = description_frame(&mut a, &ctx, vec![wheel.clone()]).0; - } - // The wheel scrolls smoothly over several frames: wait until the row stays put. - for _ in 0..60 { - let next = description_frame(&mut a, &ctx, vec![]).0; - let still = row(&next, label) == row(&texts, label); - texts = next; - if still { - break; - } - } + texts = scroll_into_view(&mut a, &ctx, texts, label); description_frame(&mut a, &ctx, vec![egui::Event::PointerMoved(row(&texts, label))]); let (after, _) = description_frame(&mut a, &ctx, vec![]); for (j, sentence) in sentences.iter().enumerate() { @@ -2791,30 +2780,9 @@ fn hovering_a_file_handling_row_shows_its_description() { ]; let sentences: Vec<_> = rows.iter().map(|(_, key)| descriptions::description(key).unwrap_or_else(|| panic!("`{key}` has a sentence"))).collect(); // The last rows can be under the bottom of the list: the wheel scrolls them into view. - let wheel = egui::Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -40.0), - phase: egui::TouchPhase::Move, - modifiers: Default::default(), - source: egui::MouseWheelSource::Unknown, - }; let mut texts = texts; for (i, (label, _)) in rows.iter().enumerate() { - for _ in 0..20 { - if texts.iter().any(|(t, _)| t == label) { - break; - } - texts = description_frame(&mut a, &ctx, vec![wheel.clone()]).0; - } - // The wheel scrolls smoothly over several frames: wait until the row stays put. - for _ in 0..60 { - let next = description_frame(&mut a, &ctx, vec![]).0; - let still = row(&next, label) == row(&texts, label); - texts = next; - if still { - break; - } - } + texts = scroll_into_view(&mut a, &ctx, texts, label); description_frame(&mut a, &ctx, vec![egui::Event::PointerMoved(row(&texts, label))]); let (after, _) = description_frame(&mut a, &ctx, vec![]); for (j, sentence) in sentences.iter().enumerate() {