Skip to content

Commit b2a46d0

Browse files
authored
Fill the windows in the examples with a solid color
Fixes #776.
1 parent 4748890 commit b2a46d0

30 files changed

+264
-19
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ smol_str = "0.2.0"
6363
image = { version = "0.24.0", default-features = false, features = ["png"] }
6464
simple_logger = { version = "2.1.0", default_features = false }
6565

66+
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dev-dependencies]
67+
softbuffer = "0.3.0"
68+
6669
[target.'cfg(target_os = "android")'.dependencies]
6770
# Coordinate the next winit release with android-ndk-rs: https://github.com/rust-windowing/winit/issues/1995
6871
android-activity = "0.4.0"

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ Winit provides the following features, which can be enabled in your `Cargo.toml`
7373

7474
Note that windows don't appear on Wayland until you draw/present to them.
7575

76-
`winit` doesn't do drawing, try the examples in [`glutin`] instead.
77-
78-
[`glutin`]: https://github.com/rust-windowing/glutin
79-
8076
#### WebAssembly
8177

8278
To run the web example: `cargo run-wasm --example web`

deny.toml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ skip = [
3434
{ name = "bitflags" }, # the ecosystem is in the process of migrating.
3535
{ name = "nix" }, # differing version - as of 2023-03-02 whis can be solved with `cargo update && cargo update -p calloop --precise 0.10.2`
3636
{ name = "memoffset"}, # due to different nix versions.
37+
{ name = "memmap2" }, # sctk uses a different version until the next update
38+
{ name = "libloading" }, # x11rb uses a different version until the next update
3739
{ name = "syn" }, # https://github.com/rust-mobile/ndk/issues/392 and https://github.com/rustwasm/wasm-bindgen/issues/3390
3840
{ name = "miniz_oxide"}, # https://github.com/rust-lang/flate2-rs/issues/340
3941
{ name = "redox_syscall" }, # https://gitlab.redox-os.org/redox-os/orbclient/-/issues/46

examples/child_window.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#[cfg(any(x11_platform, macos_platform, windows_platform))]
2+
#[path = "util/fill.rs"]
3+
mod fill;
4+
15
#[cfg(any(x11_platform, macos_platform, windows_platform))]
26
fn main() {
37
use std::collections::HashMap;
@@ -70,6 +74,10 @@ fn main() {
7074
}
7175
_ => (),
7276
}
77+
} else if let Event::RedrawRequested(wid) = event {
78+
if let Some(window) = windows.get(&wid) {
79+
fill::fill_window(window);
80+
}
7381
}
7482
})
7583
}

examples/control_flow.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use winit::{
1414
window::WindowBuilder,
1515
};
1616

17+
#[path = "util/fill.rs"]
18+
mod fill;
19+
1720
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1821
enum Mode {
1922
Wait,
@@ -100,7 +103,9 @@ fn main() {
100103
control_flow.set_exit();
101104
}
102105
}
103-
Event::RedrawRequested(_window_id) => {}
106+
Event::RedrawRequested(_window_id) => {
107+
fill::fill_window(&window);
108+
}
104109
Event::RedrawEventsCleared => {
105110
match mode {
106111
Mode::Wait => control_flow.set_wait(),

examples/cursor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use winit::{
77
window::{CursorIcon, WindowBuilder},
88
};
99

10+
#[path = "util/fill.rs"]
11+
mod fill;
12+
1013
fn main() {
1114
SimpleLogger::new().init().unwrap();
1215
let event_loop = EventLoop::new();
@@ -46,6 +49,9 @@ fn main() {
4649
} => {
4750
control_flow.set_exit();
4851
}
52+
Event::RedrawRequested(_) => {
53+
fill::fill_window(&window);
54+
}
4955
_ => (),
5056
}
5157
});

examples/cursor_grab.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use winit::{
88
window::{CursorGrabMode, WindowBuilder},
99
};
1010

11+
#[path = "util/fill.rs"]
12+
mod fill;
13+
1114
fn main() {
1215
SimpleLogger::new().init().unwrap();
1316
let event_loop = EventLoop::new();
@@ -67,6 +70,7 @@ fn main() {
6770
},
6871
_ => (),
6972
},
73+
Event::RedrawRequested(_) => fill::fill_window(&window),
7074
_ => (),
7175
}
7276
});

examples/custom_events.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fn main() {
99
window::WindowBuilder,
1010
};
1111

12+
#[path = "util/fill.rs"]
13+
mod fill;
14+
1215
#[derive(Debug, Clone, Copy)]
1316
enum CustomEvent {
1417
Timer,
@@ -17,7 +20,7 @@ fn main() {
1720
SimpleLogger::new().init().unwrap();
1821
let event_loop = EventLoopBuilder::<CustomEvent>::with_user_event().build();
1922

20-
let _window = WindowBuilder::new()
23+
let window = WindowBuilder::new()
2124
.with_title("A fantastic window!")
2225
.build(&event_loop)
2326
.unwrap();
@@ -44,6 +47,9 @@ fn main() {
4447
event: WindowEvent::CloseRequested,
4548
..
4649
} => control_flow.set_exit(),
50+
Event::RedrawRequested(_) => {
51+
fill::fill_window(&window);
52+
}
4753
_ => (),
4854
}
4955
});

examples/drag_window.rs

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use winit::{
88
window::{Window, WindowBuilder, WindowId},
99
};
1010

11+
#[path = "util/fill.rs"]
12+
mod fill;
13+
1114
fn main() {
1215
SimpleLogger::new().init().unwrap();
1316
let event_loop = EventLoop::new();
@@ -58,6 +61,13 @@ fn main() {
5861
}
5962
_ => (),
6063
},
64+
Event::RedrawRequested(wid) => {
65+
if wid == window_1.id() {
66+
fill::fill_window(&window_1);
67+
} else if wid == window_2.id() {
68+
fill::fill_window(&window_2);
69+
}
70+
}
6171
_ => (),
6272
});
6373
}

examples/fullscreen.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use winit::window::{Fullscreen, WindowBuilder};
99
#[cfg(target_os = "macos")]
1010
use winit::platform::macos::WindowExtMacOS;
1111

12+
#[path = "util/fill.rs"]
13+
mod fill;
14+
1215
fn main() {
1316
SimpleLogger::new().init().unwrap();
1417
let event_loop = EventLoop::new();
@@ -123,6 +126,9 @@ fn main() {
123126
},
124127
_ => (),
125128
},
129+
Event::RedrawRequested(_) => {
130+
fill::fill_window(&window);
131+
}
126132
_ => {}
127133
}
128134
});

examples/handling_close.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ use winit::{
88
window::WindowBuilder,
99
};
1010

11+
#[path = "util/fill.rs"]
12+
mod fill;
13+
1114
fn main() {
1215
SimpleLogger::new().init().unwrap();
1316
let event_loop = EventLoop::new();
1417

15-
let _window = WindowBuilder::new()
18+
let window = WindowBuilder::new()
1619
.with_title("Your faithful window")
1720
.build(&event_loop)
1821
.unwrap();
@@ -79,6 +82,9 @@ fn main() {
7982
_ => (),
8083
}
8184
}
85+
Event::RedrawRequested(_) => {
86+
fill::fill_window(&window);
87+
}
8288
_ => (),
8389
}
8490
});

examples/ime.rs

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use winit::{
1010
window::{ImePurpose, WindowBuilder},
1111
};
1212

13+
#[path = "util/fill.rs"]
14+
mod fill;
15+
1316
fn main() {
1417
SimpleLogger::new()
1518
.with_level(LevelFilter::Trace)
@@ -97,6 +100,9 @@ fn main() {
97100
println!("\nIME purpose: {ime_purpose:?}\n");
98101
}
99102
}
103+
Event::RedrawRequested(_) => {
104+
fill::fill_window(&window);
105+
}
100106
_ => (),
101107
}
102108
});

examples/key_binding.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ fn main() {
1818

1919
#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
2020
fn main() {
21+
#[path = "util/fill.rs"]
22+
mod fill;
23+
2124
simple_logger::SimpleLogger::new().init().unwrap();
2225
let event_loop = EventLoop::new();
2326

24-
let _window = WindowBuilder::new()
27+
let window = WindowBuilder::new()
2528
.with_inner_size(LogicalSize::new(400.0, 200.0))
2629
.build(&event_loop)
2730
.unwrap();
@@ -53,6 +56,9 @@ fn main() {
5356
}
5457
_ => (),
5558
},
59+
Event::RedrawRequested(_) => {
60+
fill::fill_window(&window);
61+
}
5662
_ => (),
5763
};
5864
});

examples/mouse_wheel.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use winit::{
77
window::WindowBuilder,
88
};
99

10+
#[path = "util/fill.rs"]
11+
mod fill;
12+
1013
fn main() {
1114
SimpleLogger::new().init().unwrap();
1215
let event_loop = EventLoop::new();
@@ -56,6 +59,9 @@ In other words, the deltas indicate the direction in which to move the content (
5659
},
5760
_ => (),
5861
},
62+
Event::RedrawRequested(_) => {
63+
fill::fill_window(&window);
64+
}
5965
_ => (),
6066
}
6167
});

examples/multiwindow.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use winit::{
1010
window::Window,
1111
};
1212

13+
#[path = "util/fill.rs"]
14+
mod fill;
15+
1316
fn main() {
1417
SimpleLogger::new().init().unwrap();
1518
let event_loop = EventLoop::new();
@@ -56,6 +59,11 @@ fn main() {
5659
_ => (),
5760
}
5861
}
62+
Event::RedrawRequested(window_id) => {
63+
if let Some(window) = windows.get(&window_id) {
64+
fill::fill_window(window);
65+
}
66+
}
5967
_ => (),
6068
}
6169
})

examples/request_redraw.rs

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use winit::{
77
window::WindowBuilder,
88
};
99

10+
#[path = "util/fill.rs"]
11+
mod fill;
12+
1013
fn main() {
1114
SimpleLogger::new().init().unwrap();
1215
let event_loop = EventLoop::new();
@@ -34,6 +37,7 @@ fn main() {
3437
},
3538
Event::RedrawRequested(_) => {
3639
println!("\nredrawing!\n");
40+
fill::fill_window(&window);
3741
}
3842
_ => (),
3943
}

examples/request_redraw_threaded.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#[cfg(not(wasm_platform))]
44
fn main() {
5-
use std::{thread, time};
5+
use std::{sync::Arc, thread, time};
66

77
use simple_logger::SimpleLogger;
88
use winit::{
@@ -11,17 +11,26 @@ fn main() {
1111
window::WindowBuilder,
1212
};
1313

14+
#[path = "util/fill.rs"]
15+
mod fill;
16+
1417
SimpleLogger::new().init().unwrap();
1518
let event_loop = EventLoop::new();
1619

17-
let window = WindowBuilder::new()
18-
.with_title("A fantastic window!")
19-
.build(&event_loop)
20-
.unwrap();
20+
let window = {
21+
let window = WindowBuilder::new()
22+
.with_title("A fantastic window!")
23+
.build(&event_loop)
24+
.unwrap();
25+
Arc::new(window)
26+
};
2127

22-
thread::spawn(move || loop {
23-
thread::sleep(time::Duration::from_secs(1));
24-
window.request_redraw();
28+
thread::spawn({
29+
let window = window.clone();
30+
move || loop {
31+
thread::sleep(time::Duration::from_secs(1));
32+
window.request_redraw();
33+
}
2534
});
2635

2736
event_loop.run(move |event, _, control_flow| {
@@ -36,6 +45,7 @@ fn main() {
3645
} => control_flow.set_exit(),
3746
Event::RedrawRequested(_) => {
3847
println!("\nredrawing!\n");
48+
fill::fill_window(&window);
3949
}
4050
_ => (),
4151
}

examples/resizable.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use winit::{
99
window::WindowBuilder,
1010
};
1111

12+
#[path = "util/fill.rs"]
13+
mod fill;
14+
1215
fn main() {
1316
SimpleLogger::new().init().unwrap();
1417
let event_loop = EventLoop::new();
@@ -45,6 +48,9 @@ fn main() {
4548
}
4649
_ => (),
4750
},
51+
Event::RedrawRequested(_) => {
52+
fill::fill_window(&window);
53+
}
4854
_ => (),
4955
};
5056
});

0 commit comments

Comments
 (0)