Merge pull request #149 from hecrj/feature/window-resized-event

Window resized event
This commit is contained in:
Héctor Ramón 2020-01-10 05:13:04 +01:00 committed by GitHub
commit 992ca76afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 5 deletions

View File

@ -1,4 +1,7 @@
use crate::input::{keyboard, mouse};
use crate::{
input::{keyboard, mouse},
window,
};
/// A user interface event.
///
@ -13,4 +16,7 @@ pub enum Event {
/// A mouse event
Mouse(mouse::Event),
/// A window event
Window(window::Event),
}

View File

@ -44,6 +44,7 @@ pub mod layout;
pub mod renderer;
pub mod subscription;
pub mod widget;
pub mod window;
mod clipboard;
mod element;

4
native/src/window.rs Normal file
View File

@ -0,0 +1,4 @@
//! Build window-based GUI applications.
mod event;
pub use event::Event;

View File

@ -0,0 +1,12 @@
/// A window-related event.
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Event {
/// A window was resized
Resized {
/// The new width of the window (in units)
width: u32,
/// The new height of the window (in units)
height: u32,
},
}

View File

@ -2,8 +2,8 @@ use crate::{
container, conversion,
input::{keyboard, mouse},
renderer::{Target, Windowed},
subscription, Cache, Clipboard, Command, Container, Debug, Element, Event,
Length, MouseCursor, Settings, Subscription, UserInterface,
subscription, window, Cache, Clipboard, Command, Container, Debug, Element,
Event, Length, MouseCursor, Settings, Subscription, UserInterface,
};
/// An interactive, native cross-platform application.
@ -373,10 +373,13 @@ pub trait Application: Sized {
*control_flow = ControlFlow::Exit;
}
WindowEvent::Resized(new_size) => {
events.push(Event::Window(window::Event::Resized {
width: new_size.width.round() as u32,
height: new_size.height.round() as u32,
}));
size = new_size;
resized = true;
log::debug!("Resized: {:?}", new_size);
}
_ => {}
},