use super::CommonEvent;
use crate::impl_common_event_deref;
mod from_mouse;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PointerId(usize);
#[derive(Debug)]
pub struct PointerEvent {
pub id: PointerId,
pub width: f32,
pub height: f32,
pub pressure: f32,
pub tilt_x: f32,
pub tilt_y: f32,
pub twist: f32,
pub point_type: PointerType,
pub is_primary: bool,
pub common: CommonEvent,
}
bitflags! {
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
pub struct MouseButtons: u8 {
const PRIMARY = 0b0000_0001;
const SECONDARY = 0b0000_0010;
const AUXILIARY = 0b0000_0100;
const FOURTH = 0b0000_1000;
const FIFTH = 0b0001_0000;
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PointerType {
Mouse,
Pen,
Touch,
}
impl_common_event_deref!(PointerEvent);
#[cfg(test)]
mod tests {
use winit::{dpi::LogicalPosition, event::WindowEvent};
use crate::{prelude::*, reset_test_env, test_helper::*};
fn tap_on(wnd: &Window, x: f32, y: f32) {
let logical = LogicalPosition::new(x, y);
#[allow(deprecated)]
wnd.processes_native_event(WindowEvent::CursorMoved {
device_id: winit::event::DeviceId::dummy(),
position: logical.to_physical(1.),
});
wnd.process_mouse_press(Box::new(DummyDeviceId), MouseButtons::PRIMARY);
wnd.process_mouse_release(Box::new(DummyDeviceId), MouseButtons::PRIMARY);
}
#[test]
fn tap_focus() {
reset_test_env!();
let (tap, w_tap) = split_value(0);
let (focused, w_focused) = split_value(false);
let w = fn_widget! {
let mut host = @MockMulti {};
watch!($host.is_focused())
.subscribe(move |v| *$w_focused.write() = v);
@$host {
@MockBox {
size: Size::new(50., 50.,),
on_tap: move |_| *$w_tap.write() += 1,
}
@MockBox {
size: Size::new(50., 50.,),
on_tap: move |_| *$w_tap.write() += 1,
on_key_down: move |_| println!("dummy code"),
}
}
};
let mut wnd = TestWindow::new_with_size(w, Size::new(100., 100.));
wnd.draw_frame();
tap_on(&wnd, 25., 25.);
wnd.draw_frame();
assert_eq!(*tap.read(), 1);
assert!(!*focused.read());
tap_on(&wnd, 75., 25.);
wnd.draw_frame();
assert_eq!(*tap.read(), 2);
assert!(*focused.read());
}
}