Skip to content

Commit 6fbebde

Browse files
authored
refactor!: Rename accesskit_winit::Adapter::on_event to process_event (#307)
1 parent eed2e23 commit 6fbebde

File tree

6 files changed

+42
-44
lines changed

6 files changed

+42
-44
lines changed

platforms/winit/examples/simple.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,37 +177,40 @@ fn main() -> Result<(), impl std::error::Error> {
177177
event_loop.set_control_flow(ControlFlow::Wait);
178178

179179
match event {
180-
Event::WindowEvent { event, .. } if adapter.on_event(&window, &event) => match event {
181-
WindowEvent::CloseRequested => {
182-
event_loop.exit();
183-
}
184-
WindowEvent::KeyboardInput {
185-
event:
186-
KeyEvent {
187-
logical_key: virtual_code,
188-
state: ElementState::Pressed,
189-
..
190-
},
191-
..
192-
} => match virtual_code {
193-
Key::Named(winit::keyboard::NamedKey::Tab) => {
194-
let mut state = state.lock().unwrap();
195-
let new_focus = if state.focus == BUTTON_1_ID {
196-
BUTTON_2_ID
197-
} else {
198-
BUTTON_1_ID
199-
};
200-
state.set_focus(&adapter, new_focus);
201-
}
202-
Key::Named(winit::keyboard::NamedKey::Space) => {
203-
let mut state = state.lock().unwrap();
204-
let id = state.focus;
205-
state.press_button(&adapter, id);
180+
Event::WindowEvent { event, .. } => {
181+
adapter.process_event(&window, &event);
182+
match event {
183+
WindowEvent::CloseRequested => {
184+
event_loop.exit();
206185
}
186+
WindowEvent::KeyboardInput {
187+
event:
188+
KeyEvent {
189+
logical_key: virtual_code,
190+
state: ElementState::Pressed,
191+
..
192+
},
193+
..
194+
} => match virtual_code {
195+
Key::Named(winit::keyboard::NamedKey::Tab) => {
196+
let mut state = state.lock().unwrap();
197+
let new_focus = if state.focus == BUTTON_1_ID {
198+
BUTTON_2_ID
199+
} else {
200+
BUTTON_1_ID
201+
};
202+
state.set_focus(&adapter, new_focus);
203+
}
204+
Key::Named(winit::keyboard::NamedKey::Space) => {
205+
let mut state = state.lock().unwrap();
206+
let id = state.focus;
207+
state.press_button(&adapter, id);
208+
}
209+
_ => (),
210+
},
207211
_ => (),
208-
},
209-
_ => (),
210-
},
212+
}
213+
}
211214
Event::UserEvent(ActionRequestEvent {
212215
request:
213216
ActionRequest {

platforms/winit/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ impl Adapter {
7474
Self { adapter }
7575
}
7676

77-
#[must_use]
78-
pub fn on_event(&self, window: &Window, event: &WindowEvent) -> bool {
79-
self.adapter.on_event(window, event)
77+
/// Allows reacting to window events.
78+
///
79+
/// This must be called whenever a new window event is received
80+
/// and before it is handled by the application.
81+
pub fn process_event(&self, window: &Window, event: &WindowEvent) {
82+
self.adapter.process_event(window, event);
8083
}
8184

8285
pub fn update(&self, update: TreeUpdate) {

platforms/winit/src/platform_impl/macos.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ impl Adapter {
3939
}
4040
}
4141

42-
pub fn on_event(&self, _window: &Window, event: &WindowEvent) -> bool {
42+
pub fn process_event(&self, _window: &Window, event: &WindowEvent) {
4343
if let WindowEvent::Focused(is_focused) = event {
4444
if let Some(events) = self.adapter.update_view_focus_state(*is_focused) {
4545
events.raise();
4646
}
4747
}
48-
49-
true
5048
}
5149
}

platforms/winit/src/platform_impl/null.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ impl Adapter {
2222

2323
pub fn update_if_active(&self, _updater: impl FnOnce() -> TreeUpdate) {}
2424

25-
pub fn on_event(&self, _window: &Window, _event: &WindowEvent) -> bool {
26-
true
27-
}
25+
pub fn process_event(&self, _window: &Window, _event: &WindowEvent) {}
2826
}

platforms/winit/src/platform_impl/unix.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Adapter {
4646
}
4747
}
4848

49-
pub fn on_event(&self, window: &Window, event: &WindowEvent) -> bool {
49+
pub fn process_event(&self, window: &Window, event: &WindowEvent) {
5050
match event {
5151
WindowEvent::Moved(outer_position) => {
5252
let outer_position: (_, _) = outer_position.cast::<f64>().into();
@@ -85,7 +85,5 @@ impl Adapter {
8585
}
8686
_ => (),
8787
}
88-
89-
true
9088
}
9189
}

platforms/winit/src/platform_impl/windows.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,5 @@ impl Adapter {
3838
}
3939
}
4040

41-
pub fn on_event(&self, _window: &Window, _event: &WindowEvent) -> bool {
42-
true
43-
}
41+
pub fn process_event(&self, _window: &Window, _event: &WindowEvent) {}
4442
}

0 commit comments

Comments
 (0)