diff --git a/CHANGELOG.md b/CHANGELOG.md index 192ce58bf4..32da86f71a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Implement `Default`, `Hash`, and `Eq` for `LogicalPosition`, `PhysicalPosition`, `LogicalSize`, and `PhysicalSize`. - On macOS, initialize the Menu Bar with minimal defaults. (Can be prevented using `enable_default_menu_creation`) - On macOS, change the default behavior for first click when the window was unfocused. Now the window becomes focused and then emits a `MouseInput` event on a "first mouse click". +- Implement mint (math interoperability standard types) conversions (under feature flag `mint`). # 0.24.0 (2020-12-09) diff --git a/Cargo.toml b/Cargo.toml index 1af7d4d23e..45916253b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ log = "0.4" serde = { version = "1", optional = true, features = ["serde_derive"] } raw-window-handle = "0.3" bitflags = "1" +mint = { version = "0.5.6", optional = true } [dev-dependencies] image = "0.23.12" diff --git a/README.md b/README.md index 8ba6518d4a..6dd8c8d59c 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Winit provides the following features, which can be enabled in your `Cargo.toml` * `serde`: Enables serialization/deserialization of certain types with [Serde](https://crates.io/crates/serde). * `x11` (enabled by default): On Unix platform, compiles with the X11 backend * `wayland` (enabled by default): On Unix platform, compiles with the Wayland backend +* `mint`: Enables mint (math interoperability standard types) conversions. ### Platform-specific usage diff --git a/src/dpi.rs b/src/dpi.rs index 35458452f4..ac08952ffa 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -228,6 +228,23 @@ impl Into<[X; 2]> for LogicalPosition

{ } } +#[cfg(feature = "mint")] +impl From> for LogicalPosition

{ + fn from(mint: mint::Point2

) -> Self { + Self::new(mint.x, mint.y) + } +} + +#[cfg(feature = "mint")] +impl From> for mint::Point2

{ + fn from(winit: LogicalPosition

) -> Self { + mint::Point2 { + x: winit.x, + y: winit.y, + } + } +} + /// A position represented in physical pixels. #[derive(Debug, Copy, Clone, Eq, PartialEq, Default, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -293,6 +310,23 @@ impl Into<[X; 2]> for PhysicalPosition

{ } } +#[cfg(feature = "mint")] +impl From> for PhysicalPosition

{ + fn from(mint: mint::Point2

) -> Self { + Self::new(mint.x, mint.y) + } +} + +#[cfg(feature = "mint")] +impl From> for mint::Point2

{ + fn from(winit: PhysicalPosition

) -> Self { + mint::Point2 { + x: winit.x, + y: winit.y, + } + } +} + /// A size represented in logical pixels. #[derive(Debug, Copy, Clone, Eq, PartialEq, Default, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -358,6 +392,23 @@ impl Into<[X; 2]> for LogicalSize

{ } } +#[cfg(feature = "mint")] +impl From> for LogicalSize

{ + fn from(mint: mint::Vector2

) -> Self { + Self::new(mint.x, mint.y) + } +} + +#[cfg(feature = "mint")] +impl From> for mint::Vector2

{ + fn from(winit: LogicalSize

) -> Self { + mint::Vector2 { + x: winit.width, + y: winit.height, + } + } +} + /// A size represented in physical pixels. #[derive(Debug, Copy, Clone, Eq, PartialEq, Default, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -420,6 +471,23 @@ impl Into<[X; 2]> for PhysicalSize

{ } } +#[cfg(feature = "mint")] +impl From> for PhysicalSize

{ + fn from(mint: mint::Vector2

) -> Self { + Self::new(mint.x, mint.y) + } +} + +#[cfg(feature = "mint")] +impl From> for mint::Vector2

{ + fn from(winit: PhysicalSize

) -> Self { + mint::Vector2 { + x: winit.width, + y: winit.height, + } + } +} + /// A size that's either physical or logical. #[derive(Debug, Copy, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]