Merge pull request #319 from yodaldevoid/winit_22

Add support for winit 0.22
This commit is contained in:
Joonas Javanainen 2020-05-18 23:01:38 +03:00 committed by GitHub
commit f579e063ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 82 additions and 29 deletions

View File

@ -56,6 +56,11 @@ jobs:
with:
command: check
args: --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-20
- name: Run cargo check (imgui-winit-support with winit-22)
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-22
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
@ -164,3 +169,8 @@ jobs:
with:
command: test
args: --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-20
- name: Run cargo test (imgui-winit-support with winit-22)
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-22

View File

@ -16,7 +16,7 @@ exclude = [
[dependencies]
bitflags = "1.0"
glium = { version = "0.26", default-features = false, optional = true }
glium = { version = "0.27", default-features = false, optional = true }
gfx = { version = "0.18", optional = true }
imgui-sys = { version = "0.4.0-pre", path = "imgui-sys" }
lazy_static = "1.1"

View File

@ -339,13 +339,13 @@ dependencies = [
[[package]]
name = "glium"
version = "0.26.0"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.45 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -354,7 +354,7 @@ dependencies = [
[[package]]
name = "glutin"
version = "0.23.0"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -375,7 +375,7 @@ dependencies = [
"parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -448,7 +448,7 @@ name = "imgui"
version = "0.4.0-pre"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui-sys 0.4.0-pre",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -459,7 +459,7 @@ name = "imgui-examples"
version = "0.0.0"
dependencies = [
"clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.4.0-pre",
"imgui-glium-renderer 0.4.0-pre",
@ -470,7 +470,7 @@ dependencies = [
name = "imgui-glium-renderer"
version = "0.4.0-pre"
dependencies = [
"glium 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)",
"imgui 0.4.0-pre",
]
@ -486,7 +486,7 @@ name = "imgui-winit-support"
version = "0.4.0-pre"
dependencies = [
"imgui 0.4.0-pre",
"winit 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winit 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1102,7 +1102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winit"
version = "0.21.0"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1219,8 +1219,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af"
"checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a"
"checksum gl_generator 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d"
"checksum glium 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a46e88b2c64cfa63d54ed54dc2a0d25136470eb1721e10be49d857ab583f8663"
"checksum glutin 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf22d4e90c55d9be9f2ad52410e7a2c0d7e9c99d93a13df73a672e7ef4e8c7f7"
"checksum glium 0.27.0 (registry+https://github.com/rust-lang/crates.io-index)" = "030bb23a12fac7e589b002c5e131e89348df88f91b56e3f3dbc4249527eeebf9"
"checksum glutin 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)" = "611023dea5047f3e9047aecb9e361852dcfd0881129daf5d110106ca2b14f3f3"
"checksum glutin_egl_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772edef3b28b8ad41e4ea202748e65eefe8e5ffd1f4535f1219793dbb20b3d4c"
"checksum glutin_emscripten_sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80de4146df76e8a6c32b03007bc764ff3249dcaeb4f675d68a06caf1bac363f1"
"checksum glutin_gles2_sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07e853d96bebcb8e53e445225c3009758c6f5960d44f2543245f6f07b567dae0"
@ -1303,7 +1303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum winit 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "65a5c1a5ef76ac31cc97ad29489acdbed2178f3fc12ca00ee6cb11d60adb5a3a"
"checksum winit 0.22.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fc53342d3d1a3d57f3949e0692d93d5a8adb7814d8683cef4a09c2b550e94246"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum x11-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "89bd49c06c9eb5d98e6ba6536cf64ac9f7ee3a009b2f53996d405b3944f6bcea"
"checksum x11-dl 2.18.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8"

View File

@ -11,7 +11,7 @@ publish = false
[dev-dependencies]
clipboard = "0.5"
glium = { version = "0.26", default-features = true }
glium = { version = "0.27", default-features = true }
image = "0.23"
imgui = { path = "../" }
imgui-glium-renderer = { path = "../imgui-glium-renderer" }

View File

@ -10,5 +10,5 @@ license = "MIT/Apache-2.0"
categories = ["gui", "rendering"]
[dependencies]
glium = { version = "0.26", default-features = false }
glium = { version = "0.27", default-features = false }
imgui = { version = "0.4.0-pre", path = "../", features = ["glium"] }

View File

@ -13,6 +13,7 @@ categories = ["gui"]
imgui = { version = "0.4.0-pre", path = "../" }
winit-19 = { version = ">= 0.16, <= 0.19", package = "winit", optional = true }
winit-20 = { version = ">= 0.20, <= 0.21", package = "winit", optional = true }
winit-22 = { version = "0.22", package = "winit", optional = true }
[features]
default = ["winit-20"]
default = ["winit-22"]

View File

@ -77,6 +77,9 @@ use winit_19 as winit;
#[cfg(feature = "winit-20")]
use winit_20 as winit;
#[cfg(feature = "winit-22")]
use winit_22 as winit;
use imgui::{self, BackendFlags, ConfigFlags, Context, ImString, Io, Key, Ui};
use std::cmp::Ordering;
use winit::dpi::{LogicalPosition, LogicalSize};
@ -87,8 +90,8 @@ use winit::{
TouchPhase, VirtualKeyCode, Window, WindowEvent,
};
#[cfg(feature = "winit-20")]
use winit_20::{
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
use winit::{
error::ExternalError,
event::{
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase,
@ -210,7 +213,7 @@ impl WinitPlatform {
///
/// * framebuffer scale (= DPI factor) is set
/// * display size is set
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
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());
self.hidpi_mode = hidpi_mode;
@ -243,7 +246,7 @@ impl WinitPlatform {
///
/// This utility function is useful if you are using a DPI mode other than default, and want
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
pub fn scale_size_from_winit(
&self,
window: &Window,
@ -277,7 +280,7 @@ impl WinitPlatform {
///
/// This utility function is useful if you are using a DPI mode other than default, and want
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
pub fn scale_pos_from_winit(
&self,
window: &Window,
@ -311,7 +314,7 @@ impl WinitPlatform {
///
/// This utility function is useful if you are using a DPI mode other than default, and want
/// your application to use the same logical coordinates as imgui-rs.
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
pub fn scale_pos_for_winit(
&self,
window: &Window,
@ -408,6 +411,48 @@ impl WinitPlatform {
_ => (),
}
}
/// Handles a winit event.
///
/// This function performs the following actions (depends on the event):
///
/// * window size / dpi factor changes are applied
/// * keyboard state is updated
/// * mouse state is updated
#[cfg(any(feature = "winit-22"))]
pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &Event<T>) {
match *event {
Event::WindowEvent {
window_id,
ref event,
} if window_id == window.id() => {
// We need to track modifiers separately because some system like macOS, will
// not reliably send modifier states during certain events like ScreenCapture.
// Gotta let the people show off their pretty imgui widgets!
if let WindowEvent::ModifiersChanged(modifiers) = event {
io.key_shift = modifiers.shift();
io.key_ctrl = modifiers.ctrl();
io.key_alt = modifiers.alt();
io.key_super = modifiers.logo();
}
self.handle_window_event(io, window, event);
}
// Track key release events outside our window. If we don't do this,
// we might never see the release event if some other window gets focus.
Event::DeviceEvent {
event:
DeviceEvent::Key(KeyboardInput {
state: ElementState::Released,
virtual_keycode: Some(key),
..
}),
..
} => {
io.keys_down[key as usize] = false;
}
_ => (),
}
}
#[cfg(feature = "winit-19")]
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
match *event {
@ -494,7 +539,7 @@ impl WinitPlatform {
_ => (),
}
}
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
match *event {
WindowEvent::Resized(physical_size) => {
@ -618,7 +663,7 @@ impl WinitPlatform {
/// This function performs the following actions:
///
/// * mouse cursor is repositioned (if requested by imgui-rs)
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
pub fn prepare_frame(&self, io: &mut Io, window: &Window) -> Result<(), ExternalError> {
if io.want_set_mouse_pos {
let logical_pos = self.scale_pos_for_winit(
@ -668,7 +713,7 @@ impl WinitPlatform {
/// This function performs the following actions:
///
/// * mouse cursor is changed and/or hidden (if requested by imgui-rs)
#[cfg(feature = "winit-20")]
#[cfg(any(feature = "winit-20", feature = "winit-22"))]
pub fn prepare_render(&self, ui: &Ui, window: &Window) {
let io = ui.io();
if !io

View File

@ -72,6 +72,7 @@ pub(crate) unsafe extern "C" fn set_clipboard_text(user_data: *mut c_void, text:
}
/// # Clipboard
#[allow(clippy::fn_address_comparisons)] // This is allowed because although function addresses wont be unique, we just care if its OURS
impl<'ui> Ui<'ui> {
/// Returns the current clipboard contents as text, or None if the clipboard is empty or cannot
/// be accessed

View File

@ -1,6 +1,5 @@
use std::marker::PhantomData;
use std::ptr;
use sys;
use super::{ImStr, Ui};

View File

@ -1,7 +1,6 @@
use std::marker::PhantomData;
use std::os::raw::c_float;
use std::{f32, mem, ptr};
use sys;
use super::{ImStr, Ui};

View File

@ -1,7 +1,6 @@
use std::marker::PhantomData;
use std::os::raw::c_float;
use std::{f32, mem, ptr};
use sys;
use super::{ImStr, Ui};

View File

@ -1,4 +1,3 @@
use sys;
use sys::{ImDrawList, ImU32};
use super::Ui;