mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 05:28:35 +00:00
sudo rm -rf old-winit
Somewhat experimental removal of old winit versions, to reduce maintenance burden Significantly reduces (around half) the length of winit-support, should reduce amount of work done in CI
This commit is contained in:
parent
69f43e3025
commit
c032408329
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@ -67,15 +67,8 @@ jobs:
|
||||
- name: freetype and docking
|
||||
run: cargo clippy --workspace --all-targets --features freetype,docking
|
||||
|
||||
# supported winit versions (with otherwise default features)
|
||||
- run: cargo doc
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-19 --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-20 --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-22 --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-23/default --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-24/default --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-25/default --all-targets
|
||||
- run: cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-26/default --all-targets
|
||||
- name: allf eatures
|
||||
run: cargo clippy --workspace --all-targets --all-features
|
||||
|
||||
test:
|
||||
name: Run tests
|
||||
@ -147,20 +140,17 @@ jobs:
|
||||
if: matrix.os != 'windows-latest'
|
||||
run: cargo test --workspace --all-targets --features freetype
|
||||
|
||||
- name: freetype and docking
|
||||
- name: all features
|
||||
if: matrix.os != 'windows-latest'
|
||||
run: cargo test --workspace --all-targets --features freetype,docking
|
||||
run: cargo test --workspace --all-targets --all-features
|
||||
|
||||
- name: doc tests
|
||||
run: cargo test --workspace --doc
|
||||
|
||||
- run: cargo test --workspace --doc
|
||||
# run to check for lint problems
|
||||
- run: cargo doc
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-19
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-20
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-22
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-23/default
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-24/default
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-25/default
|
||||
- run: cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features winit-26/default
|
||||
- name: build documentation
|
||||
run: cargo doc
|
||||
|
||||
# Run unreasonably slow tests under release, but only the crates that have
|
||||
# them, and don't bother doing this on most platforms.
|
||||
- run: cargo test -p imgui --release -- --ignored
|
||||
|
||||
@ -11,20 +11,4 @@ categories = ["gui"]
|
||||
|
||||
[dependencies]
|
||||
imgui = { version = "0.8.1-alpha.0", path = "../imgui" }
|
||||
winit-19 = { version = ">= 0.16, < 0.20", package = "winit", optional = true }
|
||||
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", default-features = false, optional = true }
|
||||
winit-24 = { version = "0.24", package = "winit", default-features = false, optional = true }
|
||||
winit-25 = { version = "0.25", package = "winit", default-features = false, optional = true }
|
||||
winit-26 = { version = "0.26", package = "winit", default-features = false, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["winit-26/default"]
|
||||
test = ["winit-23/default", "winit-24/default", "winit-25/default", "winit-26/default"]
|
||||
|
||||
# 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
|
||||
# problems from this we don't expose this in the public API in any way, keeping
|
||||
# things additive.
|
||||
no-warn-on-multiple = []
|
||||
winit = { version = "0.26.0", default-features = false }
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
# Updating Winit
|
||||
|
||||
Updating the default version of Winit is very annoying and error prone. We should make some automated way to do it so we don't have any issues in the future, but here is what needs to be done:
|
||||
|
||||
1. Make sure that glutin is on the new version of Winit that you want to use. It's easier if our default winit version is on that new default.
|
||||
2. Update the default in the Cargo.toml by simply changing the default guard.
|
||||
3. At the top of lib.rs, edit the CFG guards which handle `use winit_x as winit;` such that the new default only relies on a positive feature guard (just copy the form used for the old default). If you don't do this, you'll get some particularly strange errors about two crates being used, since somehow the dependency resolver will pick a winit that the user didn't choose (and presumably won't use if it actually made it to compilation).
|
||||
4. Profit??
|
||||
@ -13,38 +13,15 @@
|
||||
//! 4. Call frame preparation callback (every frame)
|
||||
//! 5. Call render preparation callback (every frame)
|
||||
//!
|
||||
//! ## Complete example for winit 0.20+ (without a renderer)
|
||||
//! ## Complete example (without a renderer)
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "winit-19")]
|
||||
//! # fn main() {}
|
||||
//! #
|
||||
//! # #[cfg(not(feature = "winit-19"))]
|
||||
//! # fn main() {
|
||||
//! # #[cfg(feature = "winit-20")]
|
||||
//! # use winit_20 as winit;
|
||||
//! #
|
||||
//! # #[cfg(feature = "winit-22")]
|
||||
//! # use winit_22 as winit;
|
||||
//! #
|
||||
//! # #[cfg(feature = "winit-23")]
|
||||
//! # use winit_23 as winit;
|
||||
//! #
|
||||
//! # #[cfg(feature = "winit-24")]
|
||||
//! # use winit_24 as winit;
|
||||
//! #
|
||||
//! # #[cfg(feature = "winit-25")]
|
||||
//! # use winit_25 as winit;
|
||||
//! #
|
||||
//! # #[cfg(feature = "winit-26")]
|
||||
//! # use winit_26 as winit;
|
||||
//! #
|
||||
//! use imgui::Context;
|
||||
//! use imgui_winit_support::{HiDpiMode, WinitPlatform};
|
||||
//! use std::time::Instant;
|
||||
//! use winit::event::{Event, WindowEvent};
|
||||
//! use winit::event_loop::{ControlFlow, EventLoop};
|
||||
//! use winit::window::{Window};
|
||||
//! use winit::window::Window;
|
||||
//!
|
||||
//! let mut event_loop = EventLoop::new();
|
||||
//! let mut window = Window::new(&event_loop).unwrap();
|
||||
@ -94,154 +71,13 @@
|
||||
//! }
|
||||
//! }
|
||||
//! })
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! ## `winit` versions and features.
|
||||
//!
|
||||
//! This crate has several features which control the version of winit which is
|
||||
//! used.
|
||||
//!
|
||||
//! The following versions are supported, controlled by the listed feature.
|
||||
//!
|
||||
//! - The `winit-26` feature uses winit versions compatible with `0.26`. This is
|
||||
//! on by default, so to use any other version you need to disable this crates
|
||||
//! default features.
|
||||
//! - The `winit-25` feature supports winit versions `0.25`.
|
||||
//! - The `winit-24` feature supports winit versions `0.24`.
|
||||
//! - The `winit-23` feature uses winit versions compatible with `0.23`.
|
||||
//! - The `winit-22` feature uses winit versions compatible with `0.22`.
|
||||
//! - The `winit-20` feature should support winit either `0.20` or winit `0.21`.
|
||||
//! - The `winit-19` feature should support winits older than `0.19` (possibly
|
||||
//! back to winit 0.16.*, but this isn't regularly tested and may not work).
|
||||
//!
|
||||
//! If multiple `winit-*` features are enabled, and it is a debug build (as
|
||||
//! determined by `debug_assertions`), we will log a warning to stderr during
|
||||
//! init. This can be disabled by either turning on the `no-warn-on-multiple`
|
||||
//! feature, fixing the configuration, or disabling `debug_assertions`.
|
||||
//!
|
||||
//! Conversely, if no `winit-*` features are enabled, we will fail to compile.
|
||||
//! This is not an issue generally, as by default we turn on `winit-26`.
|
||||
//!
|
||||
//! All of this is in attempt to preserve the additive nature of features (while
|
||||
//! still helping users notice project configuration issues), however it's done
|
||||
//! fairly weakly as our this crate's API isn't 100% identical across winit
|
||||
//! versions.
|
||||
//!
|
||||
//! ### Using an older `winit` version
|
||||
//!
|
||||
//! To use an older version, you must configure `default-features = false` in
|
||||
//! your `Cargo.toml`:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies.imgui-winit-support]
|
||||
//! version = "0.6"
|
||||
//! features = ["winit-$YOUR_VERSION_HERE"]
|
||||
//! default-features = false
|
||||
//! ```
|
||||
//!
|
||||
//! ### Old `winit` compatibility
|
||||
//!
|
||||
//! No guarantee is made on how long this crate will support legacy versions of
|
||||
//! `winit`, but we'll try to follow these rules:
|
||||
//!
|
||||
//! - Versions which are still in widespread use in the ecosystem will be
|
||||
//! supported while that is true (for example, 0.19 at the time of writing is
|
||||
//! quite old, but used by the most recent version of several popular crates).
|
||||
//!
|
||||
//! - Versions which are not a significant maintenance burden will be supported
|
||||
//! (for example, supporting versions older than winit 0.19 given that we
|
||||
//! support 0.19).
|
||||
//!
|
||||
//! - Explicitly removing support for a feature-indicated version will be
|
||||
//! considered a breaking change.
|
||||
//!
|
||||
//! - Changing the default feature to the new latest `winit` version is *not* a
|
||||
//! breaking change.
|
||||
|
||||
#[cfg(feature = "winit-26")]
|
||||
use winit_26 as winit;
|
||||
|
||||
#[cfg(all(not(any(feature = "winit-26")), feature = "winit-25"))]
|
||||
use winit_25 as winit;
|
||||
|
||||
#[cfg(all(
|
||||
not(any(feature = "winit-26", feature = "winit-25")),
|
||||
feature = "winit-24"
|
||||
))]
|
||||
use winit_24 as winit;
|
||||
|
||||
#[cfg(all(
|
||||
not(any(feature = "winit-26", feature = "winit-25", feature = "winit-24")),
|
||||
feature = "winit-23"
|
||||
))]
|
||||
use winit_23 as winit;
|
||||
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23"
|
||||
)),
|
||||
feature = "winit-22",
|
||||
))]
|
||||
use winit_22 as winit;
|
||||
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
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-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
use winit_19 as winit;
|
||||
|
||||
use imgui::{self, BackendFlags, ConfigFlags, Context, Io, Key, Ui};
|
||||
use std::cell::Cell;
|
||||
use std::cmp::Ordering;
|
||||
use winit::dpi::{LogicalPosition, LogicalSize};
|
||||
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
use winit::{
|
||||
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseCursor, MouseScrollDelta,
|
||||
TouchPhase, VirtualKeyCode, Window, WindowEvent,
|
||||
};
|
||||
|
||||
#[cfg(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
))]
|
||||
use winit::{
|
||||
error::ExternalError,
|
||||
event::{
|
||||
@ -251,83 +87,6 @@ use winit::{
|
||||
window::{CursorIcon as MouseCursor, Window},
|
||||
};
|
||||
|
||||
// Ensure at least one is enabled
|
||||
#[cfg(not(any(
|
||||
feature = "winit-19",
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26",
|
||||
)))]
|
||||
compile_error!("Please enable at least one version of `winit` (see documentation for details).");
|
||||
|
||||
// FIXME(thom): make updading winit and adding a new feature less of a hassle here.
|
||||
fn check_multiple_winits() {
|
||||
use std::io::Write as _;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
// bail out for release builds or if we've been explicitly disabled.
|
||||
if cfg!(any(not(debug_assertions), feature = "no-warn-on-multiple")) {
|
||||
return;
|
||||
}
|
||||
let winits_enabled = cfg!(feature = "winit-26") as usize
|
||||
+ 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
|
||||
+ cfg!(feature = "winit-19") as usize;
|
||||
|
||||
// Only complain once even if we're called multiple times.
|
||||
static COMPLAINED: AtomicBool = AtomicBool::new(false);
|
||||
// Note that the `Ordering` basically doesn't matter here, but even if it
|
||||
// did, `Relaxed` is still correct because we're only interested in the
|
||||
// effects on a single atomic variable.
|
||||
if winits_enabled <= 1
|
||||
|| COMPLAINED
|
||||
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let mut err = Vec::with_capacity(512);
|
||||
|
||||
// Log the complaint into a buffer first — in practice this is enough to
|
||||
// ensure atomicity.
|
||||
let _ = writeln!(
|
||||
err,
|
||||
"Warning (imgui-winit-support): More than one `winit-*` version feature is enabled \
|
||||
(this likely indicates misconfiguration, see documentation for details)."
|
||||
);
|
||||
let feats = [
|
||||
("winit-26", cfg!(feature = "winit-26"), " (default)"),
|
||||
("winit-25", cfg!(feature = "winit-25"), ""),
|
||||
("winit-24", cfg!(feature = "winit-24"), ""),
|
||||
("winit-23", cfg!(feature = "winit-23"), ""),
|
||||
("winit-22", cfg!(feature = "winit-22"), ""),
|
||||
("winit-20", cfg!(feature = "winit-20"), ""),
|
||||
("winit-19", cfg!(feature = "winit-19"), ""),
|
||||
];
|
||||
for &(name, enabled, extra) in &feats {
|
||||
if enabled {
|
||||
let _ = writeln!(err, " `feature = {:?}` is enabled{}", name, extra);
|
||||
}
|
||||
}
|
||||
if cfg!(feature = "winit-25") && winits_enabled == 2 {
|
||||
let _ = writeln!(
|
||||
err,
|
||||
" Perhaps you are missing a `default-features = false`?",
|
||||
);
|
||||
}
|
||||
let _ = writeln!(
|
||||
err,
|
||||
" (Note: This warning is only present in debug builds, and \
|
||||
can be disabled using the \"no-warn-on-multiple\" feature)"
|
||||
);
|
||||
let _ = std::io::stderr().write_all(&err);
|
||||
}
|
||||
|
||||
/// State of a single mouse button. Used so that we can detect cases where mouse
|
||||
/// press and release occur on the same frame (seems surprisingly frequent on
|
||||
/// macOS now...)
|
||||
@ -390,34 +149,6 @@ fn to_winit_cursor(cursor: imgui::MouseCursor) -> MouseCursor {
|
||||
}
|
||||
|
||||
impl CursorSettings {
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
fn apply(&self, window: &Window) {
|
||||
match self.cursor {
|
||||
Some(mouse_cursor) if !self.draw_cursor => {
|
||||
window.hide_cursor(false);
|
||||
window.set_cursor(to_winit_cursor(mouse_cursor));
|
||||
}
|
||||
_ => window.hide_cursor(true),
|
||||
}
|
||||
}
|
||||
#[cfg(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
))]
|
||||
fn apply(&self, window: &Window) {
|
||||
match self.cursor {
|
||||
Some(mouse_cursor) if !self.draw_cursor => {
|
||||
@ -478,8 +209,6 @@ impl WinitPlatform {
|
||||
/// * keys are configured
|
||||
/// * platform name is set
|
||||
pub fn init(imgui: &mut Context) -> WinitPlatform {
|
||||
// noop in non-debug builds, if disabled, or if called a second time.
|
||||
check_multiple_winits();
|
||||
let io = imgui.io_mut();
|
||||
io.backend_flags.insert(BackendFlags::HAS_MOUSE_CURSORS);
|
||||
io.backend_flags.insert(BackendFlags::HAS_SET_MOUSE_POS);
|
||||
@ -522,41 +251,6 @@ impl WinitPlatform {
|
||||
///
|
||||
/// * framebuffer scale (= DPI factor) is set
|
||||
/// * display size is set
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn attach_window(&mut self, io: &mut Io, window: &Window, hidpi_mode: HiDpiMode) {
|
||||
let (hidpi_mode, hidpi_factor) = hidpi_mode.apply(window.get_hidpi_factor());
|
||||
self.hidpi_mode = hidpi_mode;
|
||||
self.hidpi_factor = hidpi_factor;
|
||||
io.display_framebuffer_scale = [hidpi_factor as f32, hidpi_factor as f32];
|
||||
if let Some(logical_size) = window.get_inner_size() {
|
||||
let logical_size = self.scale_size_from_winit(window, logical_size);
|
||||
io.display_size = [logical_size.width as f32, logical_size.height as f32];
|
||||
}
|
||||
}
|
||||
/// Attaches the platform instance to a winit window.
|
||||
///
|
||||
/// This function configures imgui-rs in the following ways:
|
||||
///
|
||||
/// * framebuffer scale (= DPI factor) is set
|
||||
/// * display size is set
|
||||
#[cfg(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26",
|
||||
))]
|
||||
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;
|
||||
@ -576,37 +270,6 @@ 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(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn scale_size_from_winit(&self, window: &Window, logical_size: LogicalSize) -> LogicalSize {
|
||||
match self.hidpi_mode {
|
||||
ActiveHiDpiMode::Default => logical_size,
|
||||
_ => logical_size
|
||||
.to_physical(window.get_hidpi_factor())
|
||||
.to_logical(self.hidpi_factor),
|
||||
}
|
||||
}
|
||||
/// Scales a logical size coming from winit using the current DPI mode.
|
||||
///
|
||||
/// 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(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
))]
|
||||
pub fn scale_size_from_winit(
|
||||
&self,
|
||||
window: &Window,
|
||||
@ -623,41 +286,6 @@ 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(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn scale_pos_from_winit(
|
||||
&self,
|
||||
window: &Window,
|
||||
logical_pos: LogicalPosition,
|
||||
) -> LogicalPosition {
|
||||
match self.hidpi_mode {
|
||||
ActiveHiDpiMode::Default => logical_pos,
|
||||
_ => logical_pos
|
||||
.to_physical(window.get_hidpi_factor())
|
||||
.to_logical(self.hidpi_factor),
|
||||
}
|
||||
}
|
||||
/// Scales a logical position coming from winit using the current DPI mode.
|
||||
///
|
||||
/// 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(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
))]
|
||||
pub fn scale_pos_from_winit(
|
||||
&self,
|
||||
window: &Window,
|
||||
@ -674,41 +302,6 @@ 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(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn scale_pos_for_winit(
|
||||
&self,
|
||||
window: &Window,
|
||||
logical_pos: LogicalPosition,
|
||||
) -> LogicalPosition {
|
||||
match self.hidpi_mode {
|
||||
ActiveHiDpiMode::Default => logical_pos,
|
||||
_ => logical_pos
|
||||
.to_physical(self.hidpi_factor)
|
||||
.to_logical(window.get_hidpi_factor()),
|
||||
}
|
||||
}
|
||||
/// Scales a logical position for winit using the current DPI mode.
|
||||
///
|
||||
/// 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(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
))]
|
||||
pub fn scale_pos_for_winit(
|
||||
&self,
|
||||
window: &Window,
|
||||
@ -728,116 +321,6 @@ impl WinitPlatform {
|
||||
/// * window size / dpi factor changes are applied
|
||||
/// * keyboard state is updated
|
||||
/// * mouse state is updated
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn handle_event(&mut self, io: &mut Io, window: &Window, event: &Event) {
|
||||
match *event {
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
ref event,
|
||||
} if window_id == window.id() => {
|
||||
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;
|
||||
match key {
|
||||
VirtualKeyCode::LShift | VirtualKeyCode::RShift => io.key_shift = false,
|
||||
VirtualKeyCode::LControl | VirtualKeyCode::RControl => io.key_ctrl = false,
|
||||
VirtualKeyCode::LAlt | VirtualKeyCode::RAlt => io.key_alt = false,
|
||||
VirtualKeyCode::LWin | VirtualKeyCode::RWin => io.key_super = false,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
/// 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(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
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>) {
|
||||
match *event {
|
||||
Event::WindowEvent {
|
||||
window_id,
|
||||
ref event,
|
||||
} if window_id == window.id() => {
|
||||
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;
|
||||
}
|
||||
|
||||
// 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!
|
||||
Event::DeviceEvent {
|
||||
event: DeviceEvent::ModifiersChanged(modifiers),
|
||||
..
|
||||
} => {
|
||||
io.key_shift = modifiers.shift();
|
||||
io.key_ctrl = modifiers.ctrl();
|
||||
io.key_alt = modifiers.alt();
|
||||
io.key_super = modifiers.logo();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
/// 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",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26",
|
||||
))]
|
||||
pub fn handle_event<T>(&mut self, io: &mut Io, window: &Window, event: &Event<T>) {
|
||||
match *event {
|
||||
Event::WindowEvent {
|
||||
@ -872,235 +355,6 @@ impl WinitPlatform {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
|
||||
match *event {
|
||||
WindowEvent::Resized(logical_size) => {
|
||||
let logical_size = self.scale_size_from_winit(window, logical_size);
|
||||
io.display_size = [logical_size.width as f32, logical_size.height as f32];
|
||||
}
|
||||
WindowEvent::HiDpiFactorChanged(scale) => {
|
||||
let hidpi_factor = match self.hidpi_mode {
|
||||
ActiveHiDpiMode::Default => scale,
|
||||
ActiveHiDpiMode::Rounded => scale.round(),
|
||||
_ => return,
|
||||
};
|
||||
// Mouse position needs to be changed while we still have both the old and the new
|
||||
// values
|
||||
if io.mouse_pos[0].is_finite() && io.mouse_pos[1].is_finite() {
|
||||
io.mouse_pos = [
|
||||
io.mouse_pos[0] * (hidpi_factor / self.hidpi_factor) as f32,
|
||||
io.mouse_pos[1] * (hidpi_factor / self.hidpi_factor) as f32,
|
||||
];
|
||||
}
|
||||
self.hidpi_factor = hidpi_factor;
|
||||
io.display_framebuffer_scale = [hidpi_factor as f32, hidpi_factor as f32];
|
||||
// Window size might change too if we are using DPI rounding
|
||||
if let Some(logical_size) = window.get_inner_size() {
|
||||
let logical_size = self.scale_size_from_winit(window, logical_size);
|
||||
io.display_size = [logical_size.width as f32, logical_size.height as f32];
|
||||
}
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
virtual_keycode: Some(key),
|
||||
state,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
io.keys_down[key as usize] = state == ElementState::Pressed;
|
||||
}
|
||||
WindowEvent::ReceivedCharacter(ch) => {
|
||||
// Exclude the backspace key ('\u{7f}'). Otherwise we will insert this char and then
|
||||
// delete it.
|
||||
if ch != '\u{7f}' {
|
||||
io.add_input_character(ch)
|
||||
}
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let position = self.scale_pos_from_winit(window, position);
|
||||
io.mouse_pos = [position.x as f32, position.y as f32];
|
||||
}
|
||||
WindowEvent::MouseWheel {
|
||||
delta,
|
||||
phase: TouchPhase::Moved,
|
||||
..
|
||||
} => match delta {
|
||||
MouseScrollDelta::LineDelta(h, v) => {
|
||||
io.mouse_wheel_h = h;
|
||||
io.mouse_wheel = v;
|
||||
}
|
||||
MouseScrollDelta::PixelDelta(pos) => {
|
||||
match pos.x.partial_cmp(&0.0) {
|
||||
Some(Ordering::Greater) => io.mouse_wheel_h += 1.0,
|
||||
Some(Ordering::Less) => io.mouse_wheel_h -= 1.0,
|
||||
_ => (),
|
||||
}
|
||||
match pos.y.partial_cmp(&0.0) {
|
||||
Some(Ordering::Greater) => io.mouse_wheel += 1.0,
|
||||
Some(Ordering::Less) => io.mouse_wheel -= 1.0,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
},
|
||||
WindowEvent::MouseInput { state, button, .. } => {
|
||||
let pressed = state == ElementState::Pressed;
|
||||
match button {
|
||||
MouseButton::Left => self.mouse_buttons[0].set(pressed),
|
||||
MouseButton::Right => self.mouse_buttons[1].set(pressed),
|
||||
MouseButton::Middle => self.mouse_buttons[2].set(pressed),
|
||||
MouseButton::Other(idx @ 0..=4) => {
|
||||
self.mouse_buttons[idx as usize].set(pressed)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
WindowEvent::Focused(newly_focused) => {
|
||||
if !newly_focused {
|
||||
// Set focus-lost to avoid stuck keys (like 'alt'
|
||||
// when alt-tabbing)
|
||||
io.app_focus_lost = true;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
)),
|
||||
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) => {
|
||||
let logical_size = physical_size.to_logical(window.scale_factor());
|
||||
let logical_size = self.scale_size_from_winit(window, logical_size);
|
||||
io.display_size = [logical_size.width as f32, logical_size.height as f32];
|
||||
}
|
||||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
let hidpi_factor = match self.hidpi_mode {
|
||||
ActiveHiDpiMode::Default => scale_factor,
|
||||
ActiveHiDpiMode::Rounded => scale_factor.round(),
|
||||
_ => return,
|
||||
};
|
||||
// Mouse position needs to be changed while we still have both the old and the new
|
||||
// values
|
||||
if io.mouse_pos[0].is_finite() && io.mouse_pos[1].is_finite() {
|
||||
io.mouse_pos = [
|
||||
io.mouse_pos[0] * (hidpi_factor / self.hidpi_factor) as f32,
|
||||
io.mouse_pos[1] * (hidpi_factor / self.hidpi_factor) as f32,
|
||||
];
|
||||
}
|
||||
self.hidpi_factor = hidpi_factor;
|
||||
io.display_framebuffer_scale = [hidpi_factor as f32, hidpi_factor as f32];
|
||||
// Window size might change too if we are using DPI rounding
|
||||
let logical_size = window.inner_size().to_logical(scale_factor);
|
||||
let logical_size = self.scale_size_from_winit(window, logical_size);
|
||||
io.display_size = [logical_size.width as f32, logical_size.height as f32];
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
input:
|
||||
KeyboardInput {
|
||||
virtual_keycode: Some(key),
|
||||
state,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
let pressed = state == ElementState::Pressed;
|
||||
io.keys_down[key as usize] = pressed;
|
||||
|
||||
// This is a bit redundant here, but we'll leave it in. The OS occasionally
|
||||
// fails to send modifiers keys, but it doesn't seem to send false-positives,
|
||||
// so double checking isn't terrible in case some system *doesn't* send
|
||||
// device events sometimes.
|
||||
match key {
|
||||
VirtualKeyCode::LShift | VirtualKeyCode::RShift => io.key_shift = pressed,
|
||||
VirtualKeyCode::LControl | VirtualKeyCode::RControl => io.key_ctrl = pressed,
|
||||
VirtualKeyCode::LAlt | VirtualKeyCode::RAlt => io.key_alt = pressed,
|
||||
VirtualKeyCode::LWin | VirtualKeyCode::RWin => io.key_super = pressed,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
WindowEvent::ReceivedCharacter(ch) => {
|
||||
// Exclude the backspace key ('\u{7f}'). Otherwise we will insert this char and then
|
||||
// delete it.
|
||||
if ch != '\u{7f}' {
|
||||
io.add_input_character(ch)
|
||||
}
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let position = position.to_logical(window.scale_factor());
|
||||
let position = self.scale_pos_from_winit(window, position);
|
||||
io.mouse_pos = [position.x as f32, position.y as f32];
|
||||
}
|
||||
WindowEvent::MouseWheel {
|
||||
delta,
|
||||
phase: TouchPhase::Moved,
|
||||
..
|
||||
} => match delta {
|
||||
MouseScrollDelta::LineDelta(h, v) => {
|
||||
io.mouse_wheel_h = h;
|
||||
io.mouse_wheel = v;
|
||||
}
|
||||
MouseScrollDelta::PixelDelta(pos) => {
|
||||
match pos.x.partial_cmp(&0.0) {
|
||||
Some(Ordering::Greater) => io.mouse_wheel_h += 1.0,
|
||||
Some(Ordering::Less) => io.mouse_wheel_h -= 1.0,
|
||||
_ => (),
|
||||
}
|
||||
match pos.y.partial_cmp(&0.0) {
|
||||
Some(Ordering::Greater) => io.mouse_wheel += 1.0,
|
||||
Some(Ordering::Less) => io.mouse_wheel -= 1.0,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
},
|
||||
WindowEvent::MouseInput { state, button, .. } => {
|
||||
let pressed = state == ElementState::Pressed;
|
||||
match button {
|
||||
MouseButton::Left => self.mouse_buttons[0].set(pressed),
|
||||
MouseButton::Right => self.mouse_buttons[1].set(pressed),
|
||||
MouseButton::Middle => self.mouse_buttons[2].set(pressed),
|
||||
MouseButton::Other(idx @ 0..=4) => {
|
||||
self.mouse_buttons[idx as usize].set(pressed)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
WindowEvent::Focused(newly_focused) => {
|
||||
if !newly_focused {
|
||||
// Set focus-lost to avoid stuck keys (like 'alt'
|
||||
// when alt-tabbing)
|
||||
io.app_focus_lost = true;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26"
|
||||
))]
|
||||
fn handle_window_event(&mut self, io: &mut Io, window: &Window, event: &WindowEvent) {
|
||||
match *event {
|
||||
WindowEvent::Resized(physical_size) => {
|
||||
@ -1216,43 +470,6 @@ impl WinitPlatform {
|
||||
/// This function performs the following actions:
|
||||
///
|
||||
/// * mouse cursor is repositioned (if requested by imgui-rs)
|
||||
#[cfg(all(
|
||||
not(any(
|
||||
feature = "winit-26",
|
||||
feature = "winit-25",
|
||||
feature = "winit-24",
|
||||
feature = "winit-23",
|
||||
feature = "winit-22",
|
||||
feature = "winit-20"
|
||||
)),
|
||||
feature = "winit-19",
|
||||
))]
|
||||
pub fn prepare_frame(&self, io: &mut Io, window: &Window) -> Result<(), String> {
|
||||
self.copy_mouse_to_io(&mut io.mouse_down);
|
||||
if io.want_set_mouse_pos {
|
||||
let logical_pos = self.scale_pos_for_winit(
|
||||
window,
|
||||
LogicalPosition::new(f64::from(io.mouse_pos[0]), f64::from(io.mouse_pos[1])),
|
||||
);
|
||||
window.set_cursor_position(logical_pos)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
/// Frame preparation callback.
|
||||
///
|
||||
/// Call this before calling the imgui-rs context `frame` function.
|
||||
/// This function performs the following actions:
|
||||
///
|
||||
/// * mouse cursor is repositioned (if requested by imgui-rs)
|
||||
#[cfg(any(
|
||||
feature = "winit-20",
|
||||
feature = "winit-22",
|
||||
feature = "winit-23",
|
||||
feature = "winit-24",
|
||||
feature = "winit-25",
|
||||
feature = "winit-26",
|
||||
))]
|
||||
pub fn prepare_frame(&self, io: &mut Io, window: &Window) -> Result<(), ExternalError> {
|
||||
self.copy_mouse_to_io(&mut io.mouse_down);
|
||||
if io.want_set_mouse_pos {
|
||||
|
||||
@ -32,30 +32,11 @@ fn try_main() -> Result<()> {
|
||||
}
|
||||
|
||||
fn lint_all() -> Result<()> {
|
||||
// Lint with only default, only docking, and only freetype
|
||||
// Lint with only default, only docking, and only freetype, and everything
|
||||
xshell::cmd!("cargo clippy --workspace --all-targets").run()?;
|
||||
xshell::cmd!("cargo clippy --workspace --all-targets --features docking").run()?;
|
||||
xshell::cmd!("cargo clippy --workspace --all-targets --features freetype").run()?;
|
||||
|
||||
// Lint winit with all features
|
||||
xshell::cmd!(
|
||||
"cargo clippy --manifest-path imgui-winit-support/Cargo.toml --all-features --all-targets"
|
||||
)
|
||||
.run()?;
|
||||
|
||||
// Lint with various winit versions
|
||||
let winits = &[
|
||||
"winit-19",
|
||||
"winit-20",
|
||||
"winit-22",
|
||||
"winit-23/default",
|
||||
"winit-24/default",
|
||||
"winit-25/default",
|
||||
"winit-26/default",
|
||||
];
|
||||
for &winit in winits {
|
||||
xshell::cmd!("cargo clippy --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features {winit} --all-targets").run()?;
|
||||
}
|
||||
xshell::cmd!("cargo clippy --workspace --all-targets --all-features").run()?;
|
||||
|
||||
// Check formatting
|
||||
xshell::cmd!("cargo fmt --all -- --check").run()?;
|
||||
@ -71,18 +52,6 @@ fn test_all() -> Result<()> {
|
||||
// Test doc examples
|
||||
xshell::cmd!("cargo test --workspace --doc").run()?;
|
||||
|
||||
// Test with various winit versions
|
||||
let winits = &[
|
||||
"winit-19",
|
||||
"winit-20",
|
||||
"winit-22",
|
||||
"winit-23/default",
|
||||
"winit-24/default",
|
||||
"winit-25/default",
|
||||
];
|
||||
for &winit in winits {
|
||||
xshell::cmd!("cargo test --manifest-path imgui-winit-support/Cargo.toml --no-default-features --features {winit} --all-targets").run()?;
|
||||
}
|
||||
// Run heavy tests in release mode
|
||||
xshell::cmd!("cargo test -p imgui --release -- --ignored").run()?;
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user