Port trials follow upstream's APIs: the guides rig without a body rect, in-place tidy and English names on the menu model, page-aware document points

This commit is contained in:
bflatastic
2026-11-22 01:53:46 +07:00
parent 5e71eb0e3c
commit 4a76442e8f
3 changed files with 18 additions and 21 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ impl Rig {
/// Sends `method`; when it is accepted, runs frames until the host has processed the input.
fn send(&mut self, method: &str, params: Value) -> Result<(), String> {
input_method(method, &params, &self.host, ViewportId::ROOT, &|_| None).expect("an input method")?;
input_method(method, &params, &self.host, ViewportId::ROOT, &|_, _| None).expect("an input method")?;
for _ in 0..32 {
self.fx.frame(Vec::new());
if self.host.injected_idle() {
+12 -16
View File
@@ -1,7 +1,8 @@
//! A heading is a caption over the rows after it: structure, never a command.
use craft_host::target::Os;
use craft_menu::{CommandRef, Item, Labeled, LayoutOptions, Menu, MenuBar, MenuBarUi, Node, Target, tidy};
use craft_menu::{Item, LayoutOptions, Menu, MenuBar, MenuBarUi, Node, Target, tidy};
use craft_ui::contract::Tracked;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers};
@@ -12,36 +13,31 @@ use crate::sample::ids;
/// they are and runs nothing when clicked.
#[trial]
fn a_heading_is_structure_and_never_a_command() {
let nodes = tidy(vec![
let mut nodes = vec![
Node::heading("最近"),
Item::new("file.new", "新建").into(),
Item::new("file.open", "打开").into(),
Item::new("file.new", "新建").english("New").into(),
Item::new("file.open", "打开").english("Open").into(),
Node::Separator,
Node::heading("Empty"),
Node::Separator,
Item::new("file.close", "关闭").into(),
Item::new("file.close", "关闭").english("Close").into(),
Node::heading("Trailing"),
]);
];
tidy(&mut nodes);
assert_eq!(
ids(&nodes),
["#最近", "file.new", "file.open", "---", "file.close"],
"a heading with no item after it goes, and the separators it leaves collapse"
);
let bar = MenuBar::new(vec![Menu::new("文件", nodes)]);
let entries = bar.help_entries(Target::Linux, &LayoutOptions::new("Trial"), None);
let bar = MenuBar::new(vec![Menu::new("文件", nodes).english("File")]);
let entries = bar.help_entries(Target::Linux, &LayoutOptions::new("Trial"));
let listed: Vec<String> = entries.iter().map(|entry| entry.command().key()).filter(|key| key.starts_with("file.")).collect();
assert_eq!(listed, ["file.new", "file.open", "file.close"], "the help search lists the items, never the heading");
let english = |labeled: Labeled<'_>| match labeled {
Labeled::Title("文件") => Some("File".to_owned()),
Labeled::Command(command) if *command == CommandRef::new("file.new") => Some("New".to_owned()),
Labeled::Command(command) if *command == CommandRef::new("file.open") => Some("Open".to_owned()),
Labeled::Command(command) if *command == CommandRef::new("file.close") => Some("Close".to_owned()),
_ => None,
};
let bar = Tracked::new(bar);
let mut fixture = Fixture::new(move |ui| {
MenuBarUi::new(&bar).english(&english).show(ui);
MenuBarUi::new(&bar).show(ui);
});
// A Mac bar has no letters.
fixture.os(Os::Linux);
@@ -235,9 +235,10 @@ fn a_dragged_guide_is_removed_off_the_bounds_or_on_a_ruler_and_alt_and_shift_cha
fn a_double_press_on_a_ruler_places_a_guide_at_once() {
let placed = |mods: Modifiers, at: &dyn Fn(Rect) -> Pos2| -> Vec<Guide> {
let guides: Shared<Vec<Guide>> = Rc::new(RefCell::new(Vec::new()));
let (mut fixture, body) = ruled(1.0, &guides);
let mut fixture = ruled(1.0, &guides);
let rect = fixture.canvas().rect;
fixture.fixture().hold(mods);
fixture.double_press_at(at(body.get()));
fixture.double_press_at(at(rect));
fixture.fixture().hold(Modifiers::NONE);
let placed = guides.borrow().clone();
placed
@@ -257,8 +258,8 @@ fn a_double_press_on_a_ruler_places_a_guide_at_once() {
assert!(placed(Modifiers::ALT, &top(650.0)).is_empty(), "a double press outside the bounds adds none");
let guides: Shared<Vec<Guide>> = Rc::new(RefCell::new(Vec::new()));
let (mut fixture, body) = ruled(1.0, &guides);
let rect = body.get();
let mut fixture = ruled(1.0, &guides);
let rect = fixture.canvas().rect;
drag_with(&mut fixture, Modifiers::NONE, pos2(300.0, rect.min.y + 4.0), pos2(300.0, 247.6));
assert_eq!(guides.borrow().len(), 1, "a press and drag out of a strip adds exactly one guide: {:?}", guides.borrow());
}