-
Notifications
You must be signed in to change notification settings - Fork 473
/
Copy pathwindow-properties.rs
53 lines (42 loc) · 1.41 KB
/
window-properties.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extern crate sdl2;
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
pub fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
let window = video_subsystem
.window("rust-sdl2 demo: Window", 800, 600)
.resizable()
.build()
.unwrap();
let mut canvas = window.into_canvas().present_vsync().build().unwrap();
let mut tick = 0;
let mut event_pump = sdl_context.event_pump().unwrap();
'running: loop {
for event in event_pump.poll_iter() {
match event {
Event::Quit { .. } |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => break 'running,
_ => {}
}
}
{
// Update the window title.
let window = canvas.window_mut();
let position = window.position();
let size = window.size();
let title = format!("Window - pos({}x{}), size({}x{}): {}",
position.0,
position.1,
size.0,
size.1,
tick);
window.set_title(&title).unwrap();
tick += 1;
}
canvas.set_draw_color(Color::RGB(0, 0, 0));
canvas.clear();
canvas.present();
}
}