Skip to content

Commit 149afcb

Browse files
committed
refactor: Make InputEvent not Copy
Implementing IME requires passing events which are not Copy, so this refactor makes it easier to implement IME.
1 parent cf4a7a2 commit 149afcb

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

core/src/events.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -766,17 +766,17 @@ impl ButtonKeyCode {
766766
})
767767
}
768768

769-
pub fn from_input_event(event: InputEvent) -> Option<Self> {
769+
pub fn from_input_event(event: &InputEvent) -> Option<Self> {
770770
match event {
771771
// ASCII characters convert directly to keyPress button events.
772772
InputEvent::TextInput { codepoint }
773-
if codepoint as u32 >= 32 && codepoint as u32 <= 126 =>
773+
if *codepoint as u32 >= 32 && *codepoint as u32 <= 126 =>
774774
{
775-
Some(ButtonKeyCode::from_u8(codepoint as u8).unwrap())
775+
Some(ButtonKeyCode::from_u8(*codepoint as u8).unwrap())
776776
}
777777

778778
// Special keys have custom values for keyPress.
779-
InputEvent::KeyDown { key_code, .. } => Self::from_key_code(key_code),
779+
InputEvent::KeyDown { key_code, .. } => Self::from_key_code(*key_code),
780780
_ => None,
781781
}
782782
}

core/src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::collections::{HashMap, HashSet};
77
/// An event describing input in general.
88
///
99
/// It's usually a processed [`PlayerEvent`].
10-
#[derive(Debug, Clone, Copy)]
10+
#[derive(Debug, Clone)]
1111
pub enum InputEvent {
1212
KeyDown {
1313
key_code: KeyCode,

core/src/player.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,11 @@ impl Player {
11341134
}
11351135

11361136
self.mutate_with_update_context(|context| {
1137-
let button_event = ButtonKeyCode::from_input_event(event)
1137+
let button_event = ButtonKeyCode::from_input_event(&event)
11381138
.map(|key_code| ClipEvent::KeyPress { key_code });
11391139

11401140
if let InputEvent::KeyDown { key_code, key_char }
1141-
| InputEvent::KeyUp { key_code, key_char } = event
1141+
| InputEvent::KeyUp { key_code, key_char } = &event
11421142
{
11431143
let ctrl_key = context.input.is_key_down(KeyCode::CONTROL);
11441144
let alt_key = context.input.is_key_down(KeyCode::ALT);
@@ -1192,7 +1192,7 @@ impl Player {
11921192
}
11931193

11941194
// Propagate clip events.
1195-
let (clip_event, listener) = match event {
1195+
let (clip_event, listener) = match &event {
11961196
InputEvent::KeyDown { .. } => {
11971197
(Some(ClipEvent::KeyDown), Some(("Key", "onKeyDown", vec![])))
11981198
}
@@ -1279,11 +1279,11 @@ impl Player {
12791279
// KeyPress events take precedence over text input.
12801280
if !key_press_handled {
12811281
if let Some(text) = context.focus_tracker.get_as_edit_text() {
1282-
if let InputEvent::TextInput { codepoint } = event {
1283-
text.text_input(codepoint, context);
1282+
if let InputEvent::TextInput { codepoint } = &event {
1283+
text.text_input(*codepoint, context);
12841284
}
1285-
if let InputEvent::TextControl { code } = event {
1286-
text.text_control_input(code, context);
1285+
if let InputEvent::TextControl { code } = &event {
1286+
text.text_control_input(*code, context);
12871287
}
12881288
}
12891289
}
@@ -1293,7 +1293,7 @@ impl Player {
12931293
if let InputEvent::KeyDown {
12941294
key_code: KeyCode::TAB,
12951295
..
1296-
} = event
1296+
} = &event
12971297
{
12981298
let reversed = context.input.is_key_down(KeyCode::SHIFT);
12991299
let tracker = context.focus_tracker;
@@ -1306,7 +1306,7 @@ impl Player {
13061306
if !key_press_handled && context.focus_tracker.highlight().is_visible() {
13071307
if let Some(focus) = context.focus_tracker.get() {
13081308
if matches!(
1309-
event,
1309+
&event,
13101310
InputEvent::KeyDown {
13111311
key_code: KeyCode::ENTER,
13121312
..
@@ -1318,8 +1318,8 @@ impl Player {
13181318
focus.handle_clip_event(context, ClipEvent::Release { index: 0 });
13191319
}
13201320

1321-
if let InputEvent::KeyDown { key_code, .. } = event {
1322-
if let Some(direction) = NavigationDirection::from_key_code(key_code) {
1321+
if let InputEvent::KeyDown { key_code, .. } = &event {
1322+
if let Some(direction) = NavigationDirection::from_key_code(*key_code) {
13231323
let tracker = context.focus_tracker;
13241324
tracker.navigate(context, direction);
13251325
}
@@ -1357,7 +1357,7 @@ impl Player {
13571357
}
13581358
}
13591359

1360-
if let InputEvent::MouseWheel { delta } = event {
1360+
if let InputEvent::MouseWheel { delta } = &event {
13611361
self.mutate_with_update_context(|context| {
13621362
let target = if let Some(over_object) = context.mouse_data.hovered {
13631363
if over_object.as_displayobject().movie().is_action_script_3()
@@ -1371,7 +1371,7 @@ impl Player {
13711371
context.stage.as_interactive()
13721372
};
13731373
if let Some(target) = target {
1374-
let event = ClipEvent::MouseWheel { delta };
1374+
let event = ClipEvent::MouseWheel { delta: *delta };
13751375
target.event_dispatch_to_avm2(context, event);
13761376
target.handle_clip_event(context, event);
13771377
}

0 commit comments

Comments
 (0)