Skip to content

Commit

Permalink
Fill the windows in the examples with a solid color (cherry-pick from…
Browse files Browse the repository at this point in the history
… upstream)

Fixes rust-windowing#776.
  • Loading branch information
notgull authored and strohel committed Aug 27, 2023
1 parent 3f077a1 commit 652ed47
Show file tree
Hide file tree
Showing 28 changed files with 255 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ serde = { version = "1", optional = true, features = ["serde_derive"] }
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
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 @@ -9,6 +9,9 @@ use winit::{
window::WindowBuilder,
};

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

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Mode {
Wait,
Expand Down Expand Up @@ -93,7 +96,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 @@ -7,6 +7,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 @@ -64,6 +67,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 @@ -9,6 +9,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 @@ -59,6 +62,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 @@ -8,6 +8,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 @@ -116,6 +119,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 @@ -7,11 +7,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 @@ -80,6 +83,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 @@ -9,6 +9,9 @@ use winit::{
window::{ImePurpose, WindowBuilder},
};

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

fn main() {
SimpleLogger::new()
.with_level(LevelFilter::Trace)
Expand Down Expand Up @@ -106,6 +109,9 @@ fn main() {
println!("\nIME purpose: {ime_purpose:?}\n");
}
}
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 @@ -9,6 +9,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 @@ -55,6 +58,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 @@ -8,6 +8,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 @@ -44,6 +47,9 @@ fn main() {
}
_ => (),
},
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
};
});
Expand Down
7 changes: 7 additions & 0 deletions examples/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use winit::{
window::{Theme, WindowBuilder},
};

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

fn main() {
SimpleLogger::new().init().unwrap();
let event_loop = EventLoop::new();
Expand Down Expand Up @@ -65,6 +68,10 @@ fn main() {
}
_ => (),
},
Event::RedrawRequested(_) => {
println!("\nredrawing!\n");
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
8 changes: 7 additions & 1 deletion examples/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,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("A fantastic window!")
.build(&event_loop)
.unwrap();
Expand All @@ -36,6 +39,9 @@ fn main() {
event: WindowEvent::CloseRequested,
..
} => control_flow.set_exit(),
Event::RedrawRequested(_) => {
fill::fill_window(&window);
}
_ => (),
}
});
Expand Down
Loading

0 comments on commit 652ed47

Please sign in to comment.