Process winit mouse input and cursor movement
This commit is contained in:
parent
ab34ef45e0
commit
ae585eb9cb
2 changed files with 38 additions and 18 deletions
|
|
@ -10,3 +10,4 @@ repository = "https://github.com/hecrj/iced"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced_native = { version = "0.1.0-alpha", path = "../native" }
|
iced_native = { version = "0.1.0-alpha", path = "../native" }
|
||||||
winit = "0.20.0-alpha3"
|
winit = "0.20.0-alpha3"
|
||||||
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::renderer::Windowed;
|
use crate::{
|
||||||
use crate::{Cache, Column, Element, Length, UserInterface};
|
column, conversion, input::mouse, renderer::Windowed, Cache, Column,
|
||||||
|
Element, Event, Length, UserInterface,
|
||||||
|
};
|
||||||
|
|
||||||
pub trait Application {
|
pub trait Application {
|
||||||
type Renderer: Windowed + iced_native::column::Renderer;
|
type Renderer: Windowed + column::Renderer;
|
||||||
|
|
||||||
type Message;
|
type Message;
|
||||||
|
|
||||||
|
|
@ -15,7 +17,7 @@ pub trait Application {
|
||||||
Self: 'static + Sized,
|
Self: 'static + Sized,
|
||||||
{
|
{
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Event, WindowEvent},
|
event::{self, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
window::WindowBuilder,
|
window::WindowBuilder,
|
||||||
};
|
};
|
||||||
|
|
@ -46,7 +48,7 @@ pub trait Application {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| match event {
|
event_loop.run(move |event, _, control_flow| match event {
|
||||||
Event::EventsCleared => {
|
event::Event::EventsCleared => {
|
||||||
// TODO: We should be able to keep a user interface alive
|
// TODO: We should be able to keep a user interface alive
|
||||||
// between events once we remove state references.
|
// between events once we remove state references.
|
||||||
//
|
//
|
||||||
|
|
@ -70,6 +72,8 @@ pub trait Application {
|
||||||
let temp_cache = user_interface.into_cache();
|
let temp_cache = user_interface.into_cache();
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
|
log::debug!("Updating");
|
||||||
|
|
||||||
self.update(message);
|
self.update(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,21 +90,36 @@ pub trait Application {
|
||||||
|
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::WindowEvent {
|
event::Event::WindowEvent {
|
||||||
event: WindowEvent::RedrawRequested,
|
event: window_event,
|
||||||
..
|
..
|
||||||
} => {
|
} => match window_event {
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
renderer.draw(&mut target, &primitive);
|
renderer.draw(&mut target, &primitive);
|
||||||
|
|
||||||
// TODO: Handle animations!
|
// TODO: Handle animations!
|
||||||
// Maybe we can use `ControlFlow::WaitUntil` for this.
|
// Maybe we can use `ControlFlow::WaitUntil` for this.
|
||||||
}
|
}
|
||||||
Event::WindowEvent {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
event: WindowEvent::CloseRequested,
|
let physical_position =
|
||||||
..
|
position.to_physical(window.hidpi_factor());
|
||||||
} => {
|
|
||||||
|
events.push(Event::Mouse(mouse::Event::CursorMoved {
|
||||||
|
x: physical_position.x as f32,
|
||||||
|
y: physical_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::CloseRequested => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit;
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue