diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 13d85bfc..26959707 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,7 +19,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: default - toolchain: 1.61.0 + toolchain: 1.62.0 override: true - name: Install packages (Linux) if: runner.os == 'Linux' @@ -84,7 +84,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.61.0 + toolchain: 1.62.0 target: wasm32-unknown-unknown override: true @@ -136,7 +136,7 @@ jobs: - uses: actions/checkout@v2 - uses: EmbarkStudios/cargo-deny-action@v1 with: - rust-version: "1.61.0" + rust-version: "1.62.0" android: name: android @@ -146,7 +146,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.61.0 + toolchain: 1.62.0 target: aarch64-linux-android override: true - name: Set up cargo cache diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index b968c23a..5bdfb656 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "egui framework - write GUI apps that compiles to web and/or natively" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/eframe" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui-wgpu/Cargo.toml b/crates/egui-wgpu/Cargo.toml index 7454bc39..a450ca57 100644 --- a/crates/egui-wgpu/Cargo.toml +++ b/crates/egui-wgpu/Cargo.toml @@ -8,7 +8,7 @@ authors = [ "Emil Ernerfeldt ", ] edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/egui-wgpu" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui-winit/Cargo.toml b/crates/egui-winit/Cargo.toml index 46372516..215e6bf3 100644 --- a/crates/egui-winit/Cargo.toml +++ b/crates/egui-winit/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Bindings for using egui with winit" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/egui-winit" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui/Cargo.toml b/crates/egui/Cargo.toml index 26f911ca..c334f1f4 100644 --- a/crates/egui/Cargo.toml +++ b/crates/egui/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "An easy-to-use immediate mode GUI that runs on both web and native" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui" license = "MIT OR Apache-2.0" readme = "../../README.md" diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index 5b008020..352369de 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -3,7 +3,7 @@ //! Try the live web demo: . Read more about egui at . //! //! `egui` is in heavy development, with each new version having breaking changes. -//! You need to have rust 1.61.0 or later to use `egui`. +//! You need to have rust 1.62.0 or later to use `egui`. //! //! To quickly get started with egui, you can take a look at [`eframe_template`](https://github.com/emilk/eframe_template) //! which uses [`eframe`](https://docs.rs/eframe). diff --git a/crates/egui/src/widgets/drag_value.rs b/crates/egui/src/widgets/drag_value.rs index 7a6af298..d750041f 100644 --- a/crates/egui/src/widgets/drag_value.rs +++ b/crates/egui/src/widgets/drag_value.rs @@ -1,6 +1,6 @@ #![allow(clippy::needless_pass_by_value)] // False positives with `impl ToString` -use std::ops::RangeInclusive; +use std::{cmp::Ordering, ops::RangeInclusive}; use crate::*; @@ -508,8 +508,47 @@ impl<'a> Widget for DragValue<'a> { } fn clamp_to_range(x: f64, range: RangeInclusive) -> f64 { - x.clamp( - range.start().min(*range.end()), - range.start().max(*range.end()), - ) + let (mut min, mut max) = (*range.start(), *range.end()); + + if min.total_cmp(&max) == Ordering::Greater { + (min, max) = (max, min); + } + + match x.total_cmp(&min) { + Ordering::Less | Ordering::Equal => min, + Ordering::Greater => match x.total_cmp(&max) { + Ordering::Greater | Ordering::Equal => max, + Ordering::Less => x, + }, + } +} + +#[cfg(test)] +mod tests { + use super::clamp_to_range; + + macro_rules! total_assert_eq { + ($a:expr, $b:expr) => { + assert!( + matches!($a.total_cmp(&$b), std::cmp::Ordering::Equal), + "{} != {}", + $a, + $b + ); + }; + } + + #[test] + fn test_total_cmp_clamp_to_range() { + total_assert_eq!(0.0_f64, clamp_to_range(-0.0, 0.0..=f64::MAX)); + total_assert_eq!(-0.0_f64, clamp_to_range(0.0, -1.0..=-0.0)); + total_assert_eq!(-1.0_f64, clamp_to_range(-25.0, -1.0..=1.0)); + total_assert_eq!(5.0_f64, clamp_to_range(5.0, -1.0..=10.0)); + total_assert_eq!(15.0_f64, clamp_to_range(25.0, -1.0..=15.0)); + total_assert_eq!(1.0_f64, clamp_to_range(1.0, 1.0..=10.0)); + total_assert_eq!(10.0_f64, clamp_to_range(10.0, 1.0..=10.0)); + total_assert_eq!(5.0_f64, clamp_to_range(5.0, 10.0..=1.0)); + total_assert_eq!(5.0_f64, clamp_to_range(15.0, 5.0..=1.0)); + total_assert_eq!(1.0_f64, clamp_to_range(-5.0, 5.0..=1.0)); + } } diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index 5df4a50f..0a73c2e4 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false default-run = "egui_demo_app" diff --git a/crates/egui_demo_lib/Cargo.toml b/crates/egui_demo_lib/Cargo.toml index 441dfedb..7a379630 100644 --- a/crates/egui_demo_lib/Cargo.toml +++ b/crates/egui_demo_lib/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Example library for egui" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/egui_demo_lib" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui_extras/Cargo.toml b/crates/egui_extras/Cargo.toml index a6303b8c..83b8d082 100644 --- a/crates/egui_extras/Cargo.toml +++ b/crates/egui_extras/Cargo.toml @@ -8,7 +8,7 @@ authors = [ ] description = "Extra functionality and widgets for the egui GUI library" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui_glium/Cargo.toml b/crates/egui_glium/Cargo.toml index 7322c495..29d1e0ab 100644 --- a/crates/egui_glium/Cargo.toml +++ b/crates/egui_glium/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Bindings for using egui natively using the glium library" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/egui_glium" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/egui_glow/Cargo.toml b/crates/egui_glow/Cargo.toml index 16acd65e..2f68a38a 100644 --- a/crates/egui_glow/Cargo.toml +++ b/crates/egui_glow/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Bindings for using egui natively using the glow library" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/egui_glow" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/emath/Cargo.toml b/crates/emath/Cargo.toml index 52e1590a..4ca98c12 100644 --- a/crates/emath/Cargo.toml +++ b/crates/emath/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Minimal 2D math library for GUI work" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/emath" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/crates/epaint/Cargo.toml b/crates/epaint/Cargo.toml index e4558909..2f8bbc20 100644 --- a/crates/epaint/Cargo.toml +++ b/crates/epaint/Cargo.toml @@ -4,7 +4,7 @@ version = "0.19.0" authors = ["Emil Ernerfeldt "] description = "Minimal 2D graphics library for GUI work" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" homepage = "https://github.com/emilk/egui/tree/master/crates/epaint" license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/examples/confirm_exit/Cargo.toml b/examples/confirm_exit/Cargo.toml index db576b13..9346a3b3 100644 --- a/examples/confirm_exit/Cargo.toml +++ b/examples/confirm_exit/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/custom_3d_glow/Cargo.toml b/examples/custom_3d_glow/Cargo.toml index 57d0fe72..afe8b919 100644 --- a/examples/custom_3d_glow/Cargo.toml +++ b/examples/custom_3d_glow/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/custom_3d_three-d/Cargo.toml b/examples/custom_3d_three-d/Cargo.toml index 01e4dcd4..4c6e662b 100644 --- a/examples/custom_3d_three-d/Cargo.toml +++ b/examples/custom_3d_three-d/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false [lib] diff --git a/examples/custom_font/Cargo.toml b/examples/custom_font/Cargo.toml index da85570b..9b2637c1 100644 --- a/examples/custom_font/Cargo.toml +++ b/examples/custom_font/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/custom_font_style/Cargo.toml b/examples/custom_font_style/Cargo.toml index 670829d9..c6f86a7e 100644 --- a/examples/custom_font_style/Cargo.toml +++ b/examples/custom_font_style/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["tami5 "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/custom_window_frame/Cargo.toml b/examples/custom_window_frame/Cargo.toml index 5346f346..1c7f30d1 100644 --- a/examples/custom_window_frame/Cargo.toml +++ b/examples/custom_window_frame/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/download_image/Cargo.toml b/examples/download_image/Cargo.toml index c40d1ddb..88f03f47 100644 --- a/examples/download_image/Cargo.toml +++ b/examples/download_image/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/file_dialog/Cargo.toml b/examples/file_dialog/Cargo.toml index b15ad038..6c3b005e 100644 --- a/examples/file_dialog/Cargo.toml +++ b/examples/file_dialog/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index 0cb18dfc..c25ab134 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/puffin_profiler/Cargo.toml b/examples/puffin_profiler/Cargo.toml index 41292397..bb371f02 100644 --- a/examples/puffin_profiler/Cargo.toml +++ b/examples/puffin_profiler/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/retained_image/Cargo.toml b/examples/retained_image/Cargo.toml index d52e0a31..91742b36 100644 --- a/examples/retained_image/Cargo.toml +++ b/examples/retained_image/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/screenshot/Cargo.toml b/examples/screenshot/Cargo.toml index 75cb7970..3cdddbbe 100644 --- a/examples/screenshot/Cargo.toml +++ b/examples/screenshot/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["René Rössler "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/serial_windows/Cargo.toml b/examples/serial_windows/Cargo.toml index cee0fab6..48ac2cad 100644 --- a/examples/serial_windows/Cargo.toml +++ b/examples/serial_windows/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/examples/svg/Cargo.toml b/examples/svg/Cargo.toml index 01c421fd..5c9cfdab 100644 --- a/examples/svg/Cargo.toml +++ b/examples/svg/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Emil Ernerfeldt "] license = "MIT OR Apache-2.0" edition = "2021" -rust-version = "1.61" +rust-version = "1.62" publish = false diff --git a/rust-toolchain b/rust-toolchain index 818270c2..760a2abc 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -5,6 +5,6 @@ # to the user in the error, instead of "error: invalid channel name '[toolchain]'". [toolchain] -channel = "1.61.0" +channel = "1.62.0" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ]