Merge branch 'red/t10' into fw/mac1

This commit is contained in:
aiongg
2026-11-16 22:47:46 +00:00
2 changed files with 63 additions and 0 deletions
+21
View File
@@ -160,6 +160,27 @@ fn a_press_on_the_first_anchor_closes_the_path_on_release_with_or_without_a_drag
assert_eq!(done.knots.len(), 3, "no anchor added");
}
// Over the first anchor of an open draft the Pen's cursor carries the close badge (#4596); over the last anchor and
// over empty canvas it does not.
#[trial]
fn the_cursor_has_the_close_badge_only_over_the_first_anchor() {
use craft_behavior::{Cursor, CursorBadge, PaintedCursor};
let mut pen = Pen::three();
let mut badge_at = |x: f64, y: f64| {
let at = pen.at(x, y);
pen.move_to(at, Modifiers::NONE);
pen.fixture.fixture().frame(Vec::new());
match craft_ui::runtime::cursor::current(pen.fixture.fixture().ctx()) {
Some(Cursor::Painted(PaintedCursor::Tool { badge, .. })) => badge,
other => panic!("the Pen shows its own cursor: {other:?}"),
}
};
assert_eq!(badge_at(60.0, 60.0), Some(CursorBadge::Close), "over the first anchor");
assert_eq!(badge_at(300.0, 250.0), None, "over empty canvas");
assert_eq!(badge_at(160.0, 160.0), None, "the last anchor does not close");
assert_eq!(badge_at(60.0, 60.0), Some(CursorBadge::Close), "back on the first anchor");
}
#[trial]
fn remove_last_waits_for_a_press_that_is_still_down() {
let mut pen = Pen::three();
@@ -129,3 +129,45 @@ fn a_new_guide_remembers_its_confirmed_values_for_the_next_open() {
reopen(&mut fixture);
assert_eq!(*values.borrow(), NewGuideValues::new(Axis::Y, typed, GuideColor::Magenta), "Cancel stored nothing: the OK'd values come back");
}
/// Position text that does not parse keeps OK from making a guide at the last good position: nothing is made and the
/// dialog stays open until the text is a number.
#[trial]
fn position_text_that_does_not_parse_keeps_ok_from_making_a_guide() {
let open = Rc::new(Cell::new(true));
let made: Rc<RefCell<Vec<Guide>>> = Rc::default();
let enabled = Rc::new(Cell::new(true));
let (opened, seen, ok_seen) = (Rc::clone(&open), Rc::clone(&made), Rc::clone(&enabled));
let mut values = NewGuideValues::new(Axis::X, 30.0, GuideColor::Magenta);
let mut fixture = Fixture::new(move |ui| {
let units = GuideUnits::new(UnitKind::Pixels, 3000.0, 2000.0, 300.0);
let mut is_open = opened.get();
let shown = NewGuideDialog::new(units, Bind::bound(&mut values)).opened(Bind::bound(&mut is_open)).show(ui);
opened.set(is_open);
ok_seen.set(shown.ok_enabled);
seen.borrow_mut().extend(shown.result);
});
fixture.settle();
let position = fixture.by_label("Position").expect("the Position field");
fixture.click(&position).settle();
fixture.key(egui::Key::A, egui::Modifiers::COMMAND);
fixture.type_text("far");
fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle();
assert!(!enabled.get(), "OK is disabled while the text does not parse");
let ok = fixture.by_label("OK").expect("the footer has OK");
fixture.click(&ok).settle();
assert!(open.get(), "the dialog stays open");
assert!(made.borrow().is_empty(), "no guide is made at the last good position");
let position = fixture.by_label("Position").expect("the Position field");
fixture.click(&position).settle();
fixture.key(egui::Key::A, egui::Modifiers::COMMAND);
fixture.type_text("40");
fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle();
assert!(enabled.get(), "a number enables OK again");
let ok = fixture.by_label("OK").expect("the footer has OK");
fixture.click(&ok).settle();
assert!(!open.get(), "OK closes the dialog");
let confirmed: Vec<_> = made.borrow().iter().map(|guide| guide.position).collect();
assert_eq!(confirmed, [40.0]);
}