classicube_helpers\events/
input.rs1#![allow(clippy::not_unsafe_ptr_arg_deref)]
2
3use std::os::raw::{c_float, c_int};
4
5use classicube_sys::{cc_bool, cc_string, InputButtons, InputDevice};
6
7use crate::make_event_handler;
8
9make_event_handler!(
10 Input,
12 Press,
13 Int,
14 (
15 {
16 name: key,
17 rust_type: char,
18 c_type: c_int,
19 to_rust: |key| char::from_u32(u32::try_from(key).expect("u32::try_from(key)")).expect("char::from_u32(key)"),
20 },
21 )
22);
23
24make_event_handler!(
25 Input,
27 Wheel,
28 Float,
29 (
30 {
31 name: delta,
32 rust_type: c_float,
33 c_type: c_float,
34 to_rust: |delta| delta,
35 },
36 )
37);
38
39make_event_handler!(
40 Input,
42 TextChanged,
43 String,
44 (
45 {
46 name: s_ptr,
47 rust_type: String,
48 c_type: *const cc_string,
49 to_rust: |s_ptr: *const cc_string| {
50 unsafe { s_ptr.as_ref().expect("s_ptr.as_ref()") }.to_string()
51 },
52 },
53 )
54);
55
56make_event_handler!(
57 Input,
59 Up2,
60 Input,
61 (
62 {
63 name: key,
64 rust_type: InputButtons,
65 c_type: c_int,
66 to_rust: |key| InputButtons::try_from(key).expect("InputButtons::try_from(key)"),
67 },
68 {
69 name: repeating,
70 rust_type: bool,
71 c_type: cc_bool,
72 to_rust: |repeating| repeating != 0,
73 },
74 {
75 name: device,
76 rust_type: *mut InputDevice,
77 c_type: *mut InputDevice,
78 to_rust: |device| device,
79 },
80 )
81);
82
83make_event_handler!(
84 Input,
86 Down2,
87 Input,
88 (
89 {
90 name: key,
91 rust_type: InputButtons,
92 c_type: c_int,
93 to_rust: |key| InputButtons::try_from(key).expect("InputButtons::try_from(key)"),
94 },
95 {
96 name: repeating,
97 rust_type: bool,
98 c_type: cc_bool,
99 to_rust: |repeating| repeating != 0,
100 },
101 {
102 name: device,
103 rust_type: *mut InputDevice,
104 c_type: *mut InputDevice,
105 to_rust: |device| device,
106 },
107 )
108);