diff --git a/core/src/font.rs b/core/src/font.rs index d8c34e5a86..d7dbb498fb 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -1,5 +1,5 @@ /// A font. -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy, Default, PartialEq)] pub enum Font { /// The default font. /// diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index cef422a2ae..827791f1eb 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -9,7 +9,7 @@ use crate::triangle; use std::sync::Arc; /// A rendering primitive. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub enum Primitive { /// An empty primitive #[default] diff --git a/graphics/src/triangle.rs b/graphics/src/triangle.rs index f52b2339b1..67d9807c36 100644 --- a/graphics/src/triangle.rs +++ b/graphics/src/triangle.rs @@ -2,7 +2,7 @@ use bytemuck::{Pod, Zeroable}; /// A set of [`Vertex2D`] and indices representing a list of triangles. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct Mesh2D { /// The vertices of the mesh pub vertices: Vec, @@ -14,7 +14,7 @@ pub struct Mesh2D { } /// A two-dimensional vertex. -#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[derive(Copy, Clone, Debug, Zeroable, Pod, PartialEq)] #[repr(C)] pub struct Vertex2D { /// The vertex position in 2D space. @@ -22,7 +22,7 @@ pub struct Vertex2D { } /// A two-dimensional vertex with a color. -#[derive(Copy, Clone, Debug, Zeroable, Pod)] +#[derive(Copy, Clone, Debug, Zeroable, Pod, PartialEq)] #[repr(C)] pub struct ColoredVertex2D { /// The vertex position in 2D space. diff --git a/graphics/src/widget/canvas/cache.rs b/graphics/src/widget/canvas/cache.rs index 678b0f927b..485a93186e 100644 --- a/graphics/src/widget/canvas/cache.rs +++ b/graphics/src/widget/canvas/cache.rs @@ -4,7 +4,7 @@ use crate::Primitive; use iced_native::Size; use std::{cell::RefCell, sync::Arc}; -#[derive(Default)] +#[derive(Default, PartialEq)] enum State { #[default] Empty, @@ -18,7 +18,7 @@ enum State { /// /// A [`Cache`] will not redraw its geometry unless the dimensions of its layer /// change or it is explicitly cleared. -#[derive(Debug, Default)] +#[derive(Debug, Default, PartialEq)] pub struct Cache { state: RefCell, } diff --git a/graphics/src/widget/qr_code.rs b/graphics/src/widget/qr_code.rs index 12ce5b1f90..1a251a8781 100644 --- a/graphics/src/widget/qr_code.rs +++ b/graphics/src/widget/qr_code.rs @@ -140,7 +140,7 @@ where /// The state of a [`QRCode`]. /// /// It stores the data that will be displayed. -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct State { contents: Vec, width: usize, diff --git a/lazy/src/responsive.rs b/lazy/src/responsive.rs index d87815f660..b5ec8814c7 100644 --- a/lazy/src/responsive.rs +++ b/lazy/src/responsive.rs @@ -112,6 +112,7 @@ where } } +#[derive(PartialEq)] struct State { tree: RefCell, } diff --git a/native/src/image.rs b/native/src/image.rs index 70fbade052..cde8777c0d 100644 --- a/native/src/image.rs +++ b/native/src/image.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use std::sync::Arc; /// A handle of some image data. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Handle { id: u64, data: Data, @@ -91,6 +91,12 @@ impl Hash for Handle { #[derive(Clone)] pub struct Bytes(Arc + Send + Sync + 'static>); +impl PartialEq for Bytes { + fn eq(&self, other: &Self) -> bool { + self.0.as_ref().as_ref() == other.0.as_ref().as_ref() + } +} + impl Bytes { /// Creates new [`Bytes`] around `data`. pub fn new(data: impl AsRef<[u8]> + Send + Sync + 'static) -> Self { @@ -125,7 +131,7 @@ impl std::ops::Deref for Bytes { } /// The data of a raster image. -#[derive(Clone, Hash)] +#[derive(Clone, Hash, PartialEq)] pub enum Data { /// File data Path(PathBuf), diff --git a/native/src/mouse/click.rs b/native/src/mouse/click.rs index 4a7d796c3c..344cc46ec1 100644 --- a/native/src/mouse/click.rs +++ b/native/src/mouse/click.rs @@ -3,7 +3,7 @@ use crate::time::Instant; use crate::Point; /// A mouse click. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Click { kind: Kind, position: Point, @@ -11,7 +11,7 @@ pub struct Click { } /// The kind of mouse click. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Kind { /// A single click Single, diff --git a/native/src/overlay/menu.rs b/native/src/overlay/menu.rs index d93a3b5655..d105c0e52d 100644 --- a/native/src/overlay/menu.rs +++ b/native/src/overlay/menu.rs @@ -115,7 +115,7 @@ where } /// The local state of a [`Menu`]. -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct State { tree: Tree, } diff --git a/native/src/svg.rs b/native/src/svg.rs index 9b98877a2e..38484c17d9 100644 --- a/native/src/svg.rs +++ b/native/src/svg.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use std::sync::Arc; /// A handle of Svg data. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Handle { id: u64, data: Arc, @@ -57,7 +57,7 @@ impl Hash for Handle { } /// The data of a vectorial image. -#[derive(Clone, Hash)] +#[derive(Clone, Hash, PartialEq)] pub enum Data { /// File data Path(PathBuf), diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs index 1f8d5d7a49..57ea5de6b5 100644 --- a/native/src/widget/image/viewer.rs +++ b/native/src/widget/image/viewer.rs @@ -336,7 +336,7 @@ where } /// The local state of a [`Viewer`]. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct State { scale: f32, starting_offset: Vector, diff --git a/native/src/widget/mouse_area.rs b/native/src/widget/mouse_area.rs index 69cfddbfde..1356318e79 100644 --- a/native/src/widget/mouse_area.rs +++ b/native/src/widget/mouse_area.rs @@ -68,7 +68,7 @@ impl<'a, Message, Renderer> MouseArea<'a, Message, Renderer> { } /// Local state of the [`MouseArea`]. -#[derive(Default)] +#[derive(Default, PartialEq)] struct State { // TODO: Support on_mouse_enter and on_mouse_exit } diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index e35a4f9634..daf017f856 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -947,7 +947,7 @@ fn notify_on_scroll( } /// The local state of a [`Scrollable`]. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct State { scroll_area_touched_at: Option, offset_y: Offset, @@ -982,7 +982,7 @@ impl operation::Scrollable for State { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] enum Offset { Absolute(f32), Relative(f32), @@ -1002,7 +1002,7 @@ impl Offset { } /// The current [`Viewport`] of the [`Scrollable`]. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct Viewport { offset_x: Offset, offset_y: Offset, diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 6113cf94c0..6cb560e862 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -1134,7 +1134,7 @@ pub fn mouse_interaction( } /// The state of a [`TextInput`]. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, PartialEq)] pub struct State { is_focused: Option, is_dragging: bool, @@ -1145,7 +1145,7 @@ pub struct State { // TODO: Add stateful horizontal scrolling offset } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] struct Focus { updated_at: Instant, now: Instant, diff --git a/native/src/widget/text_input/cursor.rs b/native/src/widget/text_input/cursor.rs index 4f3b159b9d..ae9cf6ce1e 100644 --- a/native/src/widget/text_input/cursor.rs +++ b/native/src/widget/text_input/cursor.rs @@ -2,13 +2,13 @@ use crate::widget::text_input::Value; /// The cursor of a text input. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct Cursor { state: State, } /// The state of a [`Cursor`]. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq)] pub enum State { /// Cursor without a selection Index(usize), diff --git a/native/src/widget/text_input/value.rs b/native/src/widget/text_input/value.rs index cf4da562f4..9a57560074 100644 --- a/native/src/widget/text_input/value.rs +++ b/native/src/widget/text_input/value.rs @@ -4,7 +4,7 @@ use unicode_segmentation::UnicodeSegmentation; /// /// [`TextInput`]: crate::widget::TextInput // TODO: Reduce allocations, cache results (?) -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Value { graphemes: Vec, } diff --git a/native/src/widget/tree.rs b/native/src/widget/tree.rs index 0af40c33d9..8f4a84ae62 100644 --- a/native/src/widget/tree.rs +++ b/native/src/widget/tree.rs @@ -8,7 +8,7 @@ use std::fmt; /// A persistent state widget tree. /// /// A [`Tree`] is normally associated with a specific widget in the widget tree. -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct Tree { /// The tag of the [`Tree`]. pub tag: Tag, @@ -135,6 +135,18 @@ pub enum State { Some(Box), } +impl PartialEq for State { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (State::None, State::None) => true, + (State::Some(self_state), State::Some(other_state)) => { + self_state.downcast_ref::() == other_state.downcast_ref::() + } + _ => false, + } + } +} + impl State { /// Creates a new [`State`]. pub fn new(state: T) -> Self