1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use std::path::PathBuf;

use freya_core::events::{
    EventName,
    PlatformEvent,
    PlatformEventData,
};
use freya_elements::events::{
    Code,
    Force,
    Key,
    Modifiers,
    MouseButton,
    TouchPhase,
};
use torin::prelude::CursorPoint;

pub enum TestEvent {
    /// A Mouse Event.
    Mouse {
        name: EventName,
        cursor: CursorPoint,
        button: Option<MouseButton>,
    },
    /// A Wheel event.
    Wheel {
        name: EventName,
        scroll: CursorPoint,
        cursor: CursorPoint,
    },
    /// A Keyboard event.
    Keyboard {
        name: EventName,
        key: Key,
        code: Code,
        modifiers: Modifiers,
    },
    /// A Touch event.
    Touch {
        name: EventName,
        location: CursorPoint,
        finger_id: u64,
        phase: TouchPhase,
        force: Option<Force>,
    },
    /// A File event.
    File {
        name: EventName,
        cursor: CursorPoint,
        file_path: Option<PathBuf>,
    },
}

impl From<TestEvent> for PlatformEvent {
    fn from(val: TestEvent) -> Self {
        let (name, data) = match val {
            TestEvent::File {
                name,
                cursor,
                file_path,
            } => (name, PlatformEventData::File { cursor, file_path }),
            TestEvent::Keyboard {
                name,
                key,
                code,
                modifiers,
            } => (
                name,
                PlatformEventData::Keyboard {
                    key,
                    code,
                    modifiers,
                },
            ),
            TestEvent::Mouse {
                name,
                cursor,
                button,
            } => (name, PlatformEventData::Mouse { cursor, button }),
            TestEvent::Wheel {
                name,
                scroll,
                cursor,
            } => (name, PlatformEventData::Wheel { scroll, cursor }),
            TestEvent::Touch {
                name,
                location,
                finger_id,
                phase,
                force,
            } => (
                name,
                PlatformEventData::Touch {
                    location,
                    finger_id,
                    phase,
                    force,
                },
            ),
        };

        PlatformEvent { name, data }
    }
}