Remove hash_layout method from Widget trait

This commit is contained in:
Héctor Ramón Jiménez 2022-02-22 14:10:49 +07:00
parent 9fe5080153
commit 1313c94e3b
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
35 changed files with 105 additions and 636 deletions

View file

@ -11,9 +11,7 @@ mod circle {
// implemented by `iced_wgpu` and other renderers. // implemented by `iced_wgpu` and other renderers.
use iced_native::layout::{self, Layout}; use iced_native::layout::{self, Layout};
use iced_native::renderer; use iced_native::renderer;
use iced_native::{ use iced_native::{Color, Element, Length, Point, Rectangle, Size, Widget};
Color, Element, Hasher, Length, Point, Rectangle, Size, Widget,
};
pub struct Circle { pub struct Circle {
radius: f32, radius: f32,
@ -45,12 +43,6 @@ mod circle {
layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0)) layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0))
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash;
self.radius.to_bits().hash(state);
}
fn draw( fn draw(
&self, &self,
renderer: &mut Renderer, renderer: &mut Renderer,

View file

@ -14,8 +14,7 @@ mod rainbow {
use iced_graphics::{Backend, Primitive}; use iced_graphics::{Backend, Primitive};
use iced_native::{ use iced_native::{
layout, Element, Hasher, Layout, Length, Point, Rectangle, Size, layout, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
Vector, Widget,
}; };
pub struct Rainbow; pub struct Rainbow;
@ -48,8 +47,6 @@ mod rainbow {
layout::Node::new(Size::new(size.width, size.width)) layout::Node::new(Size::new(size.width, size.width))
} }
fn hash_layout(&self, _state: &mut Hasher) {}
fn draw( fn draw(
&self, &self,
renderer: &mut Renderer<B>, renderer: &mut Renderer<B>,

View file

@ -9,10 +9,9 @@ use crate::{Backend, Primitive};
use iced_native::layout; use iced_native::layout;
use iced_native::mouse; use iced_native::mouse;
use iced_native::{ use iced_native::{
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Shell, Size, Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector,
Vector, Widget, Widget,
}; };
use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
pub mod event; pub mod event;
@ -226,14 +225,6 @@ where
}); });
}); });
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
}
} }
impl<'a, Message, P, B> From<Canvas<Message, P>> impl<'a, Message, P, B> From<Canvas<Message, P>>

View file

@ -5,8 +5,7 @@ use crate::Backend;
use iced_native::layout; use iced_native::layout;
use iced_native::{ use iced_native::{
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector, Color, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
Widget,
}; };
use thiserror::Error; use thiserror::Error;
@ -74,12 +73,6 @@ where
)) ))
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash;
self.state.contents.hash(state);
}
fn draw( fn draw(
&self, &self,
renderer: &mut Renderer<B>, renderer: &mut Renderer<B>,

View file

@ -7,12 +7,11 @@ use iced_native::mouse;
use iced_native::overlay; use iced_native::overlay;
use iced_native::renderer; use iced_native::renderer;
use iced_native::{ use iced_native::{
Clipboard, Element, Hasher, Length, Point, Rectangle, Shell, Size, Widget, Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
}; };
use ouroboros::self_referencing; use ouroboros::self_referencing;
use std::cell::RefCell; use std::cell::RefCell;
use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
/// A reusable, custom widget that uses The Elm Architecture. /// A reusable, custom widget that uses The Elm Architecture.
@ -217,12 +216,6 @@ where
}); });
} }
fn hash_layout(&self, state: &mut Hasher) {
self.with_element(|element| {
element.hash_layout(state);
});
}
fn mouse_interaction( fn mouse_interaction(
&self, &self,
layout: Layout<'_>, layout: Layout<'_>,
@ -371,18 +364,6 @@ where
.unwrap_or_default() .unwrap_or_default()
} }
fn hash_layout(&self, state: &mut Hasher, position: Point) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
(position.x as u32).hash(state);
(position.y as u32).hash(state);
self.with_overlay_maybe(|overlay| {
overlay.hash_layout(state);
});
}
fn on_event( fn on_event(
&mut self, &mut self,
event: iced_native::Event, event: iced_native::Event,

View file

@ -8,11 +8,10 @@ use iced_native::overlay;
use iced_native::renderer; use iced_native::renderer;
use iced_native::window; use iced_native::window;
use iced_native::{ use iced_native::{
Clipboard, Element, Hasher, Length, Point, Rectangle, Shell, Size, Widget, Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
}; };
use std::cell::RefCell; use std::cell::RefCell;
use std::hash::{Hash, Hasher as _};
use std::ops::Deref; use std::ops::Deref;
/// The state of a [`Responsive`] widget. /// The state of a [`Responsive`] widget.
@ -20,7 +19,6 @@ use std::ops::Deref;
pub struct State { pub struct State {
last_size: Option<Size>, last_size: Option<Size>,
last_layout: layout::Node, last_layout: layout::Node,
last_layout_hash: u64,
} }
impl State { impl State {
@ -76,8 +74,6 @@ where
Length::Fill Length::Fill
} }
fn hash_layout(&self, _hasher: &mut Hasher) {}
fn layout( fn layout(
&self, &self,
_renderer: &Renderer, _renderer: &Renderer,
@ -270,16 +266,6 @@ where
let element = let element =
view.take().unwrap()(state.last_size.unwrap_or(Size::ZERO)); view.take().unwrap()(state.last_size.unwrap_or(Size::ZERO));
let new_layout_hash = {
let mut hasher = Hasher::default();
element.hash_layout(&mut hasher);
hasher.finish()
};
if state.last_size != Some(state.last_layout.size())
|| new_layout_hash != state.last_layout_hash
{
state.last_layout = element.layout( state.last_layout = element.layout(
renderer.deref(), renderer.deref(),
&layout::Limits::new( &layout::Limits::new(
@ -288,9 +274,6 @@ where
), ),
); );
state.last_layout_hash = new_layout_hash;
}
*self = Content::Ready(Some( *self = Content::Ready(Some(
CacheBuilder { CacheBuilder {
element, element,
@ -400,18 +383,6 @@ where
.unwrap_or_default() .unwrap_or_default()
} }
fn hash_layout(&self, state: &mut Hasher, position: Point) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
(position.x as u32).hash(state);
(position.y as u32).hash(state);
self.with_overlay_maybe(|overlay| {
overlay.hash_layout(state);
});
}
fn on_event( fn on_event(
&mut self, &mut self,
event: iced_native::Event, event: iced_native::Event,

View file

@ -4,7 +4,7 @@ use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
Clipboard, Color, Hasher, Layout, Length, Point, Rectangle, Shell, Widget, Clipboard, Color, Layout, Length, Point, Rectangle, Shell, Widget,
}; };
/// A generic [`Widget`]. /// A generic [`Widget`].
@ -269,11 +269,6 @@ where
) )
} }
/// Computes the _layout_ hash of the [`Element`].
pub fn hash_layout(&self, state: &mut Hasher) {
self.widget.hash_layout(state);
}
/// Returns the overlay of the [`Element`], if there is any. /// Returns the overlay of the [`Element`], if there is any.
pub fn overlay<'b>( pub fn overlay<'b>(
&'b mut self, &'b mut self,
@ -379,10 +374,6 @@ where
) )
} }
fn hash_layout(&self, state: &mut Hasher) {
self.widget.hash_layout(state);
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,
@ -504,10 +495,6 @@ where
) )
} }
fn hash_layout(&self, state: &mut Hasher) {
self.element.widget.hash_layout(state);
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -10,7 +10,7 @@ use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::{Clipboard, Hasher, Layout, Point, Rectangle, Shell, Size}; use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size};
/// An interactive component that can be displayed on top of other widgets. /// An interactive component that can be displayed on top of other widgets.
pub trait Overlay<Message, Renderer> pub trait Overlay<Message, Renderer>
@ -39,19 +39,6 @@ where
cursor_position: Point, cursor_position: Point,
); );
/// Computes the _layout_ hash of the [`Overlay`].
///
/// The produced hash is used by the runtime to decide if the [`Layout`]
/// needs to be recomputed between frames. Therefore, to ensure maximum
/// efficiency, the hash should only be affected by the properties of the
/// [`Overlay`] that can affect layouting.
///
/// For example, the [`Text`] widget does not hash its color property, as
/// its value cannot affect the overall [`Layout`] of the user interface.
///
/// [`Text`]: crate::widget::Text
fn hash_layout(&self, state: &mut Hasher, position: Point);
/// Processes a runtime [`Event`]. /// Processes a runtime [`Event`].
/// ///
/// It receives: /// It receives:

View file

@ -4,7 +4,7 @@ use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::{Clipboard, Hasher, Layout, Point, Rectangle, Shell, Size, Vector}; use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
/// A generic [`Overlay`]. /// A generic [`Overlay`].
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
@ -100,11 +100,6 @@ where
) { ) {
self.overlay.draw(renderer, style, layout, cursor_position) self.overlay.draw(renderer, style, layout, cursor_position)
} }
/// Computes the _layout_ hash of the [`Element`].
pub fn hash_layout(&self, state: &mut Hasher) {
self.overlay.hash_layout(state, self.position);
}
} }
struct Map<'a, A, B, Renderer> { struct Map<'a, A, B, Renderer> {
@ -184,8 +179,4 @@ where
) { ) {
self.content.draw(renderer, style, layout, cursor_position) self.content.draw(renderer, style, layout, cursor_position)
} }
fn hash_layout(&self, state: &mut Hasher, position: Point) {
self.content.hash_layout(state, position);
}
} }

View file

@ -10,8 +10,8 @@ use crate::touch;
use crate::widget::scrollable::{self, Scrollable}; use crate::widget::scrollable::{self, Scrollable};
use crate::widget::Container; use crate::widget::Container;
use crate::{ use crate::{
Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point, Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle,
Rectangle, Shell, Size, Vector, Widget, Shell, Size, Vector, Widget,
}; };
pub use iced_style::menu::Style; pub use iced_style::menu::Style;
@ -204,17 +204,6 @@ where
node node
} }
fn hash_layout(&self, state: &mut Hasher, position: Point) {
use std::hash::Hash;
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
(position.x as u32).hash(state);
(position.y as u32).hash(state);
self.container.hash_layout(state);
}
fn on_event( fn on_event(
&mut self, &mut self,
event: Event, event: Event,
@ -320,17 +309,6 @@ where
layout::Node::new(size) layout::Node::new(size)
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash as _;
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.options.len().hash(state);
self.text_size.hash(state);
self.padding.hash(state);
}
fn on_event( fn on_event(
&mut self, &mut self,
event: Event, event: Event,

View file

@ -2,12 +2,9 @@
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
use std::hash::Hasher;
/// A set of interactive graphical elements with a specific [`Layout`]. /// A set of interactive graphical elements with a specific [`Layout`].
/// ///
/// It can be updated and drawn. /// It can be updated and drawn.
@ -23,8 +20,8 @@ use std::hash::Hasher;
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct UserInterface<'a, Message, Renderer> { pub struct UserInterface<'a, Message, Renderer> {
root: Element<'a, Message, Renderer>, root: Element<'a, Message, Renderer>,
base: Layer, base: layout::Node,
overlay: Option<Layer>, overlay: Option<layout::Node>,
bounds: Size, bounds: Size,
} }
@ -89,41 +86,18 @@ where
pub fn build<E: Into<Element<'a, Message, Renderer>>>( pub fn build<E: Into<Element<'a, Message, Renderer>>>(
root: E, root: E,
bounds: Size, bounds: Size,
cache: Cache, _cache: Cache,
renderer: &mut Renderer, renderer: &mut Renderer,
) -> Self { ) -> Self {
let root = root.into(); let root = root.into();
let (base, overlay) = { let base =
let hash = { renderer.layout(&root, &layout::Limits::new(Size::ZERO, bounds));
let hasher = &mut crate::Hasher::default();
root.hash_layout(hasher);
hasher.finish()
};
let layout_is_cached =
hash == cache.base.hash && bounds == cache.bounds;
let (layout, overlay) = if layout_is_cached {
(cache.base.layout, cache.overlay)
} else {
(
renderer.layout(
&root,
&layout::Limits::new(Size::ZERO, bounds),
),
None,
)
};
(Layer { layout, hash }, overlay)
};
UserInterface { UserInterface {
root, root,
base, base,
overlay, overlay: None,
bounds, bounds,
} }
} }
@ -206,16 +180,10 @@ where
let mut state = State::Updated; let mut state = State::Updated;
let (base_cursor, overlay_statuses) = if let Some(mut overlay) = let (base_cursor, overlay_statuses) = if let Some(mut overlay) =
self.root.overlay(Layout::new(&self.base.layout), renderer) self.root.overlay(Layout::new(&self.base), renderer)
{ {
let bounds = self.bounds; let bounds = self.bounds;
let mut layout = overlay.layout(renderer, bounds);
let mut layer = Self::overlay_layer(
self.overlay.take(),
bounds,
&mut overlay,
renderer,
);
let event_statuses = events let event_statuses = events
.iter() .iter()
@ -225,7 +193,7 @@ where
let event_status = overlay.on_event( let event_status = overlay.on_event(
event, event,
Layout::new(&layer.layout), Layout::new(&layout),
cursor_position, cursor_position,
renderer, renderer,
clipboard, clipboard,
@ -233,12 +201,7 @@ where
); );
shell.revalidate_layout(|| { shell.revalidate_layout(|| {
layer = Self::overlay_layer( layout = overlay.layout(renderer, bounds);
None,
bounds,
&mut overlay,
renderer,
);
}); });
if shell.are_widgets_invalid() { if shell.are_widgets_invalid() {
@ -249,15 +212,14 @@ where
}) })
.collect(); .collect();
let base_cursor = if layer.layout.bounds().contains(cursor_position) let base_cursor = if layout.bounds().contains(cursor_position) {
{
// TODO: Type-safe cursor availability // TODO: Type-safe cursor availability
Point::new(-1.0, -1.0) Point::new(-1.0, -1.0)
} else { } else {
cursor_position cursor_position
}; };
self.overlay = Some(layer); self.overlay = Some(layout);
(base_cursor, event_statuses) (base_cursor, event_statuses)
} else { } else {
@ -273,7 +235,7 @@ where
let event_status = self.root.widget.on_event( let event_status = self.root.widget.on_event(
event, event,
Layout::new(&self.base.layout), Layout::new(&self.base),
base_cursor, base_cursor,
renderer, renderer,
clipboard, clipboard,
@ -281,19 +243,11 @@ where
); );
shell.revalidate_layout(|| { shell.revalidate_layout(|| {
let hash = { self.base = renderer.layout(
let hasher = &mut crate::Hasher::default();
self.root.hash_layout(hasher);
hasher.finish()
};
let layout = renderer.layout(
&self.root, &self.root,
&layout::Limits::new(Size::ZERO, self.bounds), &layout::Limits::new(Size::ZERO, self.bounds),
); );
self.base = Layer { layout, hash };
self.overlay = None; self.overlay = None;
}); });
@ -391,24 +345,8 @@ where
let viewport = Rectangle::with_size(self.bounds); let viewport = Rectangle::with_size(self.bounds);
self.overlay = if let Some(mut overlay) = if let Some(layout) = &self.overlay {
self.root.overlay(Layout::new(&self.base.layout), renderer) let base_cursor = if layout.bounds().contains(cursor_position) {
{
let layer = Self::overlay_layer(
self.overlay.take(),
self.bounds,
&mut overlay,
renderer,
);
Some(layer)
} else {
None
};
if let Some(layer) = &self.overlay {
let base_cursor = if layer.layout.bounds().contains(cursor_position)
{
Point::new(-1.0, -1.0) Point::new(-1.0, -1.0)
} else { } else {
cursor_position cursor_position
@ -417,7 +355,7 @@ where
self.root.widget.draw( self.root.widget.draw(
renderer, renderer,
&renderer::Style::default(), &renderer::Style::default(),
Layout::new(&self.base.layout), Layout::new(&self.base),
base_cursor, base_cursor,
&viewport, &viewport,
); );
@ -425,14 +363,14 @@ where
self.root.widget.draw( self.root.widget.draw(
renderer, renderer,
&renderer::Style::default(), &renderer::Style::default(),
Layout::new(&self.base.layout), Layout::new(&self.base),
cursor_position, cursor_position,
&viewport, &viewport,
); );
}; };
let base_interaction = self.root.widget.mouse_interaction( let base_interaction = self.root.widget.mouse_interaction(
Layout::new(&self.base.layout), Layout::new(&self.base),
cursor_position, cursor_position,
&viewport, &viewport,
renderer, renderer,
@ -452,23 +390,22 @@ where
// avoid this additional call. // avoid this additional call.
overlay overlay
.as_ref() .as_ref()
.and_then(|layer| { .and_then(|layout| {
root.overlay(Layout::new(&base.layout), renderer).map( root.overlay(Layout::new(&base), renderer).map(|overlay| {
|overlay| {
let overlay_interaction = overlay.mouse_interaction( let overlay_interaction = overlay.mouse_interaction(
Layout::new(&layer.layout), Layout::new(layout),
cursor_position, cursor_position,
&viewport, &viewport,
renderer, renderer,
); );
let overlay_bounds = layer.layout.bounds(); let overlay_bounds = layout.bounds();
renderer.with_layer(overlay_bounds, |renderer| { renderer.with_layer(overlay_bounds, |renderer| {
overlay.draw( overlay.draw(
renderer, renderer,
&renderer::Style::default(), &renderer::Style::default(),
Layout::new(&layer.layout), Layout::new(layout),
cursor_position, cursor_position,
); );
}); });
@ -478,8 +415,7 @@ where
} else { } else {
base_interaction base_interaction
} }
}, })
)
}) })
.unwrap_or(base_interaction) .unwrap_or(base_interaction)
} }
@ -487,66 +423,19 @@ where
/// Relayouts and returns a new [`UserInterface`] using the provided /// Relayouts and returns a new [`UserInterface`] using the provided
/// bounds. /// bounds.
pub fn relayout(self, bounds: Size, renderer: &mut Renderer) -> Self { pub fn relayout(self, bounds: Size, renderer: &mut Renderer) -> Self {
Self::build( Self::build(self.root, bounds, Cache, renderer)
self.root,
bounds,
Cache {
base: self.base,
overlay: self.overlay,
bounds: self.bounds,
},
renderer,
)
} }
/// Extract the [`Cache`] of the [`UserInterface`], consuming it in the /// Extract the [`Cache`] of the [`UserInterface`], consuming it in the
/// process. /// process.
pub fn into_cache(self) -> Cache { pub fn into_cache(self) -> Cache {
Cache { Cache
base: self.base,
overlay: self.overlay,
bounds: self.bounds,
} }
} }
fn overlay_layer(
cache: Option<Layer>,
bounds: Size,
overlay: &mut overlay::Element<'_, Message, Renderer>,
renderer: &Renderer,
) -> Layer {
let new_hash = {
let hasher = &mut crate::Hasher::default();
overlay.hash_layout(hasher);
hasher.finish()
};
let layout = match cache {
Some(Layer { hash, layout }) if new_hash == hash => layout,
_ => overlay.layout(renderer, bounds),
};
Layer {
layout,
hash: new_hash,
}
}
}
#[derive(Debug, Clone)]
struct Layer {
layout: layout::Node,
hash: u64,
}
/// Reusable data of a specific [`UserInterface`]. /// Reusable data of a specific [`UserInterface`].
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Cache { pub struct Cache;
base: Layer,
overlay: Option<Layer>,
bounds: Size,
}
impl Cache { impl Cache {
/// Creates an empty [`Cache`]. /// Creates an empty [`Cache`].
@ -554,14 +443,7 @@ impl Cache {
/// You should use this to initialize a [`Cache`] before building your first /// You should use this to initialize a [`Cache`] before building your first
/// [`UserInterface`]. /// [`UserInterface`].
pub fn new() -> Cache { pub fn new() -> Cache {
Cache { Cache
base: Layer {
layout: layout::Node::new(Size::new(0.0, 0.0)),
hash: 0,
},
overlay: None,
bounds: Size::ZERO,
}
} }
} }

View file

@ -75,7 +75,7 @@ use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{Clipboard, Hasher, Layout, Length, Point, Rectangle, Shell}; use crate::{Clipboard, Layout, Length, Point, Rectangle, Shell};
/// A component that displays information and allows interaction. /// A component that displays information and allows interaction.
/// ///
@ -131,19 +131,6 @@ where
viewport: &Rectangle, viewport: &Rectangle,
); );
/// Computes the _layout_ hash of the [`Widget`].
///
/// The produced hash is used by the runtime to decide if the [`Layout`]
/// needs to be recomputed between frames. Therefore, to ensure maximum
/// efficiency, the hash should only be affected by the properties of the
/// [`Widget`] that can affect layouting.
///
/// For example, the [`Text`] widget does not hash its color property, as
/// its value cannot affect the overall [`Layout`] of the user interface.
///
/// [`Text`]: crate::widget::Text
fn hash_layout(&self, state: &mut Hasher);
/// Processes a runtime [`Event`]. /// Processes a runtime [`Event`].
/// ///
/// It receives: /// It receives:

View file

@ -8,12 +8,10 @@ use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::touch; use crate::touch;
use crate::{ use crate::{
Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding, Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
Point, Rectangle, Shell, Vector, Widget, Rectangle, Shell, Vector, Widget,
}; };
use std::hash::Hash;
pub use iced_style::button::{Style, StyleSheet}; pub use iced_style::button::{Style, StyleSheet};
/// A generic widget that produces a message when pressed. /// A generic widget that produces a message when pressed.
@ -333,14 +331,6 @@ where
); );
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.content.hash_layout(state);
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -1,6 +1,4 @@
//! Show toggle controls using checkboxes. //! Show toggle controls using checkboxes.
use std::hash::Hash;
use crate::alignment; use crate::alignment;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
@ -10,8 +8,8 @@ use crate::text;
use crate::touch; use crate::touch;
use crate::widget::{self, Row, Text}; use crate::widget::{self, Row, Text};
use crate::{ use crate::{
Alignment, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Alignment, Clipboard, Element, Layout, Length, Point, Rectangle, Shell,
Shell, Widget, Widget,
}; };
pub use iced_style::checkbox::{Style, StyleSheet}; pub use iced_style::checkbox::{Style, StyleSheet};
@ -262,13 +260,6 @@ where
); );
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.label.hash(state);
}
} }
impl<'a, Message, Renderer> From<Checkbox<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Checkbox<'a, Message, Renderer>>

View file

@ -1,14 +1,12 @@
//! Distribute content vertically. //! Distribute content vertically.
use std::hash::Hash;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
Rectangle, Shell, Widget, Shell, Widget,
}; };
use std::u32; use std::u32;
@ -199,23 +197,6 @@ where
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
self.max_width.hash(state);
self.max_height.hash(state);
self.align_items.hash(state);
self.spacing.hash(state);
self.padding.hash(state);
for child in &self.children {
child.widget.hash_layout(state);
}
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -1,6 +1,4 @@
//! Decorate content and apply alignment. //! Decorate content and apply alignment.
use std::hash::Hash;
use crate::alignment::{self, Alignment}; use crate::alignment::{self, Alignment};
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
@ -8,8 +6,8 @@ use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding, Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
Point, Rectangle, Shell, Widget, Rectangle, Shell, Widget,
}; };
use std::u32; use std::u32;
@ -219,21 +217,6 @@ where
); );
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.padding.hash(state);
self.width.hash(state);
self.height.hash(state);
self.max_width.hash(state);
self.max_height.hash(state);
self.horizontal_alignment.hash(state);
self.vertical_alignment.hash(state);
self.content.hash_layout(state);
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -6,8 +6,7 @@ use crate::image;
use crate::layout; use crate::layout;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
Vector, Widget,
}; };
use std::hash::Hash; use std::hash::Hash;
@ -149,16 +148,6 @@ where
render(renderer) render(renderer)
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.handle.hash(state);
self.width.hash(state);
self.height.hash(state);
self.content_fit.hash(state);
}
} }
impl<'a, Message, Renderer, Handle> From<Image<Handle>> impl<'a, Message, Renderer, Handle> From<Image<Handle>>

View file

@ -5,8 +5,8 @@ use crate::layout;
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Shell, Size, Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector,
Vector, Widget, Widget,
}; };
use std::hash::Hash; use std::hash::Hash;
@ -335,17 +335,6 @@ where
}); });
}); });
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
self.padding.hash(state);
self.handle.hash(state);
}
} }
/// The local state of a [`Viewer`]. /// The local state of a [`Viewer`].

View file

@ -34,8 +34,8 @@ use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::touch; use crate::touch;
use crate::{ use crate::{
Clipboard, Color, Element, Hasher, Layout, Length, Point, Rectangle, Shell, Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size,
Size, Vector, Widget, Vector, Widget,
}; };
pub use iced_style::pane_grid::{Line, StyleSheet}; pub use iced_style::pane_grid::{Line, StyleSheet};
@ -666,21 +666,6 @@ where
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash;
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
self.state.hash_layout(state);
for (_, element) in &self.elements {
element.hash_layout(state);
}
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -5,9 +5,7 @@ use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::widget::container; use crate::widget::container;
use crate::widget::pane_grid::TitleBar; use crate::widget::pane_grid::TitleBar;
use crate::{ use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
Clipboard, Element, Hasher, Layout, Point, Rectangle, Shell, Size,
};
/// The content of a [`Pane`]. /// The content of a [`Pane`].
/// ///
@ -236,14 +234,6 @@ where
.max(title_bar_interaction) .max(title_bar_interaction)
} }
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
if let Some(title_bar) = &self.title_bar {
title_bar.hash_layout(state);
}
self.body.hash_layout(state);
}
pub(crate) fn overlay( pub(crate) fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -1,7 +1,7 @@
use crate::widget::pane_grid::{ use crate::widget::pane_grid::{
Axis, Configuration, Direction, Node, Pane, Split, Axis, Configuration, Direction, Node, Pane, Split,
}; };
use crate::{Hasher, Point, Rectangle, Size}; use crate::{Point, Rectangle, Size};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
@ -292,10 +292,4 @@ impl Internal {
pub fn idle(&mut self) { pub fn idle(&mut self) {
self.action = Action::Idle; self.action = Action::Idle;
} }
pub fn hash_layout(&self, hasher: &mut Hasher) {
use std::hash::Hash;
self.layout.hash(hasher);
}
} }

View file

@ -5,7 +5,7 @@ use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::widget::container; use crate::widget::container;
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Shell, Size, Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size,
}; };
/// The title bar of a [`Pane`]. /// The title bar of a [`Pane`].
@ -157,17 +157,6 @@ where
} }
} }
pub(crate) fn hash_layout(&self, hasher: &mut Hasher) {
use std::hash::Hash;
self.content.hash_layout(hasher);
self.padding.hash(hasher);
if let Some(controls) = &self.controls {
controls.hash_layout(hasher);
}
}
pub(crate) fn layout( pub(crate) fn layout(
&self, &self,
renderer: &Renderer, renderer: &Renderer,

View file

@ -10,8 +10,8 @@ use crate::renderer;
use crate::text::{self, Text}; use crate::text::{self, Text};
use crate::touch; use crate::touch;
use crate::{ use crate::{
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Size,
Shell, Size, Widget, Widget,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@ -220,24 +220,6 @@ where
layout::Node::new(size) layout::Node::new(size)
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash as _;
match self.width {
Length::Shrink => {
self.placeholder.hash(state);
self.options
.iter()
.map(ToString::to_string)
.for_each(|label| label.hash(state));
}
_ => {
self.width.hash(state);
}
}
}
fn on_event( fn on_event(
&mut self, &mut self,
event: Event, event: Event,

View file

@ -1,11 +1,9 @@
//! Provide progress feedback to your users. //! Provide progress feedback to your users.
use crate::layout; use crate::layout;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
};
use std::{hash::Hash, ops::RangeInclusive}; use std::ops::RangeInclusive;
pub use iced_style::progress_bar::{Style, StyleSheet}; pub use iced_style::progress_bar::{Style, StyleSheet};
@ -141,14 +139,6 @@ where
); );
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
}
} }
impl<'a, Message, Renderer> From<ProgressBar<'a>> impl<'a, Message, Renderer> From<ProgressBar<'a>>

View file

@ -1,6 +1,4 @@
//! Create choices using radio buttons. //! Create choices using radio buttons.
use std::hash::Hash;
use crate::alignment; use crate::alignment;
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
@ -10,8 +8,8 @@ use crate::text;
use crate::touch; use crate::touch;
use crate::widget::{self, Row, Text}; use crate::widget::{self, Row, Text};
use crate::{ use crate::{
Alignment, Clipboard, Color, Element, Hasher, Layout, Length, Point, Alignment, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
Rectangle, Shell, Widget, Shell, Widget,
}; };
pub use iced_style::radio::{Style, StyleSheet}; pub use iced_style::radio::{Style, StyleSheet};
@ -280,13 +278,6 @@ where
); );
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.label.hash(state);
}
} }
impl<'a, Message, Renderer> From<Radio<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Radio<'a, Message, Renderer>>

View file

@ -5,11 +5,10 @@ use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{
Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
Rectangle, Shell, Widget, Shell, Widget,
}; };
use std::hash::Hash;
use std::u32; use std::u32;
/// A container that distributes its contents horizontally. /// A container that distributes its contents horizontally.
@ -198,23 +197,6 @@ where
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
self.max_width.hash(state);
self.max_height.hash(state);
self.align_items.hash(state);
self.spacing.hash(state);
self.padding.hash(state);
for child in &self.children {
child.widget.hash_layout(state);
}
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -1,11 +1,7 @@
//! Display a horizontal or vertical rule for dividing content. //! Display a horizontal or vertical rule for dividing content.
use crate::layout; use crate::layout;
use crate::renderer; use crate::renderer;
use crate::{ use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
};
use std::hash::Hash;
pub use iced_style::rule::{FillMode, Style, StyleSheet}; pub use iced_style::rule::{FillMode, Style, StyleSheet};
@ -122,14 +118,6 @@ where
style.color, style.color,
); );
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.height.hash(state);
}
} }
impl<'a, Message, Renderer> From<Rule<'a>> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Rule<'a>> for Element<'a, Message, Renderer>

View file

@ -7,11 +7,11 @@ use crate::renderer;
use crate::touch; use crate::touch;
use crate::widget::Column; use crate::widget::Column;
use crate::{ use crate::{
Alignment, Background, Clipboard, Color, Element, Hasher, Layout, Length, Alignment, Background, Clipboard, Color, Element, Layout, Length, Padding,
Padding, Point, Rectangle, Shell, Size, Vector, Widget, Point, Rectangle, Shell, Size, Vector, Widget,
}; };
use std::{f32, hash::Hash, u32}; use std::{f32, u32};
pub use iced_style::scrollable::StyleSheet; pub use iced_style::scrollable::StyleSheet;
@ -570,16 +570,6 @@ where
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.height.hash(state);
self.max_height.hash(state);
self.content.hash_layout(state)
}
fn overlay( fn overlay(
&mut self, &mut self,
layout: Layout<'_>, layout: Layout<'_>,

View file

@ -7,11 +7,10 @@ use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::touch; use crate::touch;
use crate::{ use crate::{
Background, Clipboard, Color, Element, Hasher, Layout, Length, Point, Background, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
Rectangle, Shell, Size, Widget, Shell, Size, Widget,
}; };
use std::hash::Hash;
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet}; pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet};
@ -374,13 +373,6 @@ where
mouse::Interaction::default() mouse::Interaction::default()
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.width.hash(state);
}
} }
impl<'a, T, Message, Renderer> From<Slider<'a, T, Message>> impl<'a, T, Message, Renderer> From<Slider<'a, T, Message>>

View file

@ -1,9 +1,7 @@
//! Distribute content vertically. //! Distribute content vertically.
use crate::layout; use crate::layout;
use crate::renderer; use crate::renderer;
use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget}; use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
use std::hash::Hash;
/// An amount of empty space. /// An amount of empty space.
/// ///
@ -68,13 +66,6 @@ where
_viewport: &Rectangle, _viewport: &Rectangle,
) { ) {
} }
fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Space>().hash(state);
self.width.hash(state);
self.height.hash(state);
}
} }
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>

View file

@ -3,11 +3,9 @@ use crate::layout;
use crate::renderer; use crate::renderer;
use crate::svg::{self, Handle}; use crate::svg::{self, Handle};
use crate::{ use crate::{
ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
Vector, Widget,
}; };
use std::hash::Hash;
use std::path::PathBuf; use std::path::PathBuf;
/// A vector graphics image. /// A vector graphics image.
@ -146,15 +144,6 @@ where
render(renderer) render(renderer)
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
std::any::TypeId::of::<Svg>().hash(state);
self.handle.hash(state);
self.width.hash(state);
self.height.hash(state);
self.content_fit.hash(state);
}
} }
impl<'a, Message, Renderer> From<Svg> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Svg> for Element<'a, Message, Renderer>

View file

@ -3,11 +3,7 @@ use crate::alignment;
use crate::layout; use crate::layout;
use crate::renderer; use crate::renderer;
use crate::text; use crate::text;
use crate::{ use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
};
use std::hash::Hash;
/// A paragraph of text. /// A paragraph of text.
/// ///
@ -151,16 +147,6 @@ where
self.vertical_alignment, self.vertical_alignment,
); );
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.content.hash(state);
self.size.hash(state);
self.width.hash(state);
self.height.hash(state);
}
} }
/// Draws text using the same logic as the [`Text`] widget. /// Draws text using the same logic as the [`Text`] widget.

View file

@ -20,8 +20,8 @@ use crate::renderer;
use crate::text::{self, Text}; use crate::text::{self, Text};
use crate::touch; use crate::touch;
use crate::{ use crate::{
Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point, Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle,
Rectangle, Shell, Size, Vector, Widget, Shell, Size, Vector, Widget,
}; };
use std::u32; use std::u32;
@ -783,17 +783,6 @@ where
) { ) {
self.draw(renderer, layout, cursor_position, None) self.draw(renderer, layout, cursor_position, None)
} }
fn hash_layout(&self, state: &mut Hasher) {
use std::{any::TypeId, hash::Hash};
struct Marker;
TypeId::of::<Marker>().hash(state);
self.width.hash(state);
self.max_width.hash(state);
self.padding.hash(state);
self.size.hash(state);
}
} }
impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>> impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>>

View file

@ -1,5 +1,4 @@
//! Show toggle controls using togglers. //! Show toggle controls using togglers.
use std::hash::Hash;
use crate::alignment; use crate::alignment;
use crate::event; use crate::event;
@ -9,8 +8,8 @@ use crate::renderer;
use crate::text; use crate::text;
use crate::widget::{Row, Text}; use crate::widget::{Row, Text};
use crate::{ use crate::{
Alignment, Clipboard, Element, Event, Hasher, Layout, Length, Point, Alignment, Clipboard, Element, Event, Layout, Length, Point, Rectangle,
Rectangle, Shell, Widget, Shell, Widget,
}; };
pub use iced_style::toggler::{Style, StyleSheet}; pub use iced_style::toggler::{Style, StyleSheet};
@ -295,13 +294,6 @@ where
style.foreground, style.foreground,
); );
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.label.hash(state)
}
} }
impl<'a, Message, Renderer> From<Toggler<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Toggler<'a, Message, Renderer>>

View file

@ -1,8 +1,4 @@
//! Display a widget over another. //! Display a widget over another.
use std::hash::Hash;
use iced_core::Rectangle;
use crate::event; use crate::event;
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
@ -11,8 +7,8 @@ use crate::text;
use crate::widget::container; use crate::widget::container;
use crate::widget::text::Text; use crate::widget::text::Text;
use crate::{ use crate::{
Clipboard, Element, Event, Hasher, Layout, Length, Padding, Point, Shell, Clipboard, Element, Event, Layout, Length, Padding, Point, Rectangle,
Size, Vector, Widget, Shell, Size, Vector, Widget,
}; };
/// An element to display a widget over another. /// An element to display a widget over another.
@ -268,13 +264,6 @@ where
}); });
} }
} }
fn hash_layout(&self, state: &mut Hasher) {
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.content.hash_layout(state);
}
} }
impl<'a, Message, Renderer> From<Tooltip<'a, Message, Renderer>> impl<'a, Message, Renderer> From<Tooltip<'a, Message, Renderer>>