Remove event conversion from iced_winit::Application
This commit is contained in:
parent
3efede2662
commit
ce6806bbf4
@ -174,9 +174,9 @@ where
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &Renderer,
|
|
||||||
clipboard: Option<&dyn Clipboard>,
|
|
||||||
events: impl IntoIterator<Item = Event>,
|
events: impl IntoIterator<Item = Event>,
|
||||||
|
clipboard: Option<&dyn Clipboard>,
|
||||||
|
renderer: &Renderer,
|
||||||
) -> Vec<Message> {
|
) -> Vec<Message> {
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
conversion,
|
conversion, size::Size, window, Cache, Clipboard, Command, Debug, Element,
|
||||||
input::{keyboard, mouse},
|
Executor, Mode, MouseCursor, Proxy, Runtime, Settings, Subscription,
|
||||||
window, Cache, Clipboard, Command, Debug, Element, Event, Executor, Mode,
|
UserInterface,
|
||||||
MouseCursor, Proxy, Runtime, Settings, Size, Subscription, UserInterface,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An interactive, native cross-platform application.
|
/// An interactive, native cross-platform application.
|
||||||
@ -200,8 +199,7 @@ pub trait Application: Sized {
|
|||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| match event {
|
event_loop.run(move |event, _, control_flow| match event {
|
||||||
event::Event::MainEventsCleared => {
|
event::Event::MainEventsCleared => {
|
||||||
if events.is_empty() && external_messages.is_empty() && !resized
|
if events.is_empty() && external_messages.is_empty() {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,11 +223,11 @@ pub trait Application: Sized {
|
|||||||
.for_each(|event| runtime.broadcast(event));
|
.for_each(|event| runtime.broadcast(event));
|
||||||
|
|
||||||
let mut messages = user_interface.update(
|
let mut messages = user_interface.update(
|
||||||
&renderer,
|
events.drain(..),
|
||||||
clipboard
|
clipboard
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|c| c as &dyn iced_native::Clipboard),
|
.map(|c| c as &dyn iced_native::Clipboard),
|
||||||
events.drain(..),
|
&renderer,
|
||||||
);
|
);
|
||||||
messages.extend(external_messages.drain(..));
|
messages.extend(external_messages.drain(..));
|
||||||
debug.event_processing_finished();
|
debug.event_processing_finished();
|
||||||
@ -341,106 +339,37 @@ pub trait Application: Sized {
|
|||||||
event::Event::WindowEvent {
|
event::Event::WindowEvent {
|
||||||
event: window_event,
|
event: window_event,
|
||||||
..
|
..
|
||||||
} => match window_event {
|
} => {
|
||||||
WindowEvent::Resized(new_size) => {
|
match window_event {
|
||||||
size = Size::new(new_size, size.scale_factor());
|
WindowEvent::Resized(new_size) => {
|
||||||
|
size = Size::new(new_size, window.scale_factor());
|
||||||
events.push(Event::Window(window::Event::Resized {
|
resized = true;
|
||||||
width: size.logical().width.round() as u32,
|
}
|
||||||
height: size.logical().height.round() as u32,
|
WindowEvent::CloseRequested => {
|
||||||
}));
|
*control_flow = ControlFlow::Exit;
|
||||||
|
}
|
||||||
resized = true;
|
#[cfg(feature = "debug")]
|
||||||
}
|
WindowEvent::KeyboardInput {
|
||||||
WindowEvent::CloseRequested => {
|
input:
|
||||||
*control_flow = ControlFlow::Exit;
|
winit::event::KeyboardInput {
|
||||||
}
|
virtual_keycode:
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
Some(winit::event::VirtualKeyCode::F12),
|
||||||
let position =
|
state: winit::event::ElementState::Pressed,
|
||||||
position.to_logical::<f64>(size.scale_factor());
|
..
|
||||||
|
|
||||||
events.push(Event::Mouse(mouse::Event::CursorMoved {
|
|
||||||
x: position.x as f32,
|
|
||||||
y: position.y as f32,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
WindowEvent::MouseInput { button, state, .. } => {
|
|
||||||
events.push(Event::Mouse(mouse::Event::Input {
|
|
||||||
button: conversion::mouse_button(button),
|
|
||||||
state: conversion::button_state(state),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
WindowEvent::MouseWheel { delta, .. } => match delta {
|
|
||||||
winit::event::MouseScrollDelta::LineDelta(
|
|
||||||
delta_x,
|
|
||||||
delta_y,
|
|
||||||
) => {
|
|
||||||
events.push(Event::Mouse(
|
|
||||||
mouse::Event::WheelScrolled {
|
|
||||||
delta: mouse::ScrollDelta::Lines {
|
|
||||||
x: delta_x,
|
|
||||||
y: delta_y,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
));
|
..
|
||||||
}
|
} => debug.toggle(),
|
||||||
winit::event::MouseScrollDelta::PixelDelta(position) => {
|
_ => {}
|
||||||
events.push(Event::Mouse(
|
|
||||||
mouse::Event::WheelScrolled {
|
|
||||||
delta: mouse::ScrollDelta::Pixels {
|
|
||||||
x: position.x as f32,
|
|
||||||
y: position.y as f32,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
WindowEvent::ReceivedCharacter(c)
|
|
||||||
if !is_private_use_character(c) =>
|
|
||||||
{
|
|
||||||
events.push(Event::Keyboard(
|
|
||||||
keyboard::Event::CharacterReceived(c),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
winit::event::KeyboardInput {
|
|
||||||
virtual_keycode: Some(virtual_keycode),
|
|
||||||
state,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
match (virtual_keycode, state) {
|
|
||||||
(
|
|
||||||
winit::event::VirtualKeyCode::F12,
|
|
||||||
winit::event::ElementState::Pressed,
|
|
||||||
) => debug.toggle(),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
events.push(Event::Keyboard(keyboard::Event::Input {
|
if let Some(event) = conversion::window_event(
|
||||||
key_code: conversion::key_code(virtual_keycode),
|
window_event,
|
||||||
state: conversion::button_state(state),
|
size.scale_factor(),
|
||||||
modifiers: conversion::modifiers_state(modifiers),
|
modifiers,
|
||||||
}));
|
) {
|
||||||
|
events.push(event);
|
||||||
}
|
}
|
||||||
WindowEvent::HoveredFile(path) => {
|
}
|
||||||
events
|
|
||||||
.push(Event::Window(window::Event::FileHovered(path)));
|
|
||||||
}
|
|
||||||
WindowEvent::DroppedFile(path) => {
|
|
||||||
events
|
|
||||||
.push(Event::Window(window::Event::FileDropped(path)));
|
|
||||||
}
|
|
||||||
WindowEvent::HoveredFileCancelled => {
|
|
||||||
events.push(Event::Window(window::Event::FilesHoveredLeft));
|
|
||||||
}
|
|
||||||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
|
||||||
size = Size::new(size.physical(), scale_factor);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
event::Event::DeviceEvent {
|
event::Event::DeviceEvent {
|
||||||
event: event::DeviceEvent::ModifiersChanged(new_modifiers),
|
event: event::DeviceEvent::ModifiersChanged(new_modifiers),
|
||||||
..
|
..
|
||||||
@ -479,13 +408,3 @@ fn build_user_interface<'a, A: Application>(
|
|||||||
|
|
||||||
user_interface
|
user_interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// As defined in: http://www.unicode.org/faq/private_use.html
|
|
||||||
fn is_private_use_character(c: char) -> bool {
|
|
||||||
match c {
|
|
||||||
'\u{E000}'..='\u{F8FF}'
|
|
||||||
| '\u{F0000}'..='\u{FFFFD}'
|
|
||||||
| '\u{100000}'..='\u{10FFFD}' => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user