Renamed left and right.

This commit is contained in:
mintlu8 2024-11-01 19:23:50 +08:00
parent 4d007cabba
commit 3969f2de3d
2 changed files with 24 additions and 18 deletions

View file

@ -231,16 +231,22 @@ bitflags::bitflags! {
#[reflect(Hash, PartialEq, Debug)]
/// Button pressed in a [`PickingInteraction`]
pub struct PressedButtons: u8 {
/// Primary mouse button is pressed.
const PRIMARY = 1;
/// Secondary mouse button is pressed.
const SECONDARY = 2;
/// Left mouse button is pressed.
const LEFT = 1;
/// Right mouse button is pressed.
const RIGHT = 2;
/// Middle mouse button is pressed.
const MIDDLE = 4;
/// Touch input is pressed.
const TOUCH = 8;
/// Custom input is pressed.
const CUSTOM = 16;
/// X1 or back, reserved, currently does nothing.
const X1 = 32;
/// X2 or forward, reserved, currently does nothing.
const X2 = 64;
/// Left mouse button or touch input is pressed.
const LEFT_OR_TOUCH = 1|8;
}
}
@ -248,10 +254,10 @@ impl From<PointerPress> for PressedButtons {
fn from(value: PointerPress) -> Self {
let mut result = PressedButtons::empty();
if value.is_primary_pressed() {
result |= PressedButtons::PRIMARY;
result |= PressedButtons::LEFT;
}
if value.is_secondary_pressed() {
result |= PressedButtons::SECONDARY;
result |= PressedButtons::RIGHT;
}
if value.is_middle_pressed() {
result |= PressedButtons::MIDDLE;
@ -344,24 +350,24 @@ mod test {
#[test]
fn merge_interaction() {
assert_eq!(
Pressed(PressedButtons::PRIMARY) | Pressed(PressedButtons::SECONDARY),
Pressed(PressedButtons::PRIMARY | PressedButtons::SECONDARY)
Pressed(PressedButtons::LEFT) | Pressed(PressedButtons::RIGHT),
Pressed(PressedButtons::LEFT | PressedButtons::RIGHT)
);
assert_eq!(
Pressed(PressedButtons::PRIMARY) | Hovered,
Pressed(PressedButtons::PRIMARY)
Pressed(PressedButtons::LEFT) | Hovered,
Pressed(PressedButtons::LEFT)
);
assert_eq!(
Hovered | Pressed(PressedButtons::PRIMARY),
Pressed(PressedButtons::PRIMARY)
Hovered | Pressed(PressedButtons::LEFT),
Pressed(PressedButtons::LEFT)
);
assert_eq!(
Pressed(PressedButtons::PRIMARY) | None,
Pressed(PressedButtons::PRIMARY)
Pressed(PressedButtons::LEFT) | None,
Pressed(PressedButtons::LEFT)
);
assert_eq!(
None | Pressed(PressedButtons::PRIMARY),
Pressed(PressedButtons::PRIMARY)
None | Pressed(PressedButtons::LEFT),
Pressed(PressedButtons::LEFT)
);
assert_eq!(Hovered | None, Hovered);
assert_eq!(None | Hovered, Hovered);

View file

@ -33,12 +33,12 @@ fn picking(sprite: Query<(&PickingInteraction, &Children)>, mut text: Query<&mut
while let Some(mut text) = iter.fetch_next() {
match interaction {
PickingInteraction::Pressed(pressed_buttons)
if pressed_buttons.contains(PressedButtons::PRIMARY) =>
if pressed_buttons.contains(PressedButtons::LEFT) =>
{
text.0 = "Left Clicked!".into();
}
PickingInteraction::Pressed(pressed_buttons)
if pressed_buttons.contains(PressedButtons::SECONDARY) =>
if pressed_buttons.contains(PressedButtons::RIGHT) =>
{
text.0 = "Right Clicked!".into();
}