Implement common Std traits on many types (#3796)
This commit is contained in:
parent
9dff801f93
commit
1168cd4113
28 changed files with 167 additions and 103 deletions
|
|
@ -112,7 +112,7 @@ pub struct EventLoop {
|
|||
combining_accent: Option<char>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub(crate) struct PlatformSpecificEventLoopAttributes {
|
||||
pub(crate) android_app: Option<AndroidApp>,
|
||||
pub(crate) ignore_volume_keys: bool,
|
||||
|
|
@ -662,7 +662,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ impl EventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ use crate::window::{
|
|||
WindowAttributes, WindowButtons, WindowId as RootWindowId, WindowLevel,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub movable_by_window_background: bool,
|
||||
pub titlebar_transparent: bool,
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -702,7 +702,7 @@ impl From<&AnyObject> for WindowId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub scale_factor: Option<f64>,
|
||||
pub valid_orientations: ValidOrientations,
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl ApplicationName {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub name: Option<ApplicationName>,
|
||||
pub activation_token: Option<ActivationToken>,
|
||||
|
|
@ -75,7 +75,7 @@ pub struct PlatformSpecificWindowAttributes {
|
|||
pub x11: X11WindowAttributes,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg(x11_platform)]
|
||||
pub struct X11WindowAttributes {
|
||||
pub visual_id: Option<x11rb::protocol::xproto::Visualid>,
|
||||
|
|
@ -194,7 +194,7 @@ impl FingerId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum MonitorHandle {
|
||||
#[cfg(x11_platform)]
|
||||
X(x11::MonitorHandle),
|
||||
|
|
@ -850,6 +850,21 @@ impl OwnedDisplayHandle {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for OwnedDisplayHandle {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
#[cfg(x11_platform)]
|
||||
(Self::X(this), Self::X(other)) => Arc::as_ptr(this).eq(&Arc::as_ptr(other)),
|
||||
#[cfg(wayland_platform)]
|
||||
(Self::Wayland(this), Self::Wayland(other)) => this.eq(other),
|
||||
#[cfg(all(x11_platform, wayland_platform))]
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for OwnedDisplayHandle {}
|
||||
|
||||
/// Returns the minimum `Option<Duration>`, taking into account that `None`
|
||||
/// equates to an infinite timeout, not a zero timeout (so can't just use
|
||||
/// `Option::min`)
|
||||
|
|
|
|||
|
|
@ -796,7 +796,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use super::ActiveEventLoop;
|
|||
use crate::cursor::{BadImage, Cursor, CursorImage, CustomCursor as RootCustomCursor};
|
||||
use crate::platform::web::CustomCursorError;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) enum CustomCursorSource {
|
||||
Image(CursorImage),
|
||||
Url { url: String, hotspot_x: u16, hotspot_y: u16 },
|
||||
|
|
|
|||
|
|
@ -711,7 +711,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -457,6 +457,18 @@ pub struct PlatformSpecificWindowAttributes {
|
|||
pub(crate) append: bool,
|
||||
}
|
||||
|
||||
impl PartialEq for PlatformSpecificWindowAttributes {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
(match (&self.canvas, &other.canvas) {
|
||||
(Some(this), Some(other)) => Arc::ptr_eq(this, other),
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}) && self.prevent_default.eq(&other.prevent_default)
|
||||
&& self.focusable.eq(&other.focusable)
|
||||
&& self.append.eq(&other.append)
|
||||
}
|
||||
}
|
||||
|
||||
impl PlatformSpecificWindowAttributes {
|
||||
pub(crate) fn set_canvas(&mut self, canvas: Option<backend::RawCanvasType>) {
|
||||
let Some(canvas) = canvas else {
|
||||
|
|
|
|||
|
|
@ -143,6 +143,28 @@ impl Default for PlatformSpecificEventLoopAttributes {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PlatformSpecificEventLoopAttributes {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.any_thread.eq(&other.any_thread)
|
||||
&& self.dpi_aware.eq(&other.dpi_aware)
|
||||
&& match (&self.msg_hook, &other.msg_hook) {
|
||||
(Some(this), Some(other)) => std::ptr::eq(&this, &other),
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PlatformSpecificEventLoopAttributes {}
|
||||
|
||||
impl std::hash::Hash for PlatformSpecificEventLoopAttributes {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.any_thread.hash(state);
|
||||
self.dpi_aware.hash(state);
|
||||
std::ptr::hash(&self.msg_hook, state);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ActiveEventLoop {
|
||||
thread_id: u32,
|
||||
thread_msg_target: HWND,
|
||||
|
|
@ -565,7 +587,7 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct OwnedDisplayHandle;
|
||||
|
||||
impl OwnedDisplayHandle {
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@ pub enum IconType {
|
|||
Big = ICON_BIG as isize,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
struct RaiiIcon {
|
||||
handle: HICON,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WinIcon {
|
||||
inner: Arc<RaiiIcon>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use crate::keyboard::Key;
|
|||
use crate::platform::windows::{BackdropType, Color, CornerPreference};
|
||||
use crate::platform_impl::Fullscreen;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PlatformSpecificWindowAttributes {
|
||||
pub owner: Option<HWND>,
|
||||
pub menu: Option<HMENU>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue