Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions platforms/winit/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions platforms/winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions platforms/winit/src/platform_impl/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 1 addition & 3 deletions platforms/winit/src/platform_impl/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
4 changes: 1 addition & 3 deletions platforms/winit/src/platform_impl/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>().into();
Expand Down Expand Up @@ -85,7 +85,5 @@ impl Adapter {
}
_ => (),
}

true
}
}
4 changes: 1 addition & 3 deletions platforms/winit/src/platform_impl/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}