mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
ui-contract: tests follow the contract (held buttons, wheel share, surface, held keys)
This commit is contained in:
@@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
|
||||
pub use crate::runtime::egui::fixture::{FullOutput, RawInput, dragged_id, record_input_hooks};
|
||||
|
||||
pub use craft_window::system::{FakeSystem, NoWindows};
|
||||
pub use craft_window::system::{FakeSystem, HeldButtons, NoWindows};
|
||||
|
||||
/// An install spec for the running build's shell and a system with no OS services, with the stories' command sets.
|
||||
pub fn install_spec() -> InstallSpec {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The click on a container's own surface: it reports in the pass of its primary release.
|
||||
|
||||
use craft_behavior::Sense;
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::layout::Block;
|
||||
use craft_ui::testing::{Frames, pointer, trial};
|
||||
@@ -13,13 +13,18 @@ const PROBE: Vec2 = Vec2::new(40.0, 40.0);
|
||||
const BLOCK: Vec2 = Vec2::new(100.0, 60.0);
|
||||
|
||||
/// What the shown container leaves for the trial to read.
|
||||
#[derive(Default)]
|
||||
struct Shown {
|
||||
rect: Cell<Rect>,
|
||||
clicked: Cell<bool>,
|
||||
seen: RefCell<Seen>,
|
||||
}
|
||||
|
||||
impl Default for Shown {
|
||||
fn default() -> Self {
|
||||
Shown { rect: Cell::new(Rect::ZERO), clicked: Cell::default(), seen: RefCell::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Shown {
|
||||
/// A panel that senses its surface, with a child that takes clicks above a block that senses nothing.
|
||||
fn show(&self, ui: &mut Ui) {
|
||||
@@ -28,7 +33,7 @@ impl Shown {
|
||||
Probe::new(&self.seen).size(PROBE).sense(Sense::CLICK).show(ui);
|
||||
Block::new(BLOCK).show(ui);
|
||||
});
|
||||
self.rect.set(out.response.rect);
|
||||
self.rect.set(out.output.rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Touch fingers: the multi-finger tap, the modal gate, the second finger that ends a press and the two-finger pan.
|
||||
|
||||
use craft_behavior::{PressCancel, PressPhase, Sense, WheelTaker};
|
||||
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, ShowContainer as _};
|
||||
use craft_ui::style::StyleCx;
|
||||
use craft_ui::testing::pointer;
|
||||
use craft_ui::testing::sensing::{ProbeRoot, show};
|
||||
use craft_ui::testing::wheel::{register, take};
|
||||
use craft_ui::testing::wheel::{register, take_share};
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use craft_ui_test_kit::contract::PlainStyle;
|
||||
use egui::{Event, Id, Pos2, Rect, Response, TouchPhase, Ui, Vec2};
|
||||
@@ -176,7 +176,7 @@ fn a_second_finger_cancels_an_open_press_and_two_fingers_moving_together_give_th
|
||||
let mut show_taker = move |ui: &mut Ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
register(&ctx, WheelTaker::new(id, Rect::from_min_size(Pos2::ZERO, Vec2::splat(400.0))).horizontal(true).vertical(true).zoom(true));
|
||||
if let Some(wheel) = take(&ctx, id) {
|
||||
if let Some(wheel) = take_share(&ctx, id) {
|
||||
sink.borrow_mut().push(wheel.touch_pan);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -252,7 +252,7 @@ fn a_wheel_over_an_open_popup_goes_to_the_popup_and_not_to_the_region_under_it()
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show_frame);
|
||||
pointer::click(&mut frames, Pos2::new(50.0, 10.0), &mut show_frame);
|
||||
let mut wheel_at = |frames: &mut Frames, at: Pos2, show_frame: &mut dyn FnMut(&mut Ui)| -> Vec<Id> {
|
||||
let wheel_at = |frames: &mut Frames, at: Pos2, show_frame: &mut dyn FnMut(&mut Ui)| -> Vec<Id> {
|
||||
frames.frame(vec![pointer::moved(at)], &mut *show_frame);
|
||||
shares.borrow_mut().clear();
|
||||
frames.frame(vec![pointer::wheel(-30.0)], &mut *show_frame);
|
||||
|
||||
@@ -706,7 +706,7 @@ fn a_key_held_by_automation_reads_as_held() {
|
||||
for _ in 0..3 {
|
||||
frame();
|
||||
}
|
||||
assert_eq!(*seen.borrow(), [egui::Key::A], "the held key reads as down");
|
||||
assert_eq!(*seen.borrow(), [Key::A], "the held key reads as down");
|
||||
host.inject_let_go(ViewportId::ROOT, Key::A);
|
||||
for _ in 0..3 {
|
||||
frame();
|
||||
|
||||
Reference in New Issue
Block a user