Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/font.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A font.
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum Font {
/// The default font.
///
Expand Down
2 changes: 1 addition & 1 deletion graphics/src/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions graphics/src/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
/// The vertices of the mesh
pub vertices: Vec<T>,
Expand All @@ -14,15 +14,15 @@ pub struct Mesh2D<T> {
}

/// 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.
pub position: [f32; 2],
}

/// 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.
Expand Down
4 changes: 2 additions & 2 deletions graphics/src/widget/canvas/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<State>,
}
Expand Down
2 changes: 1 addition & 1 deletion graphics/src/widget/qr_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<qrcode::Color>,
width: usize,
Expand Down
1 change: 1 addition & 0 deletions lazy/src/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ where
}
}

#[derive(PartialEq)]
struct State {
tree: RefCell<Tree>,
}
Expand Down
10 changes: 8 additions & 2 deletions native/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,6 +91,12 @@ impl Hash for Handle {
#[derive(Clone)]
pub struct Bytes(Arc<dyn AsRef<[u8]> + 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 {
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions native/src/mouse/click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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,
time: Instant,
}

/// The kind of mouse click.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Kind {
/// A single click
Single,
Expand Down
2 changes: 1 addition & 1 deletion native/src/overlay/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
}

/// The local state of a [`Menu`].
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct State {
tree: Tree,
}
Expand Down
4 changes: 2 additions & 2 deletions native/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data>,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion native/src/widget/image/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion native/src/widget/mouse_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions native/src/widget/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ fn notify_on_scroll<Message>(
}

/// The local state of a [`Scrollable`].
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct State {
scroll_area_touched_at: Option<Point>,
offset_y: Offset,
Expand Down Expand Up @@ -982,7 +982,7 @@ impl operation::Scrollable for State {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
enum Offset {
Absolute(f32),
Relative(f32),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Focus>,
is_dragging: bool,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions native/src/widget/text_input/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion native/src/widget/text_input/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
Expand Down
14 changes: 13 additions & 1 deletion native/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -135,6 +135,18 @@ pub enum State {
Some(Box<dyn Any>),
}

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::<Tree>() == other_state.downcast_ref::<Tree>()
}
_ => false,
}
}
}

impl State {
/// Creates a new [`State`].
pub fn new<T>(state: T) -> Self
Expand Down