Update winit to 0.29.4
This commit is contained in:
parent
dd249a1d11
commit
e819c2390b
19 changed files with 654 additions and 846 deletions
|
|
@ -130,7 +130,6 @@ glyphon = { git = "https://github.com/grovesNL/glyphon.git", rev = "2caa9fc5e592
|
||||||
guillotiere = "0.6"
|
guillotiere = "0.6"
|
||||||
half = "2.2"
|
half = "2.2"
|
||||||
image = "0.24"
|
image = "0.24"
|
||||||
instant = "0.1"
|
|
||||||
kamadak-exif = "0.5"
|
kamadak-exif = "0.5"
|
||||||
kurbo = "0.9"
|
kurbo = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
@ -157,7 +156,8 @@ unicode-segmentation = "1.0"
|
||||||
wasm-bindgen-futures = "0.4"
|
wasm-bindgen-futures = "0.4"
|
||||||
wasm-timer = "0.2"
|
wasm-timer = "0.2"
|
||||||
web-sys = "0.3"
|
web-sys = "0.3"
|
||||||
|
web-time = "0.2"
|
||||||
wgpu = "0.18"
|
wgpu = "0.18"
|
||||||
winapi = "0.3"
|
winapi = "0.3"
|
||||||
window_clipboard = "0.3"
|
window_clipboard = "0.3"
|
||||||
winit = { git = "https://github.com/iced-rs/winit.git", rev = "c52db2045d0a2f1b8d9923870de1d4ab1994146e", default-features = false }
|
winit = { git = "https://github.com/iced-rs/winit.git", rev = "3bcdb9abcd7459978ec689523bc21943d38da0f9", default-features = false, features = ["rwh_05", "x11", "wayland"] }
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,11 @@ log.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
xxhash-rust.workspace = true
|
xxhash-rust.workspace = true
|
||||||
num-traits.workspace = true
|
num-traits.workspace = true
|
||||||
|
web-time.workspace = true
|
||||||
|
|
||||||
palette.workspace = true
|
palette.workspace = true
|
||||||
palette.optional = true
|
palette.optional = true
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
instant.workspace = true
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
raw-window-handle.workspace = true
|
raw-window-handle.workspace = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use super::{KeyCode, Modifiers};
|
||||||
/// additional events, feel free to [open an issue] and share your use case!_
|
/// additional events, feel free to [open an issue] and share your use case!_
|
||||||
///
|
///
|
||||||
/// [open an issue]: https://github.com/iced-rs/iced/issues
|
/// [open an issue]: https://github.com/iced-rs/iced/issues
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// A keyboard key was pressed.
|
/// A keyboard key was pressed.
|
||||||
KeyPressed {
|
KeyPressed {
|
||||||
|
|
@ -15,6 +15,9 @@ pub enum Event {
|
||||||
|
|
||||||
/// The state of the modifier keys
|
/// The state of the modifier keys
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
|
|
||||||
|
/// The text produced by the key press, if any.
|
||||||
|
text: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A keyboard key was released.
|
/// A keyboard key was released.
|
||||||
|
|
@ -26,9 +29,6 @@ pub enum Event {
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A unicode character was received.
|
|
||||||
CharacterReceived(char),
|
|
||||||
|
|
||||||
/// The keyboard modifiers have changed.
|
/// The keyboard modifiers have changed.
|
||||||
ModifiersChanged(Modifiers),
|
ModifiersChanged(Modifiers),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,12 @@ pub enum Button {
|
||||||
/// The middle (wheel) button.
|
/// The middle (wheel) button.
|
||||||
Middle,
|
Middle,
|
||||||
|
|
||||||
|
/// The back mouse button.
|
||||||
|
Back,
|
||||||
|
|
||||||
|
/// The forward mouse button.
|
||||||
|
Forward,
|
||||||
|
|
||||||
/// Some other button.
|
/// Some other button.
|
||||||
Other(u16),
|
Other(u16),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,4 @@
|
||||||
//! Keep track of time, both in native and web platforms!
|
//! Keep track of time, both in native and web platforms!
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
pub use web_time::Duration;
|
||||||
pub use instant::Instant;
|
pub use web_time::Instant;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
pub use instant::Duration;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use std::time::Instant;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use std::time::Duration;
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ use iced_winit::winit;
|
||||||
use iced_winit::Clipboard;
|
use iced_winit::Clipboard;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Event, ModifiersState, WindowEvent},
|
event::{Event, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
|
keyboard::ModifiersState,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|
@ -48,7 +49,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
// Initialize winit
|
// Initialize winit
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new()?;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
let window = winit::window::WindowBuilder::new()
|
let window = winit::window::WindowBuilder::new()
|
||||||
|
|
@ -160,67 +161,15 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run event loop
|
// Run event loop
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, window_target| {
|
||||||
// You should change this if you want to render continuosly
|
// You should change this if you want to render continuosly
|
||||||
*control_flow = ControlFlow::Wait;
|
window_target.set_control_flow(ControlFlow::Wait);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => {
|
Event::WindowEvent {
|
||||||
match event {
|
event: WindowEvent::RedrawRequested,
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
..
|
||||||
cursor_position = Some(position);
|
} => {
|
||||||
}
|
|
||||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
|
||||||
modifiers = new_modifiers;
|
|
||||||
}
|
|
||||||
WindowEvent::Resized(_) => {
|
|
||||||
resized = true;
|
|
||||||
}
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map window event to iced event
|
|
||||||
if let Some(event) = iced_winit::conversion::window_event(
|
|
||||||
window::Id::MAIN,
|
|
||||||
&event,
|
|
||||||
window.scale_factor(),
|
|
||||||
modifiers,
|
|
||||||
) {
|
|
||||||
state.queue_event(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
// If there are events pending
|
|
||||||
if !state.is_queue_empty() {
|
|
||||||
// We update iced
|
|
||||||
let _ = state.update(
|
|
||||||
viewport.logical_size(),
|
|
||||||
cursor_position
|
|
||||||
.map(|p| {
|
|
||||||
conversion::cursor_position(
|
|
||||||
p,
|
|
||||||
viewport.scale_factor(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.map(mouse::Cursor::Available)
|
|
||||||
.unwrap_or(mouse::Cursor::Unavailable),
|
|
||||||
&mut renderer,
|
|
||||||
&Theme::Dark,
|
|
||||||
&renderer::Style {
|
|
||||||
text_color: Color::WHITE,
|
|
||||||
},
|
|
||||||
&mut clipboard,
|
|
||||||
&mut debug,
|
|
||||||
);
|
|
||||||
|
|
||||||
// and request a redraw
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
if resized {
|
if resized {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
|
|
@ -309,7 +258,60 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Event::WindowEvent { event, .. } => {
|
||||||
|
match event {
|
||||||
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
|
cursor_position = Some(position);
|
||||||
|
}
|
||||||
|
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||||
|
modifiers = new_modifiers.state();
|
||||||
|
}
|
||||||
|
WindowEvent::Resized(_) => {
|
||||||
|
resized = true;
|
||||||
|
}
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
|
window_target.exit();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map window event to iced event
|
||||||
|
if let Some(event) = iced_winit::conversion::window_event(
|
||||||
|
window::Id::MAIN,
|
||||||
|
&event,
|
||||||
|
window.scale_factor(),
|
||||||
|
modifiers,
|
||||||
|
) {
|
||||||
|
state.queue_event(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
// If there are events pending
|
||||||
|
if !state.is_queue_empty() {
|
||||||
|
// We update iced
|
||||||
|
let _ = state.update(
|
||||||
|
viewport.logical_size(),
|
||||||
|
cursor_position
|
||||||
|
.map(|p| {
|
||||||
|
conversion::cursor_position(p, viewport.scale_factor())
|
||||||
|
})
|
||||||
|
.map(mouse::Cursor::Available)
|
||||||
|
.unwrap_or(mouse::Cursor::Unavailable),
|
||||||
|
&mut renderer,
|
||||||
|
&Theme::Dark,
|
||||||
|
&renderer::Style {
|
||||||
|
text_color: Color::WHITE,
|
||||||
|
},
|
||||||
|
&mut clipboard,
|
||||||
|
&mut debug,
|
||||||
|
);
|
||||||
|
|
||||||
|
// and request a redraw
|
||||||
|
window.request_redraw();
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ impl Application for App {
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key_code: keyboard::KeyCode::Tab,
|
key_code: keyboard::KeyCode::Tab,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if modifiers.shift() {
|
if modifiers.shift() {
|
||||||
widget::focus_previous()
|
widget::focus_previous()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced.workspace = true
|
iced.workspace = true
|
||||||
iced.features = ["image", "debug", "tokio"]
|
iced.features = ["image", "debug", "tokio", "webgl"]
|
||||||
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ impl Application for App {
|
||||||
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
|
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key_code: keyboard::KeyCode::Tab,
|
key_code: keyboard::KeyCode::Tab,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
..
|
||||||
})) if modifiers.shift() => widget::focus_previous(),
|
})) if modifiers.shift() => widget::focus_previous(),
|
||||||
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
|
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key_code: keyboard::KeyCode::Tab,
|
key_code: keyboard::KeyCode::Tab,
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ where
|
||||||
core::Event::Keyboard(Event::KeyPressed {
|
core::Event::Keyboard(Event::KeyPressed {
|
||||||
key_code,
|
key_code,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
..
|
||||||
}),
|
}),
|
||||||
core::event::Status::Ignored,
|
core::event::Status::Ignored,
|
||||||
) => f(key_code, modifiers),
|
) => f(key_code, modifiers),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub use crate::core::event::Status;
|
||||||
/// A [`Canvas`] event.
|
/// A [`Canvas`] event.
|
||||||
///
|
///
|
||||||
/// [`Canvas`]: crate::Canvas
|
/// [`Canvas`]: crate::Canvas
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// A mouse event.
|
/// A mouse event.
|
||||||
Mouse(mouse::Event),
|
Mouse(mouse::Event),
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub use crate::core::event::Status;
|
||||||
/// A [`Shader`] event.
|
/// A [`Shader`] event.
|
||||||
///
|
///
|
||||||
/// [`Shader`]: crate::Shader
|
/// [`Shader`]: crate::Shader
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// A mouse event.
|
/// A mouse event.
|
||||||
Mouse(mouse::Event),
|
Mouse(mouse::Event),
|
||||||
|
|
|
||||||
|
|
@ -649,6 +649,7 @@ impl Update {
|
||||||
keyboard::Event::KeyPressed {
|
keyboard::Event::KeyPressed {
|
||||||
key_code,
|
key_code,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
text,
|
||||||
} if state.is_focused => {
|
} if state.is_focused => {
|
||||||
if let Some(motion) = motion(key_code) {
|
if let Some(motion) = motion(key_code) {
|
||||||
let motion =
|
let motion =
|
||||||
|
|
@ -678,12 +679,15 @@ impl Update {
|
||||||
{
|
{
|
||||||
Some(Self::Paste)
|
Some(Self::Paste)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => {
|
||||||
|
let text = text?;
|
||||||
|
|
||||||
|
edit(Edit::Insert(
|
||||||
|
text.chars().next().unwrap_or_default(),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::Event::CharacterReceived(c) if state.is_focused => {
|
|
||||||
edit(Edit::Insert(c))
|
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
||||||
|
|
@ -752,34 +752,9 @@ where
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::CharacterReceived(c)) => {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
let state = state();
|
key_code, text, ..
|
||||||
|
}) => {
|
||||||
if let Some(focus) = &mut state.is_focused {
|
|
||||||
let Some(on_input) = on_input else {
|
|
||||||
return event::Status::Ignored;
|
|
||||||
};
|
|
||||||
|
|
||||||
if state.is_pasting.is_none()
|
|
||||||
&& !state.keyboard_modifiers.command()
|
|
||||||
&& !c.is_control()
|
|
||||||
{
|
|
||||||
let mut editor = Editor::new(value, &mut state.cursor);
|
|
||||||
|
|
||||||
editor.insert(c);
|
|
||||||
|
|
||||||
let message = (on_input)(editor.contents());
|
|
||||||
shell.publish(message);
|
|
||||||
|
|
||||||
focus.updated_at = Instant::now();
|
|
||||||
|
|
||||||
update_cache(state, value);
|
|
||||||
|
|
||||||
return event::Status::Captured;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed { key_code, .. }) => {
|
|
||||||
let state = state();
|
let state = state();
|
||||||
|
|
||||||
if let Some(focus) = &mut state.is_focused {
|
if let Some(focus) = &mut state.is_focused {
|
||||||
|
|
@ -971,7 +946,30 @@ where
|
||||||
| keyboard::KeyCode::Down => {
|
| keyboard::KeyCode::Down => {
|
||||||
return event::Status::Ignored;
|
return event::Status::Ignored;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {
|
||||||
|
if let Some(text) = text {
|
||||||
|
let c = text.chars().next().unwrap_or_default();
|
||||||
|
|
||||||
|
if state.is_pasting.is_none()
|
||||||
|
&& !state.keyboard_modifiers.command()
|
||||||
|
&& !c.is_control()
|
||||||
|
{
|
||||||
|
let mut editor =
|
||||||
|
Editor::new(value, &mut state.cursor);
|
||||||
|
|
||||||
|
editor.insert(c);
|
||||||
|
|
||||||
|
let message = (on_input)(editor.contents());
|
||||||
|
shell.publish(message);
|
||||||
|
|
||||||
|
focus.updated_at = Instant::now();
|
||||||
|
|
||||||
|
update_cache(state, value);
|
||||||
|
|
||||||
|
return event::Status::Captured;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,9 @@ where
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::with_user_event().build();
|
let event_loop = EventLoopBuilder::with_user_event()
|
||||||
|
.build()
|
||||||
|
.expect("Create event loop");
|
||||||
let proxy = event_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
|
|
||||||
let runtime = {
|
let runtime = {
|
||||||
|
|
@ -155,7 +157,7 @@ where
|
||||||
{
|
{
|
||||||
use winit::platform::web::WindowExtWebSys;
|
use winit::platform::web::WindowExtWebSys;
|
||||||
|
|
||||||
let canvas = window.canvas();
|
let canvas = window.canvas().expect("Get window canvas");
|
||||||
|
|
||||||
let window = web_sys::window().unwrap();
|
let window = web_sys::window().unwrap();
|
||||||
let document = window.document().unwrap();
|
let document = window.document().unwrap();
|
||||||
|
|
@ -210,45 +212,28 @@ where
|
||||||
|
|
||||||
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
platform::run(event_loop, move |event, _, control_flow| {
|
let _ = event_loop.run(move |event, event_loop| {
|
||||||
use winit::event_loop::ControlFlow;
|
if event_loop.exiting() {
|
||||||
|
|
||||||
if let ControlFlow::ExitWithCode(_) = control_flow {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let event = match event {
|
event_sender.start_send(event).expect("Send event");
|
||||||
winit::event::Event::WindowEvent {
|
|
||||||
event:
|
let poll = instance.as_mut().poll(&mut context);
|
||||||
winit::event::WindowEvent::ScaleFactorChanged {
|
|
||||||
new_inner_size,
|
match poll {
|
||||||
..
|
task::Poll::Pending => {
|
||||||
},
|
if let Ok(Some(flow)) = control_receiver.try_next() {
|
||||||
window_id,
|
event_loop.set_control_flow(flow);
|
||||||
} => Some(winit::event::Event::WindowEvent {
|
}
|
||||||
event: winit::event::WindowEvent::Resized(*new_inner_size),
|
}
|
||||||
window_id,
|
task::Poll::Ready(_) => {
|
||||||
}),
|
event_loop.exit();
|
||||||
_ => event.to_static(),
|
}
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(event) = event {
|
Ok(())
|
||||||
event_sender.start_send(event).expect("Send event");
|
|
||||||
|
|
||||||
let poll = instance.as_mut().poll(&mut context);
|
|
||||||
|
|
||||||
match poll {
|
|
||||||
task::Poll::Pending => {
|
|
||||||
if let Ok(Some(flow)) = control_receiver.try_next() {
|
|
||||||
*control_flow = flow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
task::Poll::Ready(_) => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_instance<A, E, C>(
|
async fn run_instance<A, E, C>(
|
||||||
|
|
@ -259,7 +244,7 @@ async fn run_instance<A, E, C>(
|
||||||
mut proxy: winit::event_loop::EventLoopProxy<A::Message>,
|
mut proxy: winit::event_loop::EventLoopProxy<A::Message>,
|
||||||
mut debug: Debug,
|
mut debug: Debug,
|
||||||
mut event_receiver: mpsc::UnboundedReceiver<
|
mut event_receiver: mpsc::UnboundedReceiver<
|
||||||
winit::event::Event<'_, A::Message>,
|
winit::event::Event<A::Message>,
|
||||||
>,
|
>,
|
||||||
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
mut control_sender: mpsc::UnboundedSender<winit::event_loop::ControlFlow>,
|
||||||
init_command: Command<A::Message>,
|
init_command: Command<A::Message>,
|
||||||
|
|
@ -335,89 +320,24 @@ async fn run_instance<A, E, C>(
|
||||||
| event::StartCause::ResumeTimeReached { .. }
|
| event::StartCause::ResumeTimeReached { .. }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
event::Event::MainEventsCleared => {
|
event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(
|
||||||
if !redraw_pending && events.is_empty() && messages.is_empty() {
|
event::MacOS::ReceivedUrl(url),
|
||||||
continue;
|
)) => {
|
||||||
}
|
use crate::core::event;
|
||||||
|
|
||||||
debug.event_processing_started();
|
|
||||||
|
|
||||||
let (interface_state, statuses) = user_interface.update(
|
|
||||||
&events,
|
|
||||||
state.cursor(),
|
|
||||||
&mut renderer,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut messages,
|
|
||||||
);
|
|
||||||
|
|
||||||
debug.event_processing_finished();
|
|
||||||
|
|
||||||
for (event, status) in
|
|
||||||
events.drain(..).zip(statuses.into_iter())
|
|
||||||
{
|
|
||||||
runtime.broadcast(event, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !messages.is_empty()
|
|
||||||
|| matches!(
|
|
||||||
interface_state,
|
|
||||||
user_interface::State::Outdated
|
|
||||||
)
|
|
||||||
{
|
|
||||||
let mut cache =
|
|
||||||
ManuallyDrop::into_inner(user_interface).into_cache();
|
|
||||||
|
|
||||||
// Update application
|
|
||||||
update(
|
|
||||||
&mut application,
|
|
||||||
&mut compositor,
|
|
||||||
&mut surface,
|
|
||||||
&mut cache,
|
|
||||||
&state,
|
|
||||||
&mut renderer,
|
|
||||||
&mut runtime,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut should_exit,
|
|
||||||
&mut proxy,
|
|
||||||
&mut debug,
|
|
||||||
&mut messages,
|
|
||||||
&window,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update window
|
|
||||||
state.synchronize(&application, &window);
|
|
||||||
|
|
||||||
user_interface = ManuallyDrop::new(build_user_interface(
|
|
||||||
&application,
|
|
||||||
cache,
|
|
||||||
&mut renderer,
|
|
||||||
state.logical_size(),
|
|
||||||
&mut debug,
|
|
||||||
));
|
|
||||||
|
|
||||||
if should_exit {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Avoid redrawing all the time by forcing widgets to
|
|
||||||
// request redraws on state changes
|
|
||||||
//
|
|
||||||
// Then, we can use the `interface_state` here to decide if a redraw
|
|
||||||
// is needed right away, or simply wait until a specific time.
|
|
||||||
let redraw_event = Event::Window(
|
|
||||||
window::Id::MAIN,
|
|
||||||
window::Event::RedrawRequested(Instant::now()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let (interface_state, _) = user_interface.update(
|
|
||||||
&[redraw_event.clone()],
|
|
||||||
state.cursor(),
|
|
||||||
&mut renderer,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut messages,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
events.push(Event::PlatformSpecific(
|
||||||
|
event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(
|
||||||
|
url,
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
event::Event::UserEvent(message) => {
|
||||||
|
messages.push(message);
|
||||||
|
}
|
||||||
|
event::Event::WindowEvent {
|
||||||
|
event: event::WindowEvent::RedrawRequested { .. },
|
||||||
|
..
|
||||||
|
} => {
|
||||||
debug.draw_started();
|
debug.draw_started();
|
||||||
let new_mouse_interaction = user_interface.draw(
|
let new_mouse_interaction = user_interface.draw(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
|
|
@ -437,38 +357,6 @@ async fn run_instance<A, E, C>(
|
||||||
mouse_interaction = new_mouse_interaction;
|
mouse_interaction = new_mouse_interaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.request_redraw();
|
|
||||||
runtime.broadcast(redraw_event, core::event::Status::Ignored);
|
|
||||||
|
|
||||||
let _ = control_sender.start_send(match interface_state {
|
|
||||||
user_interface::State::Updated {
|
|
||||||
redraw_request: Some(redraw_request),
|
|
||||||
} => match redraw_request {
|
|
||||||
window::RedrawRequest::NextFrame => ControlFlow::Poll,
|
|
||||||
window::RedrawRequest::At(at) => {
|
|
||||||
ControlFlow::WaitUntil(at)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => ControlFlow::Wait,
|
|
||||||
});
|
|
||||||
|
|
||||||
redraw_pending = false;
|
|
||||||
}
|
|
||||||
event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(
|
|
||||||
event::MacOS::ReceivedUrl(url),
|
|
||||||
)) => {
|
|
||||||
use crate::core::event;
|
|
||||||
|
|
||||||
events.push(Event::PlatformSpecific(
|
|
||||||
event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(
|
|
||||||
url,
|
|
||||||
)),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
event::Event::UserEvent(message) => {
|
|
||||||
messages.push(message);
|
|
||||||
}
|
|
||||||
event::Event::RedrawRequested(_) => {
|
|
||||||
let physical_size = state.physical_size();
|
let physical_size = state.physical_size();
|
||||||
|
|
||||||
if physical_size.width == 0 || physical_size.height == 0 {
|
if physical_size.width == 0 || physical_size.height == 0 {
|
||||||
|
|
@ -566,6 +454,98 @@ async fn run_instance<A, E, C>(
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !redraw_pending && events.is_empty() && messages.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.event_processing_started();
|
||||||
|
|
||||||
|
let (interface_state, statuses) = user_interface.update(
|
||||||
|
&events,
|
||||||
|
state.cursor(),
|
||||||
|
&mut renderer,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut messages,
|
||||||
|
);
|
||||||
|
|
||||||
|
debug.event_processing_finished();
|
||||||
|
|
||||||
|
for (event, status) in events.drain(..).zip(statuses.into_iter()) {
|
||||||
|
runtime.broadcast(event, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !messages.is_empty()
|
||||||
|
|| matches!(interface_state, user_interface::State::Outdated)
|
||||||
|
{
|
||||||
|
let mut cache =
|
||||||
|
ManuallyDrop::into_inner(user_interface).into_cache();
|
||||||
|
|
||||||
|
// Update application
|
||||||
|
update(
|
||||||
|
&mut application,
|
||||||
|
&mut compositor,
|
||||||
|
&mut surface,
|
||||||
|
&mut cache,
|
||||||
|
&state,
|
||||||
|
&mut renderer,
|
||||||
|
&mut runtime,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut should_exit,
|
||||||
|
&mut proxy,
|
||||||
|
&mut debug,
|
||||||
|
&mut messages,
|
||||||
|
&window,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update window
|
||||||
|
state.synchronize(&application, &window);
|
||||||
|
|
||||||
|
user_interface = ManuallyDrop::new(build_user_interface(
|
||||||
|
&application,
|
||||||
|
cache,
|
||||||
|
&mut renderer,
|
||||||
|
state.logical_size(),
|
||||||
|
&mut debug,
|
||||||
|
));
|
||||||
|
|
||||||
|
if should_exit {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Avoid redrawing all the time by forcing widgets to
|
||||||
|
// request redraws on state changes
|
||||||
|
//
|
||||||
|
// Then, we can use the `interface_state` here to decide if a redraw
|
||||||
|
// is needed right away, or simply wait until a specific time.
|
||||||
|
let redraw_event = Event::Window(
|
||||||
|
window::Id::MAIN,
|
||||||
|
window::Event::RedrawRequested(Instant::now()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let (interface_state, _) = user_interface.update(
|
||||||
|
&[redraw_event.clone()],
|
||||||
|
state.cursor(),
|
||||||
|
&mut renderer,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut messages,
|
||||||
|
);
|
||||||
|
|
||||||
|
window.request_redraw();
|
||||||
|
runtime.broadcast(redraw_event, core::event::Status::Ignored);
|
||||||
|
|
||||||
|
let _ = control_sender.start_send(match interface_state {
|
||||||
|
user_interface::State::Updated {
|
||||||
|
redraw_request: Some(redraw_request),
|
||||||
|
} => match redraw_request {
|
||||||
|
window::RedrawRequest::NextFrame => ControlFlow::Poll,
|
||||||
|
window::RedrawRequest::At(at) => ControlFlow::WaitUntil(at),
|
||||||
|
},
|
||||||
|
_ => ControlFlow::Wait,
|
||||||
|
});
|
||||||
|
|
||||||
|
redraw_pending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually drop the user interface
|
// Manually drop the user interface
|
||||||
|
|
@ -575,8 +555,8 @@ async fn run_instance<A, E, C>(
|
||||||
/// Returns true if the provided event should cause an [`Application`] to
|
/// Returns true if the provided event should cause an [`Application`] to
|
||||||
/// exit.
|
/// exit.
|
||||||
pub fn requests_exit(
|
pub fn requests_exit(
|
||||||
event: &winit::event::WindowEvent<'_>,
|
event: &winit::event::WindowEvent,
|
||||||
_modifiers: winit::event::ModifiersState,
|
_modifiers: winit::keyboard::ModifiersState,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
use winit::event::WindowEvent;
|
use winit::event::WindowEvent;
|
||||||
|
|
||||||
|
|
@ -584,14 +564,14 @@ pub fn requests_exit(
|
||||||
WindowEvent::CloseRequested => true,
|
WindowEvent::CloseRequested => true,
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyEvent {
|
||||||
virtual_keycode: Some(winit::event::VirtualKeyCode::Q),
|
logical_key: winit::keyboard::Key::Character(c),
|
||||||
state: winit::event::ElementState::Pressed,
|
state: winit::event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} if _modifiers.logo() => true,
|
} if c == "q" && _modifiers.super_key() => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -726,10 +706,11 @@ pub fn run_command<A, C, E>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
window::Action::Resize(_id, size) => {
|
window::Action::Resize(_id, size) => {
|
||||||
window.set_inner_size(winit::dpi::LogicalSize {
|
let _ =
|
||||||
width: size.width,
|
window.request_inner_size(winit::dpi::LogicalSize {
|
||||||
height: size.height,
|
width: size.width,
|
||||||
});
|
height: size.height,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
window::Action::FetchSize(_id, callback) => {
|
window::Action::FetchSize(_id, callback) => {
|
||||||
let size =
|
let size =
|
||||||
|
|
@ -878,43 +859,3 @@ pub fn run_command<A, C, E>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod platform {
|
|
||||||
pub fn run<T, F>(
|
|
||||||
mut event_loop: winit::event_loop::EventLoop<T>,
|
|
||||||
event_handler: F,
|
|
||||||
) -> Result<(), super::Error>
|
|
||||||
where
|
|
||||||
F: 'static
|
|
||||||
+ FnMut(
|
|
||||||
winit::event::Event<'_, T>,
|
|
||||||
&winit::event_loop::EventLoopWindowTarget<T>,
|
|
||||||
&mut winit::event_loop::ControlFlow,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
|
||||||
|
|
||||||
let _ = event_loop.run_return(event_handler);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
mod platform {
|
|
||||||
pub fn run<T, F>(
|
|
||||||
event_loop: winit::event_loop::EventLoop<T>,
|
|
||||||
event_handler: F,
|
|
||||||
) -> !
|
|
||||||
where
|
|
||||||
F: 'static
|
|
||||||
+ FnMut(
|
|
||||||
winit::event::Event<'_, T>,
|
|
||||||
&winit::event_loop::EventLoopWindowTarget<T>,
|
|
||||||
&mut winit::event_loop::ControlFlow,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
event_loop.run(event_handler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ where
|
||||||
viewport: Viewport,
|
viewport: Viewport,
|
||||||
viewport_version: usize,
|
viewport_version: usize,
|
||||||
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||||
modifiers: winit::event::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
theme: <A::Renderer as core::Renderer>::Theme,
|
theme: <A::Renderer as core::Renderer>::Theme,
|
||||||
appearance: application::Appearance,
|
appearance: application::Appearance,
|
||||||
application: PhantomData<A>,
|
application: PhantomData<A>,
|
||||||
|
|
@ -54,7 +54,7 @@ where
|
||||||
viewport,
|
viewport,
|
||||||
viewport_version: 0,
|
viewport_version: 0,
|
||||||
cursor_position: None,
|
cursor_position: None,
|
||||||
modifiers: winit::event::ModifiersState::default(),
|
modifiers: winit::keyboard::ModifiersState::default(),
|
||||||
theme,
|
theme,
|
||||||
appearance,
|
appearance,
|
||||||
application: PhantomData,
|
application: PhantomData,
|
||||||
|
|
@ -102,7 +102,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current keyboard modifiers of the [`State`].
|
/// Returns the current keyboard modifiers of the [`State`].
|
||||||
pub fn modifiers(&self) -> winit::event::ModifiersState {
|
pub fn modifiers(&self) -> winit::keyboard::ModifiersState {
|
||||||
self.modifiers
|
self.modifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ where
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
window: &Window,
|
window: &Window,
|
||||||
event: &WindowEvent<'_>,
|
event: &WindowEvent,
|
||||||
_debug: &mut Debug,
|
_debug: &mut Debug,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
|
|
@ -142,10 +142,9 @@ where
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged {
|
WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor: new_scale_factor,
|
scale_factor: new_scale_factor,
|
||||||
new_inner_size,
|
..
|
||||||
} => {
|
} => {
|
||||||
let size =
|
let size = self.viewport.physical_size();
|
||||||
Size::new(new_inner_size.width, new_inner_size.height);
|
|
||||||
|
|
||||||
self.viewport = Viewport::with_physical_size(
|
self.viewport = Viewport::with_physical_size(
|
||||||
size,
|
size,
|
||||||
|
|
@ -164,13 +163,16 @@ where
|
||||||
self.cursor_position = None;
|
self.cursor_position = None;
|
||||||
}
|
}
|
||||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||||
self.modifiers = *new_modifiers;
|
self.modifiers = new_modifiers.state();
|
||||||
}
|
}
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyEvent {
|
||||||
virtual_keycode: Some(winit::event::VirtualKeyCode::F12),
|
logical_key:
|
||||||
|
winit::keyboard::Key::Named(
|
||||||
|
winit::keyboard::NamedKey::F12,
|
||||||
|
),
|
||||||
state: winit::event::ElementState::Pressed,
|
state: winit::event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,9 @@ pub fn window_settings(
|
||||||
/// Converts a winit window event into an iced event.
|
/// Converts a winit window event into an iced event.
|
||||||
pub fn window_event(
|
pub fn window_event(
|
||||||
id: window::Id,
|
id: window::Id,
|
||||||
event: &winit::event::WindowEvent<'_>,
|
event: &winit::event::WindowEvent,
|
||||||
scale_factor: f64,
|
scale_factor: f64,
|
||||||
modifiers: winit::event::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
) -> Option<Event> {
|
) -> Option<Event> {
|
||||||
use winit::event::WindowEvent;
|
use winit::event::WindowEvent;
|
||||||
|
|
||||||
|
|
@ -146,17 +146,6 @@ pub fn window_event(
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
|
|
||||||
let logical_size = new_inner_size.to_logical(scale_factor);
|
|
||||||
|
|
||||||
Some(Event::Window(
|
|
||||||
id,
|
|
||||||
window::Event::Resized {
|
|
||||||
width: logical_size.width,
|
|
||||||
height: logical_size.height,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
Some(Event::Window(id, window::Event::CloseRequested))
|
Some(Event::Window(id, window::Event::CloseRequested))
|
||||||
}
|
}
|
||||||
|
|
@ -203,19 +192,17 @@ pub fn window_event(
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WindowEvent::ReceivedCharacter(c) if !is_private_use_character(*c) => {
|
|
||||||
Some(Event::Keyboard(keyboard::Event::CharacterReceived(*c)))
|
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyEvent {
|
||||||
virtual_keycode: Some(virtual_keycode),
|
logical_key,
|
||||||
state,
|
state,
|
||||||
|
text,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => Some(Event::Keyboard({
|
} => Some(Event::Keyboard({
|
||||||
let key_code = key_code(*virtual_keycode);
|
let key_code = key_code(logical_key);
|
||||||
let modifiers = self::modifiers(modifiers);
|
let modifiers = self::modifiers(modifiers);
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
|
|
@ -223,6 +210,9 @@ pub fn window_event(
|
||||||
keyboard::Event::KeyPressed {
|
keyboard::Event::KeyPressed {
|
||||||
key_code,
|
key_code,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
text: text
|
||||||
|
.as_ref()
|
||||||
|
.map(winit::keyboard::SmolStr::to_string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
winit::event::ElementState::Released => {
|
winit::event::ElementState::Released => {
|
||||||
|
|
@ -233,9 +223,11 @@ pub fn window_event(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
WindowEvent::ModifiersChanged(new_modifiers) => Some(Event::Keyboard(
|
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||||
keyboard::Event::ModifiersChanged(self::modifiers(*new_modifiers)),
|
Some(Event::Keyboard(keyboard::Event::ModifiersChanged(
|
||||||
)),
|
self::modifiers(new_modifiers.state()),
|
||||||
|
)))
|
||||||
|
}
|
||||||
WindowEvent::Focused(focused) => Some(Event::Window(
|
WindowEvent::Focused(focused) => Some(Event::Window(
|
||||||
id,
|
id,
|
||||||
if *focused {
|
if *focused {
|
||||||
|
|
@ -365,7 +357,7 @@ pub fn mouse_interaction(
|
||||||
|
|
||||||
match interaction {
|
match interaction {
|
||||||
Interaction::Idle => winit::window::CursorIcon::Default,
|
Interaction::Idle => winit::window::CursorIcon::Default,
|
||||||
Interaction::Pointer => winit::window::CursorIcon::Hand,
|
Interaction::Pointer => winit::window::CursorIcon::Pointer,
|
||||||
Interaction::Working => winit::window::CursorIcon::Progress,
|
Interaction::Working => winit::window::CursorIcon::Progress,
|
||||||
Interaction::Grab => winit::window::CursorIcon::Grab,
|
Interaction::Grab => winit::window::CursorIcon::Grab,
|
||||||
Interaction::Grabbing => winit::window::CursorIcon::Grabbing,
|
Interaction::Grabbing => winit::window::CursorIcon::Grabbing,
|
||||||
|
|
@ -388,6 +380,8 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
|
||||||
winit::event::MouseButton::Left => mouse::Button::Left,
|
winit::event::MouseButton::Left => mouse::Button::Left,
|
||||||
winit::event::MouseButton::Right => mouse::Button::Right,
|
winit::event::MouseButton::Right => mouse::Button::Right,
|
||||||
winit::event::MouseButton::Middle => mouse::Button::Middle,
|
winit::event::MouseButton::Middle => mouse::Button::Middle,
|
||||||
|
winit::event::MouseButton::Back => mouse::Button::Back,
|
||||||
|
winit::event::MouseButton::Forward => mouse::Button::Forward,
|
||||||
winit::event::MouseButton::Other(other) => mouse::Button::Other(other),
|
winit::event::MouseButton::Other(other) => mouse::Button::Other(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -398,14 +392,14 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
|
||||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||||
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.10
|
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.10
|
||||||
pub fn modifiers(
|
pub fn modifiers(
|
||||||
modifiers: winit::event::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
) -> keyboard::Modifiers {
|
) -> keyboard::Modifiers {
|
||||||
let mut result = keyboard::Modifiers::empty();
|
let mut result = keyboard::Modifiers::empty();
|
||||||
|
|
||||||
result.set(keyboard::Modifiers::SHIFT, modifiers.shift());
|
result.set(keyboard::Modifiers::SHIFT, modifiers.shift_key());
|
||||||
result.set(keyboard::Modifiers::CTRL, modifiers.ctrl());
|
result.set(keyboard::Modifiers::CTRL, modifiers.control_key());
|
||||||
result.set(keyboard::Modifiers::ALT, modifiers.alt());
|
result.set(keyboard::Modifiers::ALT, modifiers.alt_key());
|
||||||
result.set(keyboard::Modifiers::LOGO, modifiers.logo());
|
result.set(keyboard::Modifiers::LOGO, modifiers.super_key());
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
@ -455,179 +449,125 @@ pub fn touch_event(
|
||||||
///
|
///
|
||||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||||
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.10
|
/// [`iced`]: https://github.com/iced-rs/iced/tree/0.10
|
||||||
pub fn key_code(
|
pub fn key_code(key: &winit::keyboard::Key) -> keyboard::KeyCode {
|
||||||
virtual_keycode: winit::event::VirtualKeyCode,
|
|
||||||
) -> keyboard::KeyCode {
|
|
||||||
use keyboard::KeyCode;
|
use keyboard::KeyCode;
|
||||||
|
use winit::keyboard::NamedKey;
|
||||||
|
|
||||||
match virtual_keycode {
|
match key {
|
||||||
winit::event::VirtualKeyCode::Key1 => KeyCode::Key1,
|
winit::keyboard::Key::Character(c) => match c.as_str() {
|
||||||
winit::event::VirtualKeyCode::Key2 => KeyCode::Key2,
|
"1" => KeyCode::Key1,
|
||||||
winit::event::VirtualKeyCode::Key3 => KeyCode::Key3,
|
"2" => KeyCode::Key2,
|
||||||
winit::event::VirtualKeyCode::Key4 => KeyCode::Key4,
|
"3" => KeyCode::Key3,
|
||||||
winit::event::VirtualKeyCode::Key5 => KeyCode::Key5,
|
"4" => KeyCode::Key4,
|
||||||
winit::event::VirtualKeyCode::Key6 => KeyCode::Key6,
|
"5" => KeyCode::Key5,
|
||||||
winit::event::VirtualKeyCode::Key7 => KeyCode::Key7,
|
"6" => KeyCode::Key6,
|
||||||
winit::event::VirtualKeyCode::Key8 => KeyCode::Key8,
|
"7" => KeyCode::Key7,
|
||||||
winit::event::VirtualKeyCode::Key9 => KeyCode::Key9,
|
"8" => KeyCode::Key8,
|
||||||
winit::event::VirtualKeyCode::Key0 => KeyCode::Key0,
|
"9" => KeyCode::Key9,
|
||||||
winit::event::VirtualKeyCode::A => KeyCode::A,
|
"0" => KeyCode::Key0,
|
||||||
winit::event::VirtualKeyCode::B => KeyCode::B,
|
"A" => KeyCode::A,
|
||||||
winit::event::VirtualKeyCode::C => KeyCode::C,
|
"B" => KeyCode::B,
|
||||||
winit::event::VirtualKeyCode::D => KeyCode::D,
|
"C" => KeyCode::C,
|
||||||
winit::event::VirtualKeyCode::E => KeyCode::E,
|
"D" => KeyCode::D,
|
||||||
winit::event::VirtualKeyCode::F => KeyCode::F,
|
"E" => KeyCode::E,
|
||||||
winit::event::VirtualKeyCode::G => KeyCode::G,
|
"F" => KeyCode::F,
|
||||||
winit::event::VirtualKeyCode::H => KeyCode::H,
|
"G" => KeyCode::G,
|
||||||
winit::event::VirtualKeyCode::I => KeyCode::I,
|
"H" => KeyCode::H,
|
||||||
winit::event::VirtualKeyCode::J => KeyCode::J,
|
"I" => KeyCode::I,
|
||||||
winit::event::VirtualKeyCode::K => KeyCode::K,
|
"J" => KeyCode::J,
|
||||||
winit::event::VirtualKeyCode::L => KeyCode::L,
|
"K" => KeyCode::K,
|
||||||
winit::event::VirtualKeyCode::M => KeyCode::M,
|
"L" => KeyCode::L,
|
||||||
winit::event::VirtualKeyCode::N => KeyCode::N,
|
"M" => KeyCode::M,
|
||||||
winit::event::VirtualKeyCode::O => KeyCode::O,
|
"N" => KeyCode::N,
|
||||||
winit::event::VirtualKeyCode::P => KeyCode::P,
|
"O" => KeyCode::O,
|
||||||
winit::event::VirtualKeyCode::Q => KeyCode::Q,
|
"P" => KeyCode::P,
|
||||||
winit::event::VirtualKeyCode::R => KeyCode::R,
|
"Q" => KeyCode::Q,
|
||||||
winit::event::VirtualKeyCode::S => KeyCode::S,
|
"R" => KeyCode::R,
|
||||||
winit::event::VirtualKeyCode::T => KeyCode::T,
|
"S" => KeyCode::S,
|
||||||
winit::event::VirtualKeyCode::U => KeyCode::U,
|
"T" => KeyCode::T,
|
||||||
winit::event::VirtualKeyCode::V => KeyCode::V,
|
"U" => KeyCode::U,
|
||||||
winit::event::VirtualKeyCode::W => KeyCode::W,
|
"V" => KeyCode::V,
|
||||||
winit::event::VirtualKeyCode::X => KeyCode::X,
|
"W" => KeyCode::W,
|
||||||
winit::event::VirtualKeyCode::Y => KeyCode::Y,
|
"X" => KeyCode::X,
|
||||||
winit::event::VirtualKeyCode::Z => KeyCode::Z,
|
"Y" => KeyCode::Y,
|
||||||
winit::event::VirtualKeyCode::Escape => KeyCode::Escape,
|
"Z" => KeyCode::Z,
|
||||||
winit::event::VirtualKeyCode::F1 => KeyCode::F1,
|
_ => KeyCode::Unlabeled,
|
||||||
winit::event::VirtualKeyCode::F2 => KeyCode::F2,
|
},
|
||||||
winit::event::VirtualKeyCode::F3 => KeyCode::F3,
|
winit::keyboard::Key::Named(named_key) => match named_key {
|
||||||
winit::event::VirtualKeyCode::F4 => KeyCode::F4,
|
NamedKey::Escape => KeyCode::Escape,
|
||||||
winit::event::VirtualKeyCode::F5 => KeyCode::F5,
|
NamedKey::F1 => KeyCode::F1,
|
||||||
winit::event::VirtualKeyCode::F6 => KeyCode::F6,
|
NamedKey::F2 => KeyCode::F2,
|
||||||
winit::event::VirtualKeyCode::F7 => KeyCode::F7,
|
NamedKey::F3 => KeyCode::F3,
|
||||||
winit::event::VirtualKeyCode::F8 => KeyCode::F8,
|
NamedKey::F4 => KeyCode::F4,
|
||||||
winit::event::VirtualKeyCode::F9 => KeyCode::F9,
|
NamedKey::F5 => KeyCode::F5,
|
||||||
winit::event::VirtualKeyCode::F10 => KeyCode::F10,
|
NamedKey::F6 => KeyCode::F6,
|
||||||
winit::event::VirtualKeyCode::F11 => KeyCode::F11,
|
NamedKey::F7 => KeyCode::F7,
|
||||||
winit::event::VirtualKeyCode::F12 => KeyCode::F12,
|
NamedKey::F8 => KeyCode::F8,
|
||||||
winit::event::VirtualKeyCode::F13 => KeyCode::F13,
|
NamedKey::F9 => KeyCode::F9,
|
||||||
winit::event::VirtualKeyCode::F14 => KeyCode::F14,
|
NamedKey::F10 => KeyCode::F10,
|
||||||
winit::event::VirtualKeyCode::F15 => KeyCode::F15,
|
NamedKey::F11 => KeyCode::F11,
|
||||||
winit::event::VirtualKeyCode::F16 => KeyCode::F16,
|
NamedKey::F12 => KeyCode::F12,
|
||||||
winit::event::VirtualKeyCode::F17 => KeyCode::F17,
|
NamedKey::F13 => KeyCode::F13,
|
||||||
winit::event::VirtualKeyCode::F18 => KeyCode::F18,
|
NamedKey::F14 => KeyCode::F14,
|
||||||
winit::event::VirtualKeyCode::F19 => KeyCode::F19,
|
NamedKey::F15 => KeyCode::F15,
|
||||||
winit::event::VirtualKeyCode::F20 => KeyCode::F20,
|
NamedKey::F16 => KeyCode::F16,
|
||||||
winit::event::VirtualKeyCode::F21 => KeyCode::F21,
|
NamedKey::F17 => KeyCode::F17,
|
||||||
winit::event::VirtualKeyCode::F22 => KeyCode::F22,
|
NamedKey::F18 => KeyCode::F18,
|
||||||
winit::event::VirtualKeyCode::F23 => KeyCode::F23,
|
NamedKey::F19 => KeyCode::F19,
|
||||||
winit::event::VirtualKeyCode::F24 => KeyCode::F24,
|
NamedKey::F20 => KeyCode::F20,
|
||||||
winit::event::VirtualKeyCode::Snapshot => KeyCode::Snapshot,
|
NamedKey::F21 => KeyCode::F21,
|
||||||
winit::event::VirtualKeyCode::Scroll => KeyCode::Scroll,
|
NamedKey::F22 => KeyCode::F22,
|
||||||
winit::event::VirtualKeyCode::Pause => KeyCode::Pause,
|
NamedKey::F23 => KeyCode::F23,
|
||||||
winit::event::VirtualKeyCode::Insert => KeyCode::Insert,
|
NamedKey::F24 => KeyCode::F24,
|
||||||
winit::event::VirtualKeyCode::Home => KeyCode::Home,
|
NamedKey::PrintScreen => KeyCode::Snapshot,
|
||||||
winit::event::VirtualKeyCode::Delete => KeyCode::Delete,
|
NamedKey::ScrollLock => KeyCode::Scroll,
|
||||||
winit::event::VirtualKeyCode::End => KeyCode::End,
|
NamedKey::Pause => KeyCode::Pause,
|
||||||
winit::event::VirtualKeyCode::PageDown => KeyCode::PageDown,
|
NamedKey::Insert => KeyCode::Insert,
|
||||||
winit::event::VirtualKeyCode::PageUp => KeyCode::PageUp,
|
NamedKey::Home => KeyCode::Home,
|
||||||
winit::event::VirtualKeyCode::Left => KeyCode::Left,
|
NamedKey::Delete => KeyCode::Delete,
|
||||||
winit::event::VirtualKeyCode::Up => KeyCode::Up,
|
NamedKey::End => KeyCode::End,
|
||||||
winit::event::VirtualKeyCode::Right => KeyCode::Right,
|
NamedKey::PageDown => KeyCode::PageDown,
|
||||||
winit::event::VirtualKeyCode::Down => KeyCode::Down,
|
NamedKey::PageUp => KeyCode::PageUp,
|
||||||
winit::event::VirtualKeyCode::Back => KeyCode::Backspace,
|
NamedKey::ArrowLeft => KeyCode::Left,
|
||||||
winit::event::VirtualKeyCode::Return => KeyCode::Enter,
|
NamedKey::ArrowUp => KeyCode::Up,
|
||||||
winit::event::VirtualKeyCode::Space => KeyCode::Space,
|
NamedKey::ArrowRight => KeyCode::Right,
|
||||||
winit::event::VirtualKeyCode::Compose => KeyCode::Compose,
|
NamedKey::ArrowDown => KeyCode::Down,
|
||||||
winit::event::VirtualKeyCode::Caret => KeyCode::Caret,
|
NamedKey::Backspace => KeyCode::Backspace,
|
||||||
winit::event::VirtualKeyCode::Numlock => KeyCode::Numlock,
|
NamedKey::Enter => KeyCode::Enter,
|
||||||
winit::event::VirtualKeyCode::Numpad0 => KeyCode::Numpad0,
|
NamedKey::Space => KeyCode::Space,
|
||||||
winit::event::VirtualKeyCode::Numpad1 => KeyCode::Numpad1,
|
NamedKey::Compose => KeyCode::Compose,
|
||||||
winit::event::VirtualKeyCode::Numpad2 => KeyCode::Numpad2,
|
NamedKey::NumLock => KeyCode::Numlock,
|
||||||
winit::event::VirtualKeyCode::Numpad3 => KeyCode::Numpad3,
|
NamedKey::AppSwitch => KeyCode::Apps,
|
||||||
winit::event::VirtualKeyCode::Numpad4 => KeyCode::Numpad4,
|
NamedKey::Convert => KeyCode::Convert,
|
||||||
winit::event::VirtualKeyCode::Numpad5 => KeyCode::Numpad5,
|
NamedKey::LaunchMail => KeyCode::Mail,
|
||||||
winit::event::VirtualKeyCode::Numpad6 => KeyCode::Numpad6,
|
NamedKey::MediaApps => KeyCode::MediaSelect,
|
||||||
winit::event::VirtualKeyCode::Numpad7 => KeyCode::Numpad7,
|
NamedKey::MediaStop => KeyCode::MediaStop,
|
||||||
winit::event::VirtualKeyCode::Numpad8 => KeyCode::Numpad8,
|
NamedKey::AudioVolumeMute => KeyCode::Mute,
|
||||||
winit::event::VirtualKeyCode::Numpad9 => KeyCode::Numpad9,
|
NamedKey::MediaStepForward => KeyCode::NavigateForward,
|
||||||
winit::event::VirtualKeyCode::AbntC1 => KeyCode::AbntC1,
|
NamedKey::MediaStepBackward => KeyCode::NavigateBackward,
|
||||||
winit::event::VirtualKeyCode::AbntC2 => KeyCode::AbntC2,
|
NamedKey::MediaSkipForward => KeyCode::NextTrack,
|
||||||
winit::event::VirtualKeyCode::NumpadAdd => KeyCode::NumpadAdd,
|
NamedKey::NonConvert => KeyCode::NoConvert,
|
||||||
winit::event::VirtualKeyCode::Plus => KeyCode::Plus,
|
NamedKey::MediaPlayPause => KeyCode::PlayPause,
|
||||||
winit::event::VirtualKeyCode::Apostrophe => KeyCode::Apostrophe,
|
NamedKey::Power => KeyCode::Power,
|
||||||
winit::event::VirtualKeyCode::Apps => KeyCode::Apps,
|
NamedKey::MediaSkipBackward => KeyCode::PrevTrack,
|
||||||
winit::event::VirtualKeyCode::At => KeyCode::At,
|
NamedKey::PowerOff => KeyCode::Sleep,
|
||||||
winit::event::VirtualKeyCode::Ax => KeyCode::Ax,
|
NamedKey::Tab => KeyCode::Tab,
|
||||||
winit::event::VirtualKeyCode::Backslash => KeyCode::Backslash,
|
NamedKey::AudioVolumeDown => KeyCode::VolumeDown,
|
||||||
winit::event::VirtualKeyCode::Calculator => KeyCode::Calculator,
|
NamedKey::AudioVolumeUp => KeyCode::VolumeUp,
|
||||||
winit::event::VirtualKeyCode::Capital => KeyCode::Capital,
|
NamedKey::WakeUp => KeyCode::Wake,
|
||||||
winit::event::VirtualKeyCode::Colon => KeyCode::Colon,
|
NamedKey::BrowserBack => KeyCode::WebBack,
|
||||||
winit::event::VirtualKeyCode::Comma => KeyCode::Comma,
|
NamedKey::BrowserFavorites => KeyCode::WebFavorites,
|
||||||
winit::event::VirtualKeyCode::Convert => KeyCode::Convert,
|
NamedKey::BrowserForward => KeyCode::WebForward,
|
||||||
winit::event::VirtualKeyCode::NumpadDecimal => KeyCode::NumpadDecimal,
|
NamedKey::BrowserHome => KeyCode::WebHome,
|
||||||
winit::event::VirtualKeyCode::NumpadDivide => KeyCode::NumpadDivide,
|
NamedKey::BrowserRefresh => KeyCode::WebRefresh,
|
||||||
winit::event::VirtualKeyCode::Equals => KeyCode::Equals,
|
NamedKey::BrowserSearch => KeyCode::WebSearch,
|
||||||
winit::event::VirtualKeyCode::Grave => KeyCode::Grave,
|
NamedKey::BrowserStop => KeyCode::WebStop,
|
||||||
winit::event::VirtualKeyCode::Kana => KeyCode::Kana,
|
NamedKey::Copy => KeyCode::Copy,
|
||||||
winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji,
|
NamedKey::Paste => KeyCode::Paste,
|
||||||
winit::event::VirtualKeyCode::LAlt => KeyCode::LAlt,
|
NamedKey::Cut => KeyCode::Cut,
|
||||||
winit::event::VirtualKeyCode::LBracket => KeyCode::LBracket,
|
_ => KeyCode::Unlabeled,
|
||||||
winit::event::VirtualKeyCode::LControl => KeyCode::LControl,
|
},
|
||||||
winit::event::VirtualKeyCode::LShift => KeyCode::LShift,
|
_ => KeyCode::Unlabeled,
|
||||||
winit::event::VirtualKeyCode::LWin => KeyCode::LWin,
|
|
||||||
winit::event::VirtualKeyCode::Mail => KeyCode::Mail,
|
|
||||||
winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect,
|
|
||||||
winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop,
|
|
||||||
winit::event::VirtualKeyCode::Minus => KeyCode::Minus,
|
|
||||||
winit::event::VirtualKeyCode::NumpadMultiply => KeyCode::NumpadMultiply,
|
|
||||||
winit::event::VirtualKeyCode::Mute => KeyCode::Mute,
|
|
||||||
winit::event::VirtualKeyCode::MyComputer => KeyCode::MyComputer,
|
|
||||||
winit::event::VirtualKeyCode::NavigateForward => {
|
|
||||||
KeyCode::NavigateForward
|
|
||||||
}
|
|
||||||
winit::event::VirtualKeyCode::NavigateBackward => {
|
|
||||||
KeyCode::NavigateBackward
|
|
||||||
}
|
|
||||||
winit::event::VirtualKeyCode::NextTrack => KeyCode::NextTrack,
|
|
||||||
winit::event::VirtualKeyCode::NoConvert => KeyCode::NoConvert,
|
|
||||||
winit::event::VirtualKeyCode::NumpadComma => KeyCode::NumpadComma,
|
|
||||||
winit::event::VirtualKeyCode::NumpadEnter => KeyCode::NumpadEnter,
|
|
||||||
winit::event::VirtualKeyCode::NumpadEquals => KeyCode::NumpadEquals,
|
|
||||||
winit::event::VirtualKeyCode::OEM102 => KeyCode::OEM102,
|
|
||||||
winit::event::VirtualKeyCode::Period => KeyCode::Period,
|
|
||||||
winit::event::VirtualKeyCode::PlayPause => KeyCode::PlayPause,
|
|
||||||
winit::event::VirtualKeyCode::Power => KeyCode::Power,
|
|
||||||
winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack,
|
|
||||||
winit::event::VirtualKeyCode::RAlt => KeyCode::RAlt,
|
|
||||||
winit::event::VirtualKeyCode::RBracket => KeyCode::RBracket,
|
|
||||||
winit::event::VirtualKeyCode::RControl => KeyCode::RControl,
|
|
||||||
winit::event::VirtualKeyCode::RShift => KeyCode::RShift,
|
|
||||||
winit::event::VirtualKeyCode::RWin => KeyCode::RWin,
|
|
||||||
winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon,
|
|
||||||
winit::event::VirtualKeyCode::Slash => KeyCode::Slash,
|
|
||||||
winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep,
|
|
||||||
winit::event::VirtualKeyCode::Stop => KeyCode::Stop,
|
|
||||||
winit::event::VirtualKeyCode::NumpadSubtract => KeyCode::NumpadSubtract,
|
|
||||||
winit::event::VirtualKeyCode::Sysrq => KeyCode::Sysrq,
|
|
||||||
winit::event::VirtualKeyCode::Tab => KeyCode::Tab,
|
|
||||||
winit::event::VirtualKeyCode::Underline => KeyCode::Underline,
|
|
||||||
winit::event::VirtualKeyCode::Unlabeled => KeyCode::Unlabeled,
|
|
||||||
winit::event::VirtualKeyCode::VolumeDown => KeyCode::VolumeDown,
|
|
||||||
winit::event::VirtualKeyCode::VolumeUp => KeyCode::VolumeUp,
|
|
||||||
winit::event::VirtualKeyCode::Wake => KeyCode::Wake,
|
|
||||||
winit::event::VirtualKeyCode::WebBack => KeyCode::WebBack,
|
|
||||||
winit::event::VirtualKeyCode::WebFavorites => KeyCode::WebFavorites,
|
|
||||||
winit::event::VirtualKeyCode::WebForward => KeyCode::WebForward,
|
|
||||||
winit::event::VirtualKeyCode::WebHome => KeyCode::WebHome,
|
|
||||||
winit::event::VirtualKeyCode::WebRefresh => KeyCode::WebRefresh,
|
|
||||||
winit::event::VirtualKeyCode::WebSearch => KeyCode::WebSearch,
|
|
||||||
winit::event::VirtualKeyCode::WebStop => KeyCode::WebStop,
|
|
||||||
winit::event::VirtualKeyCode::Yen => KeyCode::Yen,
|
|
||||||
winit::event::VirtualKeyCode::Copy => KeyCode::Copy,
|
|
||||||
winit::event::VirtualKeyCode::Paste => KeyCode::Paste,
|
|
||||||
winit::event::VirtualKeyCode::Cut => KeyCode::Cut,
|
|
||||||
winit::event::VirtualKeyCode::Asterisk => KeyCode::Asterisk,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -655,13 +595,3 @@ pub fn icon(icon: window::Icon) -> Option<winit::window::Icon> {
|
||||||
|
|
||||||
winit::window::Icon::from_rgba(pixels, size.width, size.height).ok()
|
winit::window::Icon::from_rgba(pixels, size.width, size.height).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
// As defined in: http://www.unicode.org/faq/private_use.html
|
|
||||||
pub(crate) fn is_private_use_character(c: char) -> bool {
|
|
||||||
matches!(
|
|
||||||
c,
|
|
||||||
'\u{E000}'..='\u{F8FF}'
|
|
||||||
| '\u{F0000}'..='\u{FFFFD}'
|
|
||||||
| '\u{100000}'..='\u{10FFFD}'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,10 @@ where
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
debug.startup_started();
|
debug.startup_started();
|
||||||
|
|
||||||
let event_loop = EventLoopBuilder::with_user_event().build();
|
let event_loop = EventLoopBuilder::with_user_event()
|
||||||
|
.build()
|
||||||
|
.expect("Create event loop");
|
||||||
|
|
||||||
let proxy = event_loop.create_proxy();
|
let proxy = event_loop.create_proxy();
|
||||||
|
|
||||||
let runtime = {
|
let runtime = {
|
||||||
|
|
@ -210,78 +213,64 @@ where
|
||||||
|
|
||||||
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
let mut context = task::Context::from_waker(task::noop_waker_ref());
|
||||||
|
|
||||||
platform::run(event_loop, move |event, window_target, control_flow| {
|
let _ = event_loop.run(move |event, event_loop| {
|
||||||
use winit::event_loop::ControlFlow;
|
if event_loop.exiting() {
|
||||||
|
|
||||||
if let ControlFlow::ExitWithCode(_) = control_flow {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let event = match event {
|
event_sender
|
||||||
winit::event::Event::WindowEvent {
|
.start_send(Event::EventLoopAwakened(event))
|
||||||
event:
|
.expect("Send event");
|
||||||
winit::event::WindowEvent::ScaleFactorChanged {
|
|
||||||
new_inner_size,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
window_id,
|
|
||||||
} => Some(winit::event::Event::WindowEvent {
|
|
||||||
event: winit::event::WindowEvent::Resized(*new_inner_size),
|
|
||||||
window_id,
|
|
||||||
}),
|
|
||||||
_ => event.to_static(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(event) = event {
|
loop {
|
||||||
event_sender
|
let poll = instance.as_mut().poll(&mut context);
|
||||||
.start_send(Event::EventLoopAwakened(event))
|
|
||||||
.expect("Send event");
|
|
||||||
|
|
||||||
loop {
|
match poll {
|
||||||
let poll = instance.as_mut().poll(&mut context);
|
task::Poll::Pending => match control_receiver.try_next() {
|
||||||
|
Ok(Some(control)) => match control {
|
||||||
|
Control::ChangeFlow(flow) => {
|
||||||
|
event_loop.set_control_flow(flow);
|
||||||
|
}
|
||||||
|
Control::CreateWindow {
|
||||||
|
id,
|
||||||
|
settings,
|
||||||
|
title,
|
||||||
|
monitor,
|
||||||
|
} => {
|
||||||
|
let exit_on_close_request =
|
||||||
|
settings.exit_on_close_request;
|
||||||
|
|
||||||
match poll {
|
let window = conversion::window_settings(
|
||||||
task::Poll::Pending => match control_receiver.try_next() {
|
settings, &title, monitor, None,
|
||||||
Ok(Some(control)) => match control {
|
)
|
||||||
Control::ChangeFlow(flow) => {
|
.build(event_loop)
|
||||||
*control_flow = flow;
|
.expect("Failed to build window");
|
||||||
}
|
|
||||||
Control::CreateWindow {
|
|
||||||
id,
|
|
||||||
settings,
|
|
||||||
title,
|
|
||||||
monitor,
|
|
||||||
} => {
|
|
||||||
let exit_on_close_request =
|
|
||||||
settings.exit_on_close_request;
|
|
||||||
|
|
||||||
let window = conversion::window_settings(
|
event_sender
|
||||||
settings, &title, monitor, None,
|
.start_send(Event::WindowCreated {
|
||||||
)
|
id,
|
||||||
.build(window_target)
|
window,
|
||||||
.expect("Failed to build window");
|
exit_on_close_request,
|
||||||
|
})
|
||||||
event_sender
|
.expect("Send event");
|
||||||
.start_send(Event::WindowCreated {
|
}
|
||||||
id,
|
Control::Exit => {
|
||||||
window,
|
event_loop.exit();
|
||||||
exit_on_close_request,
|
|
||||||
})
|
|
||||||
.expect("Send event");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
task::Poll::Ready(_) => {
|
_ => {
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
}
|
task::Poll::Ready(_) => {
|
||||||
|
event_loop.exit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event<Message: 'static> {
|
enum Event<Message: 'static> {
|
||||||
|
|
@ -290,11 +279,12 @@ enum Event<Message: 'static> {
|
||||||
window: winit::window::Window,
|
window: winit::window::Window,
|
||||||
exit_on_close_request: bool,
|
exit_on_close_request: bool,
|
||||||
},
|
},
|
||||||
EventLoopAwakened(winit::event::Event<'static, Message>),
|
EventLoopAwakened(winit::event::Event<Message>),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Control {
|
enum Control {
|
||||||
ChangeFlow(winit::event_loop::ControlFlow),
|
ChangeFlow(winit::event_loop::ControlFlow),
|
||||||
|
Exit,
|
||||||
CreateWindow {
|
CreateWindow {
|
||||||
id: window::Id,
|
id: window::Id,
|
||||||
settings: window::Settings,
|
settings: window::Settings,
|
||||||
|
|
@ -427,184 +417,6 @@ async fn run_instance<A, E, C>(
|
||||||
| event::StartCause::ResumeTimeReached { .. }
|
| event::StartCause::ResumeTimeReached { .. }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
event::Event::MainEventsCleared => {
|
|
||||||
debug.event_processing_started();
|
|
||||||
let mut uis_stale = false;
|
|
||||||
|
|
||||||
for (id, window) in window_manager.iter_mut() {
|
|
||||||
let mut window_events = vec![];
|
|
||||||
|
|
||||||
events.retain(|(window_id, event)| {
|
|
||||||
if *window_id == Some(id) || window_id.is_none()
|
|
||||||
{
|
|
||||||
window_events.push(event.clone());
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if !redraw_pending
|
|
||||||
&& window_events.is_empty()
|
|
||||||
&& messages.is_empty()
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (ui_state, statuses) = user_interfaces
|
|
||||||
.get_mut(&id)
|
|
||||||
.expect("Get user interface")
|
|
||||||
.update(
|
|
||||||
&window_events,
|
|
||||||
window.state.cursor(),
|
|
||||||
&mut window.renderer,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut messages,
|
|
||||||
);
|
|
||||||
|
|
||||||
if !uis_stale {
|
|
||||||
uis_stale = matches!(
|
|
||||||
ui_state,
|
|
||||||
user_interface::State::Outdated
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (event, status) in window_events
|
|
||||||
.into_iter()
|
|
||||||
.zip(statuses.into_iter())
|
|
||||||
{
|
|
||||||
runtime.broadcast(event, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.event_processing_finished();
|
|
||||||
|
|
||||||
// TODO mw application update returns which window IDs to update
|
|
||||||
if !messages.is_empty() || uis_stale {
|
|
||||||
let mut cached_interfaces: HashMap<
|
|
||||||
window::Id,
|
|
||||||
user_interface::Cache,
|
|
||||||
> = ManuallyDrop::into_inner(user_interfaces)
|
|
||||||
.drain()
|
|
||||||
.map(|(id, ui)| (id, ui.into_cache()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Update application
|
|
||||||
update(
|
|
||||||
&mut application,
|
|
||||||
&mut compositor,
|
|
||||||
&mut runtime,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut control_sender,
|
|
||||||
&mut proxy,
|
|
||||||
&mut debug,
|
|
||||||
&mut messages,
|
|
||||||
&mut window_manager,
|
|
||||||
&mut cached_interfaces,
|
|
||||||
);
|
|
||||||
|
|
||||||
// we must synchronize all window states with application state after an
|
|
||||||
// application update since we don't know what changed
|
|
||||||
for (id, window) in window_manager.iter_mut() {
|
|
||||||
window.state.synchronize(
|
|
||||||
&application,
|
|
||||||
id,
|
|
||||||
&window.raw,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rebuild UIs with the synchronized states
|
|
||||||
user_interfaces =
|
|
||||||
ManuallyDrop::new(build_user_interfaces(
|
|
||||||
&application,
|
|
||||||
&mut debug,
|
|
||||||
&mut window_manager,
|
|
||||||
cached_interfaces,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug.draw_started();
|
|
||||||
|
|
||||||
for (id, window) in window_manager.iter_mut() {
|
|
||||||
// TODO: Avoid redrawing all the time by forcing widgets to
|
|
||||||
// request redraws on state changes
|
|
||||||
//
|
|
||||||
// Then, we can use the `interface_state` here to decide if a redraw
|
|
||||||
// is needed right away, or simply wait until a specific time.
|
|
||||||
let redraw_event = core::Event::Window(
|
|
||||||
id,
|
|
||||||
window::Event::RedrawRequested(Instant::now()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let cursor = window.state.cursor();
|
|
||||||
|
|
||||||
let ui = user_interfaces
|
|
||||||
.get_mut(&id)
|
|
||||||
.expect("Get user interface");
|
|
||||||
|
|
||||||
let (ui_state, _) = ui.update(
|
|
||||||
&[redraw_event.clone()],
|
|
||||||
cursor,
|
|
||||||
&mut window.renderer,
|
|
||||||
&mut clipboard,
|
|
||||||
&mut messages,
|
|
||||||
);
|
|
||||||
|
|
||||||
let new_mouse_interaction = {
|
|
||||||
let state = &window.state;
|
|
||||||
|
|
||||||
ui.draw(
|
|
||||||
&mut window.renderer,
|
|
||||||
state.theme(),
|
|
||||||
&renderer::Style {
|
|
||||||
text_color: state.text_color(),
|
|
||||||
},
|
|
||||||
cursor,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
if new_mouse_interaction != window.mouse_interaction
|
|
||||||
{
|
|
||||||
window.raw.set_cursor_icon(
|
|
||||||
conversion::mouse_interaction(
|
|
||||||
new_mouse_interaction,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
window.mouse_interaction =
|
|
||||||
new_mouse_interaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO once widgets can request to be redrawn, we can avoid always requesting a
|
|
||||||
// redraw
|
|
||||||
window.raw.request_redraw();
|
|
||||||
|
|
||||||
runtime.broadcast(
|
|
||||||
redraw_event.clone(),
|
|
||||||
core::event::Status::Ignored,
|
|
||||||
);
|
|
||||||
|
|
||||||
let _ = control_sender.start_send(
|
|
||||||
Control::ChangeFlow(match ui_state {
|
|
||||||
user_interface::State::Updated {
|
|
||||||
redraw_request: Some(redraw_request),
|
|
||||||
} => match redraw_request {
|
|
||||||
window::RedrawRequest::NextFrame => {
|
|
||||||
ControlFlow::Poll
|
|
||||||
}
|
|
||||||
window::RedrawRequest::At(at) => {
|
|
||||||
ControlFlow::WaitUntil(at)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => ControlFlow::Wait,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
redraw_pending = false;
|
|
||||||
|
|
||||||
debug.draw_finished();
|
|
||||||
}
|
|
||||||
event::Event::PlatformSpecific(
|
event::Event::PlatformSpecific(
|
||||||
event::PlatformSpecific::MacOS(
|
event::PlatformSpecific::MacOS(
|
||||||
event::MacOS::ReceivedUrl(url),
|
event::MacOS::ReceivedUrl(url),
|
||||||
|
|
@ -624,7 +436,11 @@ async fn run_instance<A, E, C>(
|
||||||
event::Event::UserEvent(message) => {
|
event::Event::UserEvent(message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
event::Event::RedrawRequested(id) => {
|
event::Event::WindowEvent {
|
||||||
|
window_id: id,
|
||||||
|
event: event::WindowEvent::RedrawRequested,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
let Some((id, window)) =
|
let Some((id, window)) =
|
||||||
window_manager.get_mut_alias(id)
|
window_manager.get_mut_alias(id)
|
||||||
else {
|
else {
|
||||||
|
|
@ -775,6 +591,163 @@ async fn run_instance<A, E, C>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug.event_processing_started();
|
||||||
|
let mut uis_stale = false;
|
||||||
|
|
||||||
|
for (id, window) in window_manager.iter_mut() {
|
||||||
|
let mut window_events = vec![];
|
||||||
|
|
||||||
|
events.retain(|(window_id, event)| {
|
||||||
|
if *window_id == Some(id) || window_id.is_none() {
|
||||||
|
window_events.push(event.clone());
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if !redraw_pending
|
||||||
|
&& window_events.is_empty()
|
||||||
|
&& messages.is_empty()
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (ui_state, statuses) = user_interfaces
|
||||||
|
.get_mut(&id)
|
||||||
|
.expect("Get user interface")
|
||||||
|
.update(
|
||||||
|
&window_events,
|
||||||
|
window.state.cursor(),
|
||||||
|
&mut window.renderer,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut messages,
|
||||||
|
);
|
||||||
|
|
||||||
|
if !uis_stale {
|
||||||
|
uis_stale = matches!(ui_state, user_interface::State::Outdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (event, status) in
|
||||||
|
window_events.into_iter().zip(statuses.into_iter())
|
||||||
|
{
|
||||||
|
runtime.broadcast(event, status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.event_processing_finished();
|
||||||
|
|
||||||
|
// TODO mw application update returns which window IDs to update
|
||||||
|
if !messages.is_empty() || uis_stale {
|
||||||
|
let mut cached_interfaces: HashMap<
|
||||||
|
window::Id,
|
||||||
|
user_interface::Cache,
|
||||||
|
> = ManuallyDrop::into_inner(user_interfaces)
|
||||||
|
.drain()
|
||||||
|
.map(|(id, ui)| (id, ui.into_cache()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Update application
|
||||||
|
update(
|
||||||
|
&mut application,
|
||||||
|
&mut compositor,
|
||||||
|
&mut runtime,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut control_sender,
|
||||||
|
&mut proxy,
|
||||||
|
&mut debug,
|
||||||
|
&mut messages,
|
||||||
|
&mut window_manager,
|
||||||
|
&mut cached_interfaces,
|
||||||
|
);
|
||||||
|
|
||||||
|
// we must synchronize all window states with application state after an
|
||||||
|
// application update since we don't know what changed
|
||||||
|
for (id, window) in window_manager.iter_mut() {
|
||||||
|
window.state.synchronize(&application, id, &window.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rebuild UIs with the synchronized states
|
||||||
|
user_interfaces = ManuallyDrop::new(build_user_interfaces(
|
||||||
|
&application,
|
||||||
|
&mut debug,
|
||||||
|
&mut window_manager,
|
||||||
|
cached_interfaces,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.draw_started();
|
||||||
|
|
||||||
|
for (id, window) in window_manager.iter_mut() {
|
||||||
|
// TODO: Avoid redrawing all the time by forcing widgets to
|
||||||
|
// request redraws on state changes
|
||||||
|
//
|
||||||
|
// Then, we can use the `interface_state` here to decide if a redraw
|
||||||
|
// is needed right away, or simply wait until a specific time.
|
||||||
|
let redraw_event = core::Event::Window(
|
||||||
|
id,
|
||||||
|
window::Event::RedrawRequested(Instant::now()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let cursor = window.state.cursor();
|
||||||
|
|
||||||
|
let ui = user_interfaces.get_mut(&id).expect("Get user interface");
|
||||||
|
|
||||||
|
let (ui_state, _) = ui.update(
|
||||||
|
&[redraw_event.clone()],
|
||||||
|
cursor,
|
||||||
|
&mut window.renderer,
|
||||||
|
&mut clipboard,
|
||||||
|
&mut messages,
|
||||||
|
);
|
||||||
|
|
||||||
|
let new_mouse_interaction = {
|
||||||
|
let state = &window.state;
|
||||||
|
|
||||||
|
ui.draw(
|
||||||
|
&mut window.renderer,
|
||||||
|
state.theme(),
|
||||||
|
&renderer::Style {
|
||||||
|
text_color: state.text_color(),
|
||||||
|
},
|
||||||
|
cursor,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if new_mouse_interaction != window.mouse_interaction {
|
||||||
|
window.raw.set_cursor_icon(conversion::mouse_interaction(
|
||||||
|
new_mouse_interaction,
|
||||||
|
));
|
||||||
|
|
||||||
|
window.mouse_interaction = new_mouse_interaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO once widgets can request to be redrawn, we can avoid always requesting a
|
||||||
|
// redraw
|
||||||
|
window.raw.request_redraw();
|
||||||
|
|
||||||
|
runtime
|
||||||
|
.broadcast(redraw_event.clone(), core::event::Status::Ignored);
|
||||||
|
|
||||||
|
let _ = control_sender.start_send(Control::ChangeFlow(
|
||||||
|
match ui_state {
|
||||||
|
user_interface::State::Updated {
|
||||||
|
redraw_request: Some(redraw_request),
|
||||||
|
} => match redraw_request {
|
||||||
|
window::RedrawRequest::NextFrame => ControlFlow::Poll,
|
||||||
|
window::RedrawRequest::At(at) => {
|
||||||
|
ControlFlow::WaitUntil(at)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => ControlFlow::Wait,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
redraw_pending = false;
|
||||||
|
|
||||||
|
debug.draw_finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = ManuallyDrop::into_inner(user_interfaces);
|
let _ = ManuallyDrop::into_inner(user_interfaces);
|
||||||
|
|
@ -901,16 +874,12 @@ fn run_command<A, C, E>(
|
||||||
.expect("Send control action");
|
.expect("Send control action");
|
||||||
}
|
}
|
||||||
window::Action::Close(id) => {
|
window::Action::Close(id) => {
|
||||||
use winit::event_loop::ControlFlow;
|
|
||||||
|
|
||||||
let _ = window_manager.remove(id);
|
let _ = window_manager.remove(id);
|
||||||
let _ = ui_caches.remove(&id);
|
let _ = ui_caches.remove(&id);
|
||||||
|
|
||||||
if window_manager.is_empty() {
|
if window_manager.is_empty() {
|
||||||
control_sender
|
control_sender
|
||||||
.start_send(Control::ChangeFlow(
|
.start_send(Control::Exit)
|
||||||
ControlFlow::ExitWithCode(0),
|
|
||||||
))
|
|
||||||
.expect("Send control action");
|
.expect("Send control action");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -921,10 +890,12 @@ fn run_command<A, C, E>(
|
||||||
}
|
}
|
||||||
window::Action::Resize(id, size) => {
|
window::Action::Resize(id, size) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_inner_size(winit::dpi::LogicalSize {
|
let _ = window.raw.request_inner_size(
|
||||||
width: size.width,
|
winit::dpi::LogicalSize {
|
||||||
height: size.height,
|
width: size.width,
|
||||||
});
|
height: size.height,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::FetchSize(id, callback) => {
|
window::Action::FetchSize(id, callback) => {
|
||||||
|
|
@ -1153,60 +1124,20 @@ where
|
||||||
/// Returns true if the provided event should cause an [`Application`] to
|
/// Returns true if the provided event should cause an [`Application`] to
|
||||||
/// exit.
|
/// exit.
|
||||||
pub fn user_force_quit(
|
pub fn user_force_quit(
|
||||||
event: &winit::event::WindowEvent<'_>,
|
event: &winit::event::WindowEvent,
|
||||||
_modifiers: winit::event::ModifiersState,
|
_modifiers: winit::keyboard::ModifiersState,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match event {
|
match event {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
winit::event::WindowEvent::KeyboardInput {
|
winit::event::WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyEvent {
|
||||||
virtual_keycode: Some(winit::event::VirtualKeyCode::Q),
|
logical_key: winit::keyboard::Key::Character(c),
|
||||||
state: winit::event::ElementState::Pressed,
|
state: winit::event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} if _modifiers.logo() => true,
|
} if c == "q" && _modifiers.super_key() => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod platform {
|
|
||||||
pub fn run<T, F>(
|
|
||||||
mut event_loop: winit::event_loop::EventLoop<T>,
|
|
||||||
event_handler: F,
|
|
||||||
) -> Result<(), super::Error>
|
|
||||||
where
|
|
||||||
F: 'static
|
|
||||||
+ FnMut(
|
|
||||||
winit::event::Event<'_, T>,
|
|
||||||
&winit::event_loop::EventLoopWindowTarget<T>,
|
|
||||||
&mut winit::event_loop::ControlFlow,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
use winit::platform::run_return::EventLoopExtRunReturn;
|
|
||||||
|
|
||||||
let _ = event_loop.run_return(event_handler);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
mod platform {
|
|
||||||
pub fn run<T, F>(
|
|
||||||
event_loop: winit::event_loop::EventLoop<T>,
|
|
||||||
event_handler: F,
|
|
||||||
) -> !
|
|
||||||
where
|
|
||||||
F: 'static
|
|
||||||
+ FnMut(
|
|
||||||
winit::event::Event<'_, T>,
|
|
||||||
&winit::event_loop::EventLoopWindowTarget<T>,
|
|
||||||
&mut winit::event_loop::ControlFlow,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
event_loop.run(event_handler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ where
|
||||||
viewport: Viewport,
|
viewport: Viewport,
|
||||||
viewport_version: u64,
|
viewport_version: u64,
|
||||||
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||||
modifiers: winit::event::ModifiersState,
|
modifiers: winit::keyboard::ModifiersState,
|
||||||
theme: <A::Renderer as core::Renderer>::Theme,
|
theme: <A::Renderer as core::Renderer>::Theme,
|
||||||
appearance: application::Appearance,
|
appearance: application::Appearance,
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,7 @@ where
|
||||||
viewport,
|
viewport,
|
||||||
viewport_version: 0,
|
viewport_version: 0,
|
||||||
cursor_position: None,
|
cursor_position: None,
|
||||||
modifiers: winit::event::ModifiersState::default(),
|
modifiers: winit::keyboard::ModifiersState::default(),
|
||||||
theme,
|
theme,
|
||||||
appearance,
|
appearance,
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +119,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current keyboard modifiers of the [`State`].
|
/// Returns the current keyboard modifiers of the [`State`].
|
||||||
pub fn modifiers(&self) -> winit::event::ModifiersState {
|
pub fn modifiers(&self) -> winit::keyboard::ModifiersState {
|
||||||
self.modifiers
|
self.modifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@ where
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
window: &Window,
|
window: &Window,
|
||||||
event: &WindowEvent<'_>,
|
event: &WindowEvent,
|
||||||
_debug: &mut crate::runtime::Debug,
|
_debug: &mut crate::runtime::Debug,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
|
|
@ -158,10 +158,9 @@ where
|
||||||
}
|
}
|
||||||
WindowEvent::ScaleFactorChanged {
|
WindowEvent::ScaleFactorChanged {
|
||||||
scale_factor: new_scale_factor,
|
scale_factor: new_scale_factor,
|
||||||
new_inner_size,
|
..
|
||||||
} => {
|
} => {
|
||||||
let size =
|
let size = self.viewport.physical_size();
|
||||||
Size::new(new_inner_size.width, new_inner_size.height);
|
|
||||||
|
|
||||||
self.viewport = Viewport::with_physical_size(
|
self.viewport = Viewport::with_physical_size(
|
||||||
size,
|
size,
|
||||||
|
|
@ -180,13 +179,16 @@ where
|
||||||
self.cursor_position = None;
|
self.cursor_position = None;
|
||||||
}
|
}
|
||||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||||
self.modifiers = *new_modifiers;
|
self.modifiers = new_modifiers.state();
|
||||||
}
|
}
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
winit::event::KeyboardInput {
|
winit::event::KeyEvent {
|
||||||
virtual_keycode: Some(winit::event::VirtualKeyCode::F12),
|
logical_key:
|
||||||
|
winit::keyboard::Key::Named(
|
||||||
|
winit::keyboard::NamedKey::F12,
|
||||||
|
),
|
||||||
state: winit::event::ElementState::Pressed,
|
state: winit::event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue