Skip to content

Commit

Permalink
Add support & upgrade to winit 0.25 (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
repi committed May 23, 2021
1 parent a78fb45 commit 79f9345
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
2 changes: 1 addition & 1 deletion imgui-gfx-examples/Cargo.toml
Expand Up @@ -22,7 +22,7 @@ glutin = "0.26"
image = "0.23"
imgui = { path = "../imgui" }
imgui-gfx-renderer = { path = "../imgui-gfx-renderer" }
imgui-winit-support = { path = "../imgui-winit-support" }
imgui-winit-support = { path = "../imgui-winit-support", default-features = false, features = ["winit-24"] } # glutin still depends on winit 0.24
old_school_gfx_glutin_ext = "0.26"

[target.'cfg(windows)'.dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion imgui-winit-support/Cargo.toml
Expand Up @@ -16,9 +16,10 @@ winit-20 = { version = ">= 0.20, < 0.22", package = "winit", optional = true }
winit-22 = { version = "0.22", package = "winit", optional = true }
winit-23 = { version = "0.23", package = "winit", optional = true }
winit-24 = { version = "0.24", package = "winit", optional = true }
winit-25 = { version = "0.25", package = "winit", optional = true }

[features]
default = ["winit-24"]
default = ["winit-24"] # TODO: Change to winit-25 when glutin has upgraded to it

# This is phrased as a negative (unlike most features) so that it needs to be
# explicitly disabled (and `default-features = false` won't do it). To avoid
Expand Down
72 changes: 57 additions & 15 deletions imgui-winit-support/src/lib.rs
Expand Up @@ -79,6 +79,7 @@
//!
//! The following versions are supported, controlled by the listed feature.
//!
//! - The `winit-25` feature uses winit versions compatible with `0.25`.
//! - The `winit-24` feature supports winit versions `0.24`. This is
//! on by default, so to use any other version you need to disable this crates
//! default features.
Expand Down Expand Up @@ -132,26 +133,38 @@
//! - Changing the default feature to the new latest `winit` version is *not* a
//! breaking change.

#[cfg(all(not(feature = "winit-24"), feature = "winit-25"))]
use winit_25 as winit;

#[cfg(feature = "winit-24")]
use winit_24 as winit;

#[cfg(all(not(feature = "winit-24"), feature = "winit-23"))]
#[cfg(all(
not(any(feature = "winit-25", feature = "winit-24")),
feature = "winit-23"
))]
use winit_23 as winit;

#[cfg(all(
not(any(feature = "winit-24", feature = "winit-23")),
not(any(feature = "winit-25", feature = "winit-24", feature = "winit-23")),
feature = "winit-22",
))]
use winit_22 as winit;

#[cfg(all(
not(any(feature = "winit-24", feature = "winit-23", feature = "winit-22")),
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22"
)),
feature = "winit-20",
))]
use winit_20 as winit;

#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand All @@ -168,6 +181,7 @@ use winit::dpi::{LogicalPosition, LogicalSize};

#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand All @@ -184,7 +198,8 @@ use winit::{
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
use winit::{
error::ExternalError,
Expand All @@ -202,6 +217,7 @@ use winit::{
feature = "winit-22",
feature = "winit-23",
feature = "winit-24",
feature = "winit-25",
)))]
compile_error!("Please enable at least one version of `winit` (see documentation for details).");

Expand All @@ -213,7 +229,8 @@ fn check_multiple_winits() {
if cfg!(any(not(debug_assertions), feature = "no-warn-on-multiple")) {
return;
}
let winits_enabled = cfg!(feature = "winit-24") as usize
let winits_enabled = cfg!(feature = "winit-25") as usize
+ cfg!(feature = "winit-24") as usize
+ cfg!(feature = "winit-23") as usize
+ cfg!(feature = "winit-22") as usize
+ cfg!(feature = "winit-20") as usize
Expand Down Expand Up @@ -241,6 +258,7 @@ fn check_multiple_winits() {
(this likely indicates misconfiguration, see documentation for details)."
);
let feats = [
("winit-25", cfg!(feature = "winit-25"), ""),
("winit-24", cfg!(feature = "winit-24"), " (default)"),
("winit-23", cfg!(feature = "winit-23"), ""),
("winit-22", cfg!(feature = "winit-22"), ""),
Expand Down Expand Up @@ -330,6 +348,7 @@ fn to_winit_cursor(cursor: imgui::MouseCursor) -> MouseCursor {
impl CursorSettings {
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand All @@ -350,7 +369,8 @@ impl CursorSettings {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
fn apply(&self, window: &Window) {
match self.cursor {
Expand Down Expand Up @@ -458,6 +478,7 @@ impl WinitPlatform {
/// * display size is set
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -485,7 +506,8 @@ impl WinitPlatform {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25",
))]
pub fn attach_window(&mut self, io: &mut Io, window: &Window, hidpi_mode: HiDpiMode) {
let (hidpi_mode, hidpi_factor) = hidpi_mode.apply(window.scale_factor());
Expand All @@ -508,6 +530,7 @@ impl WinitPlatform {
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand All @@ -531,7 +554,8 @@ impl WinitPlatform {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
pub fn scale_size_from_winit(
&self,
Expand All @@ -551,6 +575,7 @@ impl WinitPlatform {
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -578,7 +603,8 @@ impl WinitPlatform {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
pub fn scale_pos_from_winit(
&self,
Expand All @@ -598,6 +624,7 @@ impl WinitPlatform {
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -625,7 +652,8 @@ impl WinitPlatform {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
pub fn scale_pos_for_winit(
&self,
Expand All @@ -648,6 +676,7 @@ impl WinitPlatform {
/// * mouse state is updated
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -694,7 +723,12 @@ impl WinitPlatform {
/// * keyboard state is updated
/// * mouse state is updated
#[cfg(all(
not(any(feature = "winit-24", feature = "winit-23", feature = "winit-22")),
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22"
)),
feature = "winit-20",
))]
pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &Event<T>) {
Expand Down Expand Up @@ -741,7 +775,12 @@ impl WinitPlatform {
/// * window size / dpi factor changes are applied
/// * keyboard state is updated
/// * mouse state is updated
#[cfg(any(feature = "winit-22", feature = "winit-23", feature = "winit-24"))]
#[cfg(any(
feature = "winit-22",
feature = "winit-23",
feature = "winit-24",
feature = "winit-25"
))]
pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &Event<T>) {
match *event {
Event::WindowEvent {
Expand Down Expand Up @@ -778,6 +817,7 @@ impl WinitPlatform {
}
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -873,7 +913,7 @@ impl WinitPlatform {
}
}
#[cfg(all(
not(any(feature = "winit-23", feature = "winit-24")),
not(any(feature = "winit-23", feature = "winit-24", feature = "winit-25")),
any(feature = "winit-20", feature = "winit-22")
))]
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
Expand Down Expand Up @@ -978,7 +1018,7 @@ impl WinitPlatform {
}
}

#[cfg(any(feature = "winit-23", feature = "winit-24"))]
#[cfg(any(feature = "winit-23", feature = "winit-24", feature = "winit-25"))]
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
match *event {
WindowEvent::Resized(physical_size) => {
Expand Down Expand Up @@ -1089,6 +1129,7 @@ impl WinitPlatform {
/// * mouse cursor is repositioned (if requested by imgui-rs)
#[cfg(all(
not(any(
feature = "winit-25",
feature = "winit-24",
feature = "winit-23",
feature = "winit-22",
Expand Down Expand Up @@ -1118,7 +1159,8 @@ impl WinitPlatform {
feature = "winit-20",
feature = "winit-22",
feature = "winit-23",
feature = "winit-24"
feature = "winit-24",
feature = "winit-25"
))]
pub fn prepare_frame(&self, io: &mut Io, window: &Window) -> Result<(), ExternalError> {
self.copy_mouse_to_io(&mut io.mouse_down);
Expand Down

0 comments on commit 79f9345

Please sign in to comment.