S003: shots press and hover at 60 Hz

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-25 00:28:42 -06:00
commit 60142de6ee

View file

@ -35,7 +35,7 @@ fn sources() -> Sources {
fn harness(scene: Scene, appearance: Appearance, size: (f32, f32)) -> Harness<'static> { fn harness(scene: Scene, appearance: Appearance, size: (f32, f32)) -> Harness<'static> {
let mut app = None; let mut app = None;
Harness::builder().with_size(vec2(size.0, size.1)).wgpu().build_ui(move |ui| { Harness::builder().with_size(vec2(size.0, size.1)).with_step_dt(1.0 / 60.0).wgpu().build_ui(move |ui| {
if app.is_none() { if app.is_none() {
// Fonts count from the next frame. // Fonts count from the next frame.
app = Some(App::new(ui.ctx(), settings(appearance), sources())); app = Some(App::new(ui.ctx(), settings(appearance), sources()));
@ -59,17 +59,17 @@ fn shots() {
for (mode, appearance) in [("light", Appearance::Light), ("dark", Appearance::Dark)] { for (mode, appearance) in [("light", Appearance::Light), ("dark", Appearance::Dark)] {
for size in sizes.split(',') { for size in sizes.split(',') {
let mut h = harness(*scene, appearance, pair(size, 'x').expect("SIZES=WxH,WxH")); let mut h = harness(*scene, appearance, pair(size, 'x').expect("SIZES=WxH,WxH"));
// The pointer meets what the last frame drew.
h.run_steps(2);
if let Some((x, y)) = hover { if let Some((x, y)) = hover {
let at = pos2(x, y); h.input_mut().events.push(Event::PointerMoved(pos2(x, y)));
h.input_mut().events.push(Event::PointerMoved(at));
h.step();
if std::env::var_os("PRESS").is_some() {
let press = Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE };
h.input_mut().events.push(press);
}
} }
for _ in 0..60 { h.run_steps(60);
h.step(); if let Some((x, y)) = hover.filter(|_| std::env::var_os("PRESS").is_some()) {
let pos = pos2(x, y);
h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
// egui gives up on a click held for 0.8 s.
h.run_steps(30);
} }
if let Some(dir) = &out { if let Some(dir) = &out {
h.render().expect("render").save(format!("{dir}/{}-{mode}-{size}.png", scene.0)).unwrap(); h.render().expect("render").save(format!("{dir}/{}-{mode}-{size}.png", scene.0)).unwrap();