From 8d6c73d290d551441bb33b9e0185b4e22ccf8ecf Mon Sep 17 00:00:00 2001 From: DataTriny Date: Sat, 4 Nov 2023 17:54:40 +0100 Subject: [PATCH] fix!: Rename `accesskit_winit::Adapter::on_event` to `process_event` --- platforms/winit/examples/simple.rs | 61 ++++++++++---------- platforms/winit/src/lib.rs | 9 ++- platforms/winit/src/platform_impl/macos.rs | 4 +- platforms/winit/src/platform_impl/null.rs | 4 +- platforms/winit/src/platform_impl/unix.rs | 4 +- platforms/winit/src/platform_impl/windows.rs | 4 +- 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/platforms/winit/examples/simple.rs b/platforms/winit/examples/simple.rs index 9fc0746e..e93c04d5 100644 --- a/platforms/winit/examples/simple.rs +++ b/platforms/winit/examples/simple.rs @@ -177,37 +177,40 @@ fn main() -> Result<(), impl std::error::Error> { event_loop.set_control_flow(ControlFlow::Wait); match event { - Event::WindowEvent { event, .. } if adapter.on_event(&window, &event) => match event { - WindowEvent::CloseRequested => { - event_loop.exit(); - } - WindowEvent::KeyboardInput { - event: - KeyEvent { - logical_key: virtual_code, - state: ElementState::Pressed, - .. - }, - .. - } => match virtual_code { - Key::Named(winit::keyboard::NamedKey::Tab) => { - let mut state = state.lock().unwrap(); - let new_focus = if state.focus == BUTTON_1_ID { - BUTTON_2_ID - } else { - BUTTON_1_ID - }; - state.set_focus(&adapter, new_focus); - } - Key::Named(winit::keyboard::NamedKey::Space) => { - let mut state = state.lock().unwrap(); - let id = state.focus; - state.press_button(&adapter, id); + Event::WindowEvent { event, .. } => { + adapter.process_event(&window, &event); + match event { + WindowEvent::CloseRequested => { + event_loop.exit(); } + WindowEvent::KeyboardInput { + event: + KeyEvent { + logical_key: virtual_code, + state: ElementState::Pressed, + .. + }, + .. + } => match virtual_code { + Key::Named(winit::keyboard::NamedKey::Tab) => { + let mut state = state.lock().unwrap(); + let new_focus = if state.focus == BUTTON_1_ID { + BUTTON_2_ID + } else { + BUTTON_1_ID + }; + state.set_focus(&adapter, new_focus); + } + Key::Named(winit::keyboard::NamedKey::Space) => { + let mut state = state.lock().unwrap(); + let id = state.focus; + state.press_button(&adapter, id); + } + _ => (), + }, _ => (), - }, - _ => (), - }, + } + } Event::UserEvent(ActionRequestEvent { request: ActionRequest { diff --git a/platforms/winit/src/lib.rs b/platforms/winit/src/lib.rs index 6d8187ca..2bfc08f0 100644 --- a/platforms/winit/src/lib.rs +++ b/platforms/winit/src/lib.rs @@ -74,9 +74,12 @@ impl Adapter { Self { adapter } } - #[must_use] - pub fn on_event(&self, window: &Window, event: &WindowEvent) -> bool { - self.adapter.on_event(window, event) + /// Allows reacting to window events. + /// + /// This must be called whenever a new window event is received + /// and before it is handled by the application. + pub fn process_event(&self, window: &Window, event: &WindowEvent) { + self.adapter.process_event(window, event); } pub fn update(&self, update: TreeUpdate) { diff --git a/platforms/winit/src/platform_impl/macos.rs b/platforms/winit/src/platform_impl/macos.rs index f3839449..535aa8c4 100644 --- a/platforms/winit/src/platform_impl/macos.rs +++ b/platforms/winit/src/platform_impl/macos.rs @@ -39,13 +39,11 @@ impl Adapter { } } - pub fn on_event(&self, _window: &Window, event: &WindowEvent) -> bool { + pub fn process_event(&self, _window: &Window, event: &WindowEvent) { if let WindowEvent::Focused(is_focused) = event { if let Some(events) = self.adapter.update_view_focus_state(*is_focused) { events.raise(); } } - - true } } diff --git a/platforms/winit/src/platform_impl/null.rs b/platforms/winit/src/platform_impl/null.rs index 2b462b7d..27918631 100644 --- a/platforms/winit/src/platform_impl/null.rs +++ b/platforms/winit/src/platform_impl/null.rs @@ -22,7 +22,5 @@ impl Adapter { pub fn update_if_active(&self, _updater: impl FnOnce() -> TreeUpdate) {} - pub fn on_event(&self, _window: &Window, _event: &WindowEvent) -> bool { - true - } + pub fn process_event(&self, _window: &Window, _event: &WindowEvent) {} } diff --git a/platforms/winit/src/platform_impl/unix.rs b/platforms/winit/src/platform_impl/unix.rs index 2c40684c..ab5b7030 100644 --- a/platforms/winit/src/platform_impl/unix.rs +++ b/platforms/winit/src/platform_impl/unix.rs @@ -46,7 +46,7 @@ impl Adapter { } } - pub fn on_event(&self, window: &Window, event: &WindowEvent) -> bool { + pub fn process_event(&self, window: &Window, event: &WindowEvent) { match event { WindowEvent::Moved(outer_position) => { let outer_position: (_, _) = outer_position.cast::().into(); @@ -85,7 +85,5 @@ impl Adapter { } _ => (), } - - true } } diff --git a/platforms/winit/src/platform_impl/windows.rs b/platforms/winit/src/platform_impl/windows.rs index aa5dce07..348cc395 100644 --- a/platforms/winit/src/platform_impl/windows.rs +++ b/platforms/winit/src/platform_impl/windows.rs @@ -38,7 +38,5 @@ impl Adapter { } } - pub fn on_event(&self, _window: &Window, _event: &WindowEvent) -> bool { - true - } + pub fn process_event(&self, _window: &Window, _event: &WindowEvent) {} }