Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make size/position types generic over pixel type #1277

Merged
merged 12 commits into from Nov 14, 2019
25 changes: 10 additions & 15 deletions examples/multithreaded.rs
Expand Up @@ -5,14 +5,14 @@ fn main() {
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};

use winit::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::{CursorIcon, Fullscreen, WindowBuilder},
};

const WINDOW_COUNT: usize = 3;
const WINDOW_SIZE: PhysicalSize = PhysicalSize::new(600, 400);
const WINDOW_SIZE: PhysicalSize<u32> = PhysicalSize::new(600, 400);

env_logger::init();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -108,30 +108,25 @@ fn main() {
M => window.set_maximized(state),
P => window.set_outer_position({
let mut position = window.outer_position().unwrap();
let sign = if state { 1.0 } else { -1.0 };
position.x += 10.0 * sign;
position.y += 10.0 * sign;
let sign = if state { 1 } else { -1 };
position.x += 10 * sign;
position.y += 10 * sign;
position
}),
Q => window.request_redraw(),
R => window.set_resizable(state),
S => window.set_inner_size(match state {
true => {
PhysicalSize::new(
WINDOW_SIZE.width + 100,
WINDOW_SIZE.height + 100,
)
}
true => PhysicalSize::new(
WINDOW_SIZE.width + 100,
WINDOW_SIZE.height + 100,
),
false => WINDOW_SIZE,
}),
W => {
if let Size::Physical(size) = WINDOW_SIZE.into() {
window
.set_cursor_position(Position::Physical(
PhysicalPosition::new(
size.width as f64 / 2.0,
size.height as f64 / 2.0,
),
PhysicalPosition::new(size.width / 2, size.height / 2),
))
.unwrap()
}
Expand Down