Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion test/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ impl Interaction {
button: *button,
target: None,
},
mouse::Event::WheelScrolled { delta } => {
Mouse::Scroll { delta: *delta }
}
_ => None?,
}),
Event::Keyboard(keyboard) => Self::Keyboard(match keyboard {
Expand Down Expand Up @@ -191,6 +194,38 @@ impl Interaction {
}),
None,
),
(
Mouse::Scroll {
delta: ScrollDelta::Lines { x, y },
},
Mouse::Scroll {
delta: ScrollDelta::Lines { x: xx, y: yy },
},
) => (
Self::Mouse(Mouse::Scroll {
delta: ScrollDelta::Lines {
x: x + xx,
y: y + yy,
},
}),
None,
),
(
Mouse::Scroll {
delta: ScrollDelta::Pixels { x, y },
},
Mouse::Scroll {
delta: ScrollDelta::Pixels { x: xx, y: yy },
},
) => (
Self::Mouse(Mouse::Scroll {
delta: ScrollDelta::Pixels {
x: x + xx,
y: y + yy,
},
}),
None,
),
(current, next) => {
(Self::Mouse(current), Some(Self::Mouse(next)))
}
Expand Down Expand Up @@ -238,6 +273,9 @@ impl Interaction {
let mouse_release =
|button| Event::Mouse(mouse::Event::ButtonReleased(button));

let mouse_scroll =
|delta| Event::Mouse(mouse::Event::WheelScrolled { delta });

let key_press = |key| simulator::press_key(key, None);

let key_release = |key| simulator::release_key(key);
Expand Down Expand Up @@ -283,6 +321,9 @@ impl Interaction {
} => {
vec![mouse_press(*button), mouse_release(*button)]
}
Mouse::Scroll { delta } => {
vec![mouse_scroll(*delta)]
}
},
Interaction::Keyboard(keyboard) => match keyboard {
Keyboard::Press(key) => vec![key_press(*key)],
Expand Down Expand Up @@ -331,6 +372,11 @@ pub enum Mouse {
/// The location of the click.
target: Option<Target>,
},
/// The wheel was scrolled
Scroll {
/// The amount of scrolling
delta: ScrollDelta,
},
}

impl fmt::Display for Mouse {
Expand Down Expand Up @@ -360,6 +406,14 @@ impl fmt::Display for Mouse {
format::button_at(*button, target.as_ref())
)
}
Mouse::Scroll { delta } => match delta {
ScrollDelta::Lines { x, y } => {
write!(f, "scroll ({x}, {y}) lines")
}
ScrollDelta::Pixels { x, y } => {
write!(f, "scroll ({x}, {y}) pixels")
}
},
}
}
}
Expand Down Expand Up @@ -503,6 +557,7 @@ impl fmt::Display for Expectation {
}
}

use iced_runtime::core::mouse::ScrollDelta;
pub use parser::Error as ParseError;

mod parser {
Expand Down Expand Up @@ -550,7 +605,14 @@ mod parser {
fn mouse(input: &str) -> IResult<&str, Mouse> {
let mouse_move = preceded(tag("move "), target).map(Mouse::Move);

alt((mouse_move, mouse_click, mouse_press, mouse_release)).parse(input)
alt((
mouse_move,
mouse_click,
mouse_press,
mouse_release,
mouse_scroll,
))
.parse(input)
}

fn mouse_click(input: &str) -> IResult<&str, Mouse> {
Expand All @@ -577,6 +639,19 @@ mod parser {
Ok((input, Mouse::Release { button, target }))
}

fn mouse_scroll(input: &str) -> IResult<&str, Mouse> {
let (input, _) = tag("scroll ")(input)?;

let (input, Point { x, y }) = point(input)?;

alt((
tag(" lines").map(|_| ScrollDelta::Lines { x, y }),
tag(" pixels").map(|_| ScrollDelta::Pixels { x, y }),
))
.map(|delta| Mouse::Scroll { delta })
.parse(input)
}

fn mouse_button_at(
input: &str,
) -> IResult<&str, (mouse::Button, Option<Target>)> {
Expand Down