Files
craft-libs/crates/ui-widgets/tests/it/menu/mod.rs
T
aiongg cdb179df0b Menus taller than their room scroll by strips and the wheel; side overlays open upward
Scroll gets a strip indicator: arrows above and below the view that scroll while
the pointer rests on them, taking height from the view and never width. Menu and
inline menus use it, so every menu layer, the menu bar's included, scrolls in the
room it has. overlay::place opens a side overlay that runs past the bounds the
other way when it fits there, so a tall submenu of a low row opens upward.
2026-11-12 22:46:05 +00:00

53 lines
1.9 KiB
Rust

//! `Menu` and `MenuItem`: the columns of an inline menu's rows.
mod bar;
mod closed;
mod native;
mod openers;
mod overflow;
mod pick_focus;
mod rows;
mod submenus;
use craft_behavior::IconId;
use craft_ui::contract::{Show as _, ShowContainer as _};
use craft_ui::layout_components::Stack;
use craft_ui::menu::{Menu, MenuItem};
use craft_ui::primitives::IconSpec;
use craft_ui::testing::{Fixture, trial};
/// Regression: an inline menu inside a content-sized container shows by the record its container's measuring run
/// left, so its own body runs only for real; the rows before the first iconed or checked row still take the columns,
/// in every frame (a tab strip's overflow menu checks only the shown tab).
#[trial]
fn rows_of_an_inline_menu_shown_from_its_container_record_take_the_columns_of_later_rows() {
let mut fixture = Fixture::new(|ui| {
Stack::new().show(ui, |ui, _| {
Menu::inline("Tabs").show(ui, |ui, _| {
MenuItem::new("Layers").show(ui);
MenuItem::new("History").icon(IconSpec::svg(IconId::new("history"))).show(ui);
MenuItem::new("Swatches").check(true).show(ui);
});
});
});
let at = |fixture: &Fixture, label: &str| fixture.texts().iter().find(|text| text.text.replace('&', "") == label).map(|text| text.rect.left());
let mut frames = 0;
while at(&fixture, "Swatches").is_none() && frames < 8 {
fixture.frame(vec![]);
frames += 1;
}
let x = |fixture: &Fixture, label: &str| at(fixture, label).expect("the row is shown");
for frame in 0..3 {
assert_eq!(x(&fixture, "Layers"), x(&fixture, "Swatches"), "frame {frame}: a plain row takes the mark and icon columns");
assert_eq!(x(&fixture, "History"), x(&fixture, "Swatches"), "frame {frame}: an iconed row takes the mark column");
fixture.frame(vec![]);
}
}