Skip to content

Commit 5f209bd

Browse files
Legend-Mastermaroideramrbashir
authored
refactor(windows): re-land remove window subclassing (#1231)
ref: rust-windowing/winit#1933 Co-authored-by: Markus Røyset <maroider@protonmail.com> Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com>
1 parent a89d75a commit 5f209bd

7 files changed

Lines changed: 570 additions & 560 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tao": patch
3+
---
4+
5+
Fixed `with_background_color` doesn't work on initial load on Windows
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tao": minor
3+
---
4+
5+
Removed window subclassing on Windows

examples/background_color.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014-2021 The winit contributors
2+
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
use dpi::LogicalSize;
6+
use tao::{
7+
event::{ElementState, Event, KeyEvent, WindowEvent},
8+
event_loop::{ControlFlow, EventLoop},
9+
keyboard::KeyCode,
10+
window::WindowBuilder,
11+
};
12+
13+
fn main() {
14+
let event_loop = EventLoop::new();
15+
16+
let mut background_color = (100, 100, 100, 255);
17+
18+
let window = WindowBuilder::new()
19+
.with_title("Hit space to change background color!")
20+
.with_inner_size(LogicalSize::new(400.0, 300.0))
21+
.with_background_color(background_color)
22+
.build(&event_loop)
23+
.unwrap();
24+
25+
event_loop.run(move |event, _, control_flow| {
26+
*control_flow = ControlFlow::Wait;
27+
28+
match event {
29+
Event::WindowEvent { event, .. } => match event {
30+
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
31+
WindowEvent::KeyboardInput {
32+
event:
33+
KeyEvent {
34+
physical_key: KeyCode::Space,
35+
state: ElementState::Released,
36+
..
37+
},
38+
..
39+
} => {
40+
background_color.1 = background_color.1.wrapping_add(20);
41+
println!("Setting background color to: {background_color:?}");
42+
window.set_background_color(Some(background_color));
43+
}
44+
_ => (),
45+
},
46+
_ => (),
47+
}
48+
});
49+
}

0 commit comments

Comments
 (0)