mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
ui-contract: Fixture::click_at's press and release carry the modifiers Fixture::hold keeps
They carried none, so a component that reads the release's modifiers never saw a held Alt. The frames already announce held modifiers, so the click no longer announces and clears its own.
This commit is contained in:
@@ -62,28 +62,14 @@ pub(crate) fn text_event(text: &str) -> Event {
|
||||
Event::Text(text.to_owned())
|
||||
}
|
||||
|
||||
/// The announcement of `modifiers`, none when no modifier is held.
|
||||
#[cfg(feature = "testing")]
|
||||
fn announced(modifiers: Modifiers) -> Option<Event> {
|
||||
(modifiers != Modifiers::NONE).then(|| modifiers_changed(modifiers))
|
||||
}
|
||||
|
||||
/// The frame that clears `modifiers`, none when none was held.
|
||||
#[cfg(feature = "testing")]
|
||||
fn cleared(modifiers: Modifiers) -> Option<Frame> {
|
||||
announced(modifiers).map(|_| vec![modifiers_changed(Modifiers::NONE)])
|
||||
}
|
||||
|
||||
/// A move to `pos` (with `modifiers` announced first), then `count` times a press and a release of `button`, one
|
||||
/// frame each; `modifiers` are cleared in a last frame when they were set.
|
||||
/// A move to `pos`, then `count` times a press and a release of `button` carrying the held `modifiers`, one frame each.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn click_frames(pos: Pos2, pressed_button: egui::PointerButton, count: u32, modifiers: Modifiers) -> Vec<Frame> {
|
||||
let mut frames = vec![announced(modifiers).into_iter().chain([pointer_moved(pos)]).collect()];
|
||||
let mut frames = vec![vec![pointer_moved(pos)]];
|
||||
for _ in 0..count {
|
||||
frames.push(vec![button(pos, pressed_button, true, modifiers)]);
|
||||
frames.push(vec![button(pos, pressed_button, false, modifiers)]);
|
||||
}
|
||||
frames.extend(cleared(modifiers));
|
||||
frames
|
||||
}
|
||||
|
||||
|
||||
@@ -655,9 +655,10 @@ impl Fixture {
|
||||
self.click_at(target.center())
|
||||
}
|
||||
|
||||
/// Hover, press and release at `pos`, in separate frames, then one idle frame.
|
||||
/// Hover, press and release at `pos`, in separate frames, then one idle frame. The press and release carry the
|
||||
/// modifiers [`Fixture::hold`] keeps.
|
||||
pub fn click_at(&mut self, pos: Pos2) -> &mut Self {
|
||||
self.play(injected::click_frames(pos, egui::PointerButton::Primary, 1, Modifiers::NONE));
|
||||
self.play(injected::click_frames(pos, egui::PointerButton::Primary, 1, self.frames.held()));
|
||||
self.frame(Vec::new())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user