summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-10 05:52:35 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-10 05:52:35 +0200
commitae585eb9cb043f2f6565bbe9c80c50cb7ded8bac (patch)
treead814258abbc3c841780203006d2a59b995269b1 /winit
parentab34ef45e0d9a17d6aee3eadf52b753fce73e3b6 (diff)
downloadiced-ae585eb9cb043f2f6565bbe9c80c50cb7ded8bac.tar.gz
iced-ae585eb9cb043f2f6565bbe9c80c50cb7ded8bac.tar.bz2
iced-ae585eb9cb043f2f6565bbe9c80c50cb7ded8bac.zip
Process `winit` mouse input and cursor movement
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml1
-rw-r--r--winit/src/application.rs55
2 files changed, 38 insertions, 18 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index d7f61503..15158e0e 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -10,3 +10,4 @@ repository = "https://github.com/hecrj/iced"
[dependencies]
iced_native = { version = "0.1.0-alpha", path = "../native" }
winit = "0.20.0-alpha3"
+log = "0.4"
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 9e23cd40..d09aad7a 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -1,8 +1,10 @@
-use crate::renderer::Windowed;
-use crate::{Cache, Column, Element, Length, UserInterface};
+use crate::{
+ column, conversion, input::mouse, renderer::Windowed, Cache, Column,
+ Element, Event, Length, UserInterface,
+};
pub trait Application {
- type Renderer: Windowed + iced_native::column::Renderer;
+ type Renderer: Windowed + column::Renderer;
type Message;
@@ -15,7 +17,7 @@ pub trait Application {
Self: 'static + Sized,
{
use winit::{
- event::{Event, WindowEvent},
+ event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
@@ -46,7 +48,7 @@ pub trait Application {
window.request_redraw();
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
// between events once we remove state references.
//
@@ -70,6 +72,8 @@ pub trait Application {
let temp_cache = user_interface.into_cache();
for message in messages {
+ log::debug!("Updating");
+
self.update(message);
}
@@ -86,21 +90,36 @@ pub trait Application {
window.request_redraw();
}
- Event::WindowEvent {
- event: WindowEvent::RedrawRequested,
+ event::Event::WindowEvent {
+ event: window_event,
..
- } => {
- renderer.draw(&mut target, &primitive);
+ } => match window_event {
+ WindowEvent::RedrawRequested => {
+ renderer.draw(&mut target, &primitive);
- // TODO: Handle animations!
- // Maybe we can use `ControlFlow::WaitUntil` for this.
- }
- Event::WindowEvent {
- event: WindowEvent::CloseRequested,
- ..
- } => {
- *control_flow = ControlFlow::Exit;
- }
+ // TODO: Handle animations!
+ // Maybe we can use `ControlFlow::WaitUntil` for this.
+ }
+ WindowEvent::CursorMoved { position, .. } => {
+ 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::Wait;
}