Skip to content

Commit

Permalink
Fill the windows in the examples with a solid color
Browse files Browse the repository at this point in the history
Fixes #776.
  • Loading branch information
notgull authored Jun 19, 2023
1 parent 4748890 commit b2a46d0
Show file tree
Hide file tree
Showing 30 changed files with 264 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ smol_str = "0.2.0"
image = { version = "0.24.0", default-features = false, features = ["png"] }
simple_logger = { version = "2.1.0", default_features = false }

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dev-dependencies]
softbuffer = "0.3.0"

[target.'cfg(target_os = "android")'.dependencies]
# Coordinate the next winit release with android-ndk-rs: https://github.com/rust-windowing/winit/issues/1995
android-activity = "0.4.0"
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ Winit provides the following features, which can be enabled in your `Cargo.toml`

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

`winit` doesn't do drawing, try the examples in [`glutin`] instead.

[`glutin`]: https://github.com/rust-windowing/glutin

#### WebAssembly

To run the web example: `cargo run-wasm --example web`
Expand Down
2 changes: 2 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ skip = [
{ name = "bitflags" }, # the ecosystem is in the process of migrating.
{ name = "nix" }, # differing version - as of 2023-03-02 whis can be solved with `cargo update && cargo update -p calloop --precise 0.10.2`
{ name = "memoffset"}, # due to different nix versions.
{ name = "memmap2" }, # sctk uses a different version until the next update
{ name = "libloading" }, # x11rb uses a different version until the next update
{ name = "syn" }, # https://github.com/rust-mobile/ndk/issues/392 and https://github.com/rustwasm/wasm-bindgen/issues/3390
{ name = "miniz_oxide"}, # https://github.com/rust-lang/flate2-rs/issues/340
{ name = "redox_syscall" }, # https://gitlab.redox-os.org/redox-os/orbclient/-/issues/46
Expand Down
8 changes: 8 additions & 0 deletions examples/child_window.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[cfg(any(x11_platform, macos_platform, windows_platform))]
#[path = "util/fill.rs"]
mod fill;

#[cfg(any(x11_platform, macos_platform, windows_platform))]
fn main() {
use std::collections::HashMap;
Expand Down Expand Up @@ -70,6 +74,10 @@ fn main() {
}
_ => (),
}
} else if let Event::RedrawRequested(wid) = event {
if let Some(window) = windows.get(&wid) {
fill::fill_window(window);
}
}
})
}
Expand Down
7 changes: 6 additions & 1 deletion examples/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use winit::{
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Mode {
Wait,
Expand Down Expand Up @@ -100,7 +103,9 @@ fn main() {
control_flow.set_exit();
}
}
Event::RedrawRequested(_window_id) => {}
Event::RedrawRequested(_window_id) => {
fill::fill_window(&window);
}
Event::RedrawEventsCleared => {
match mode {
Mode::Wait => control_flow.set_wait(),
Expand Down
6 changes: 6 additions & 0 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use winit::{
window::{CursorIcon, WindowBuilder},
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -46,6 +49,9 @@ fn main() {
} => {
control_flow.set_exit();
}
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
4 changes: 4 additions & 0 deletions examples/cursor_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use winit::{
window::{CursorGrabMode, WindowBuilder},
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -67,6 +70,7 @@ fn main() {
},
_ => (),
},
Event::RedrawRequested(_) => fill::fill_window(&window),
_ => (),
}
});
Expand Down
8 changes: 7 additions & 1 deletion examples/custom_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ fn main() {
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

#[derive(Debug, Clone, Copy)]
enum CustomEvent {
Timer,
Expand All @@ -17,7 +20,7 @@ fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoopBuilder::<CustomEvent>::with_user_event().build();

let _window = WindowBuilder::new()
let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
Expand All @@ -44,6 +47,9 @@ fn main() {
event: WindowEvent::CloseRequested,
..
} => control_flow.set_exit(),
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
10 changes: 10 additions & 0 deletions examples/drag_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use winit::{
window::{Window, WindowBuilder, WindowId},
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -58,6 +61,13 @@ fn main() {
}
_ => (),
},
Event::RedrawRequested(wid) => {
if wid == window_1.id() {
fill::fill_window(&window_1);
} else if wid == window_2.id() {
fill::fill_window(&window_2);
}
}
_ => (),
});
}
Expand Down
6 changes: 6 additions & 0 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use winit::window::{Fullscreen, WindowBuilder};
#[cfg(target_os = "macos")]
use winit::platform::macos::WindowExtMacOS;

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -123,6 +126,9 @@ fn main() {
},
_ => (),
},
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => {}
}
});
Expand Down
8 changes: 7 additions & 1 deletion examples/handling_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ use winit::{
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let _window = WindowBuilder::new()
let window = WindowBuilder::new()
.with_title("Your faithful window")
.build(&event_loop)
.unwrap();
Expand Down Expand Up @@ -79,6 +82,9 @@ fn main() {
_ => (),
}
}
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
6 changes: 6 additions & 0 deletions examples/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use winit::{
window::{ImePurpose, WindowBuilder},
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new()
.with_level(LevelFilter::Trace)
Expand Down Expand Up @@ -97,6 +100,9 @@ fn main() {
println!("\nIME purpose: {ime_purpose:?}\n");
}
}
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
8 changes: 7 additions & 1 deletion examples/key_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ fn main() {

#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
fn main() {
#[path = "util/fill.rs"]
mod fill;

simple_logger::SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let _window = WindowBuilder::new()
let window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(400.0, 200.0))
.build(&event_loop)
.unwrap();
Expand Down Expand Up @@ -53,6 +56,9 @@ fn main() {
}
_ => (),
},
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
};
});
Expand Down
6 changes: 6 additions & 0 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use winit::{
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -56,6 +59,9 @@ In other words, the deltas indicate the direction in which to move the content (
},
_ => (),
},
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
8 changes: 8 additions & 0 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use winit::{
window::Window,
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -56,6 +59,11 @@ fn main() {
_ => (),
}
}
Event::RedrawRequested(window_id) => {
if let Some(window) = windows.get(&window_id) {
fill::fill_window(window);
}
}
_ => (),
}
})
Expand Down
4 changes: 4 additions & 0 deletions examples/request_redraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use winit::{
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -34,6 +37,7 @@ fn main() {
},
Event::RedrawRequested(_) => {
println!("\nredrawing!\n");
fill::fill_window(&window);
}
_ => (),
}
Expand Down
26 changes: 18 additions & 8 deletions examples/request_redraw_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[cfg(not(wasm_platform))]
fn main() {
use std::{thread, time};
use std::{sync::Arc, thread, time};

use simple_logger::SimpleLogger;
use winit::{
Expand All @@ -11,17 +11,26 @@ fn main() {
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
let window = {
let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
Arc::new(window)
};

thread::spawn(move || loop {
thread::sleep(time::Duration::from_secs(1));
window.request_redraw();
thread::spawn({
let window = window.clone();
move || loop {
thread::sleep(time::Duration::from_secs(1));
window.request_redraw();
}
});

event_loop.run(move |event, _, control_flow| {
Expand All @@ -36,6 +45,7 @@ fn main() {
} => control_flow.set_exit(),
Event::RedrawRequested(_) => {
println!("\nredrawing!\n");
fill::fill_window(&window);
}
_ => (),
}
Expand Down
6 changes: 6 additions & 0 deletions examples/resizable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use winit::{
window::WindowBuilder,
};

#[path = "util/fill.rs"]
mod fill;

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -45,6 +48,9 @@ fn main() {
}
_ => (),
},
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
};
});
Expand Down
Loading

0 comments on commit b2a46d0

Please sign in to comment.