From ca1fcdaf1454fd3febae8e6864c9a7dec04f41b1 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sat, 22 Jan 2022 20:09:35 -0500 Subject: Add support for `ContentFit` for `Image` --- native/src/widget/image.rs | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index b8fb662e..5ddc3642 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -5,7 +5,9 @@ pub use viewer::Viewer; use crate::image; use crate::layout; use crate::renderer; -use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget}; +use crate::{ + ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, +}; use std::hash::Hash; @@ -26,6 +28,7 @@ pub struct Image { handle: Handle, width: Length, height: Length, + fit: ContentFit, } impl Image { @@ -35,6 +38,7 @@ impl Image { handle: handle.into(), width: Length::Shrink, height: Length::Shrink, + fit: ContentFit::Contain, } } @@ -49,6 +53,13 @@ impl Image { self.height = height; self } + + /// Sets the image fit + /// + /// Defaults to [`ContentFit::Contain`] + pub fn fit(self, fit: ContentFit) -> Self { + Self { fit, ..self } + } } impl Widget for Image @@ -69,24 +80,32 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { + // The raw w/h of the underlying image let (width, height) = renderer.dimensions(&self.handle); + let image_size = Size::new(width as f32, height as f32); - let aspect_ratio = width as f32 / height as f32; - - let mut size = limits + // The size to be available to the widget prior to `Shrink`ing + let raw_size = limits .width(self.width) .height(self.height) - .resolve(Size::new(width as f32, height as f32)); - - let viewport_aspect_ratio = size.width / size.height; - - if viewport_aspect_ratio > aspect_ratio { - size.width = width as f32 * size.height / height as f32; - } else { - size.height = height as f32 * size.width / width as f32; - } - - layout::Node::new(size) + .resolve(image_size); + + // The uncropped size of the image when fit to the bounds above + let full_size = self.fit.fit(image_size, raw_size); + + // Shrink the widget to fit the resized image, if requested + let final_size = Size { + width: match self.width { + Length::Shrink => f32::min(raw_size.width, full_size.width), + _ => raw_size.width, + }, + height: match self.height { + Length::Shrink => f32::min(raw_size.height, full_size.height), + _ => raw_size.height, + }, + }; + + layout::Node::new(final_size) } fn draw( @@ -97,7 +116,22 @@ where _cursor_position: Point, _viewport: &Rectangle, ) { - renderer.draw(self.handle.clone(), layout.bounds()); + // The raw w/h of the underlying image + let (width, height) = renderer.dimensions(&self.handle); + let image_size = Size::new(width as f32, height as f32); + + let adjusted_fit = self.fit.fit(image_size, layout.bounds().size()); + + renderer.with_layer(layout.bounds(), |renderer| { + renderer.draw( + self.handle.clone(), + Rectangle { + width: adjusted_fit.width, + height: adjusted_fit.height, + ..layout.bounds() + }, + ) + }) } fn hash_layout(&self, state: &mut Hasher) { -- cgit From 395eacfc103e3123a10bebe4a9330f7c126650a4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 17:35:28 +0700 Subject: Use a new clipping layer only when necessary in `Image::draw` --- native/src/widget/image.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 5ddc3642..b253b1b8 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -121,8 +121,9 @@ where let image_size = Size::new(width as f32, height as f32); let adjusted_fit = self.fit.fit(image_size, layout.bounds().size()); + let bounds = layout.bounds(); - renderer.with_layer(layout.bounds(), |renderer| { + let render = |renderer: &mut Renderer| { renderer.draw( self.handle.clone(), Rectangle { @@ -131,7 +132,15 @@ where ..layout.bounds() }, ) - }) + }; + + if adjusted_fit.width > bounds.width + || adjusted_fit.height > bounds.height + { + renderer.with_layer(layout.bounds(), render); + } else { + render(renderer) + } } fn hash_layout(&self, state: &mut Hasher) { -- cgit From 8b5c9dfa71f770281ca277163c320571c39ee572 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 17:37:24 +0700 Subject: Make documentation of `Image::fit` consistent --- native/src/widget/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index b253b1b8..f2b8ef2f 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -54,7 +54,7 @@ impl Image { self } - /// Sets the image fit + /// Sets the [`ContentFit`] of the [`Image`]. /// /// Defaults to [`ContentFit::Contain`] pub fn fit(self, fit: ContentFit) -> Self { -- cgit From 0aff444941f8b44b5a996dde4810ba6313f43a7e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 17:51:03 +0700 Subject: Rename `Image::fit` to `content_fit` ... just for consistency! --- native/src/widget/image.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index f2b8ef2f..d83230f2 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -28,7 +28,7 @@ pub struct Image { handle: Handle, width: Length, height: Length, - fit: ContentFit, + content_fit: ContentFit, } impl Image { @@ -38,7 +38,7 @@ impl Image { handle: handle.into(), width: Length::Shrink, height: Length::Shrink, - fit: ContentFit::Contain, + content_fit: ContentFit::Contain, } } @@ -57,8 +57,11 @@ impl Image { /// Sets the [`ContentFit`] of the [`Image`]. /// /// Defaults to [`ContentFit::Contain`] - pub fn fit(self, fit: ContentFit) -> Self { - Self { fit, ..self } + pub fn content_fit(self, content_fit: ContentFit) -> Self { + Self { + content_fit, + ..self + } } } @@ -91,7 +94,7 @@ where .resolve(image_size); // The uncropped size of the image when fit to the bounds above - let full_size = self.fit.fit(image_size, raw_size); + let full_size = self.content_fit.fit(image_size, raw_size); // Shrink the widget to fit the resized image, if requested let final_size = Size { @@ -120,7 +123,8 @@ where let (width, height) = renderer.dimensions(&self.handle); let image_size = Size::new(width as f32, height as f32); - let adjusted_fit = self.fit.fit(image_size, layout.bounds().size()); + let adjusted_fit = + self.content_fit.fit(image_size, layout.bounds().size()); let bounds = layout.bounds(); let render = |renderer: &mut Renderer| { -- cgit From 6822d1d9f2c5b4fcbf65763c8edd091ac18a657e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 17:52:57 +0700 Subject: Center `Image` inside available bounds when possible --- native/src/widget/image.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index d83230f2..a2e7f765 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -6,7 +6,8 @@ use crate::image; use crate::layout; use crate::renderer; use crate::{ - ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, + ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, + Vector, Widget, }; use std::hash::Hash; @@ -128,14 +129,18 @@ where let bounds = layout.bounds(); let render = |renderer: &mut Renderer| { - renderer.draw( - self.handle.clone(), - Rectangle { - width: adjusted_fit.width, - height: adjusted_fit.height, - ..layout.bounds() - }, - ) + let offset = Vector::new( + (bounds.width - adjusted_fit.width).max(0.0) / 2.0, + (bounds.height - adjusted_fit.height).max(0.0) / 2.0, + ); + + let bounds = Rectangle { + width: adjusted_fit.width, + height: adjusted_fit.height, + ..layout.bounds() + }; + + renderer.draw(self.handle.clone(), bounds + offset) }; if adjusted_fit.width > bounds.width -- cgit From 83c0e0f7a862ddcefedfb4ef11a11f9bd5245605 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 17:59:39 +0700 Subject: Add `ContentFit` support to `Svg` widget --- native/src/widget/image.rs | 1 - native/src/widget/svg.rs | 83 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 17 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index a2e7f765..8ccc7856 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -120,7 +120,6 @@ where _cursor_position: Point, _viewport: &Rectangle, ) { - // The raw w/h of the underlying image let (width, height) = renderer.dimensions(&self.handle); let image_size = Size::new(width as f32, height as f32); diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index f212dfcb..9e3639db 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -2,7 +2,10 @@ use crate::layout; use crate::renderer; use crate::svg::{self, Handle}; -use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget}; +use crate::{ + ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, + Vector, Widget, +}; use std::hash::Hash; use std::path::PathBuf; @@ -18,6 +21,7 @@ pub struct Svg { handle: Handle, width: Length, height: Length, + content_fit: ContentFit, } impl Svg { @@ -27,6 +31,7 @@ impl Svg { handle: handle.into(), width: Length::Fill, height: Length::Shrink, + content_fit: ContentFit::Contain, } } @@ -47,6 +52,16 @@ impl Svg { self.height = height; self } + + /// Sets the [`ContentFit`] of the [`Svg`]. + /// + /// Defaults to [`ContentFit::Contain`] + pub fn content_fit(self, content_fit: ContentFit) -> Self { + Self { + content_fit, + ..self + } + } } impl Widget for Svg @@ -66,24 +81,32 @@ where renderer: &Renderer, limits: &layout::Limits, ) -> layout::Node { + // The raw w/h of the underlying image let (width, height) = renderer.dimensions(&self.handle); + let image_size = Size::new(width as f32, height as f32); - let aspect_ratio = width as f32 / height as f32; - - let mut size = limits + // The size to be available to the widget prior to `Shrink`ing + let raw_size = limits .width(self.width) .height(self.height) - .resolve(Size::new(width as f32, height as f32)); - - let viewport_aspect_ratio = size.width / size.height; - - if viewport_aspect_ratio > aspect_ratio { - size.width = width as f32 * size.height / height as f32; - } else { - size.height = height as f32 * size.width / width as f32; - } - - layout::Node::new(size) + .resolve(image_size); + + // The uncropped size of the image when fit to the bounds above + let full_size = self.content_fit.fit(image_size, raw_size); + + // Shrink the widget to fit the resized image, if requested + let final_size = Size { + width: match self.width { + Length::Shrink => f32::min(raw_size.width, full_size.width), + _ => raw_size.width, + }, + height: match self.height { + Length::Shrink => f32::min(raw_size.height, full_size.height), + _ => raw_size.height, + }, + }; + + layout::Node::new(final_size) } fn draw( @@ -94,7 +117,35 @@ where _cursor_position: Point, _viewport: &Rectangle, ) { - renderer.draw(self.handle.clone(), layout.bounds()) + let (width, height) = renderer.dimensions(&self.handle); + let image_size = Size::new(width as f32, height as f32); + + let adjusted_fit = + self.content_fit.fit(image_size, layout.bounds().size()); + let bounds = layout.bounds(); + + let render = |renderer: &mut Renderer| { + let offset = Vector::new( + (bounds.width - adjusted_fit.width).max(0.0) / 2.0, + (bounds.height - adjusted_fit.height).max(0.0) / 2.0, + ); + + let bounds = Rectangle { + width: adjusted_fit.width, + height: adjusted_fit.height, + ..layout.bounds() + }; + + renderer.draw(self.handle.clone(), bounds + offset) + }; + + if adjusted_fit.width > bounds.width + || adjusted_fit.height > bounds.height + { + renderer.with_layer(layout.bounds(), render); + } else { + render(renderer) + } } fn hash_layout(&self, state: &mut Hasher) { -- cgit From 8d94cd4c5c9e33965c24e59fd4710218e346be24 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 18:09:22 +0700 Subject: Remove redundant `layout.bounds()` calls in `Image` and `Svg` --- native/src/widget/image.rs | 11 +++++------ native/src/widget/svg.rs | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 8ccc7856..6aab76e4 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -123,9 +123,8 @@ where let (width, height) = renderer.dimensions(&self.handle); let image_size = Size::new(width as f32, height as f32); - let adjusted_fit = - self.content_fit.fit(image_size, layout.bounds().size()); let bounds = layout.bounds(); + let adjusted_fit = self.content_fit.fit(image_size, bounds.size()); let render = |renderer: &mut Renderer| { let offset = Vector::new( @@ -133,19 +132,19 @@ where (bounds.height - adjusted_fit.height).max(0.0) / 2.0, ); - let bounds = Rectangle { + let drawing_bounds = Rectangle { width: adjusted_fit.width, height: adjusted_fit.height, - ..layout.bounds() + ..bounds }; - renderer.draw(self.handle.clone(), bounds + offset) + renderer.draw(self.handle.clone(), drawing_bounds + offset) }; if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height { - renderer.with_layer(layout.bounds(), render); + renderer.with_layer(bounds, render); } else { render(renderer) } diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index 9e3639db..5ce8d25b 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -120,9 +120,8 @@ where let (width, height) = renderer.dimensions(&self.handle); let image_size = Size::new(width as f32, height as f32); - let adjusted_fit = - self.content_fit.fit(image_size, layout.bounds().size()); let bounds = layout.bounds(); + let adjusted_fit = self.content_fit.fit(image_size, bounds.size()); let render = |renderer: &mut Renderer| { let offset = Vector::new( @@ -130,19 +129,19 @@ where (bounds.height - adjusted_fit.height).max(0.0) / 2.0, ); - let bounds = Rectangle { + let drawing_bounds = Rectangle { width: adjusted_fit.width, height: adjusted_fit.height, - ..layout.bounds() + ..bounds }; - renderer.draw(self.handle.clone(), bounds + offset) + renderer.draw(self.handle.clone(), drawing_bounds + offset) }; if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height { - renderer.with_layer(layout.bounds(), render); + renderer.with_layer(bounds, render); } else { render(renderer) } -- cgit From 15b4bbd49dfb4f70e1e73699958a764c0568b452 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 16 Feb 2022 18:16:09 +0700 Subject: Hash `content_fit` in `hash_layout` of `Image` and `Svg` --- native/src/widget/image.rs | 1 + native/src/widget/svg.rs | 1 + 2 files changed, 2 insertions(+) (limited to 'native/src/widget') diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 6aab76e4..83c24ee5 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -157,6 +157,7 @@ where self.handle.hash(state); self.width.hash(state); self.height.hash(state); + self.content_fit.hash(state); } } diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index 5ce8d25b..22aac331 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -153,6 +153,7 @@ where self.handle.hash(state); self.width.hash(state); self.height.hash(state); + self.content_fit.hash(state); } } -- cgit From 1313c94e3bb206f064462bc521f78dbffc2a6cd6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 22 Feb 2022 14:10:49 +0700 Subject: Remove `hash_layout` method from `Widget` trait --- native/src/widget/button.rs | 14 ++------------ native/src/widget/checkbox.rs | 13 ++----------- native/src/widget/column.rs | 23 ++--------------------- native/src/widget/container.rs | 21 ++------------------- native/src/widget/image.rs | 13 +------------ native/src/widget/image/viewer.rs | 15 ++------------- native/src/widget/pane_grid.rs | 19 ++----------------- native/src/widget/pane_grid/content.rs | 12 +----------- native/src/widget/pane_grid/state.rs | 8 +------- native/src/widget/pane_grid/title_bar.rs | 13 +------------ native/src/widget/pick_list.rs | 22 ++-------------------- native/src/widget/progress_bar.rs | 14 ++------------ native/src/widget/radio.rs | 13 ++----------- native/src/widget/row.rs | 22 ++-------------------- native/src/widget/rule.rs | 14 +------------- native/src/widget/scrollable.rs | 16 +++------------- native/src/widget/slider.rs | 12 ++---------- native/src/widget/space.rs | 11 +---------- native/src/widget/svg.rs | 13 +------------ native/src/widget/text.rs | 16 +--------------- native/src/widget/text_input.rs | 15 ++------------- native/src/widget/toggler.rs | 12 ++---------- native/src/widget/tooltip.rs | 15 ++------------- 23 files changed, 39 insertions(+), 307 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs index b4a3adc3..57fdd7d4 100644 --- a/native/src/widget/button.rs +++ b/native/src/widget/button.rs @@ -8,12 +8,10 @@ use crate::overlay; use crate::renderer; use crate::touch; use crate::{ - Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding, - Point, Rectangle, Shell, Vector, Widget, + Background, Clipboard, Color, Element, Layout, Length, Padding, Point, + Rectangle, Shell, Vector, Widget, }; -use std::hash::Hash; - pub use iced_style::button::{Style, StyleSheet}; /// 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::().hash(state); - - self.width.hash(state); - self.content.hash_layout(state); - } - fn overlay( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index fff65a40..15cbf93a 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -1,6 +1,4 @@ //! Show toggle controls using checkboxes. -use std::hash::Hash; - use crate::alignment; use crate::event::{self, Event}; use crate::layout; @@ -10,8 +8,8 @@ use crate::text; use crate::touch; use crate::widget::{self, Row, Text}; use crate::{ - Alignment, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, - Shell, Widget, + Alignment, Clipboard, Element, Layout, Length, Point, Rectangle, Shell, + Widget, }; 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::().hash(state); - - self.label.hash(state); - } } impl<'a, Message, Renderer> From> diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 66ed5e23..f161d1f2 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -1,14 +1,12 @@ //! Distribute content vertically. -use std::hash::Hash; - use crate::event::{self, Event}; use crate::layout; use crate::mouse; use crate::overlay; use crate::renderer; use crate::{ - Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point, - Rectangle, Shell, Widget, + Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle, + Shell, Widget, }; use std::u32; @@ -199,23 +197,6 @@ where } } - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().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( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index 4444732a..ca85a425 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -1,6 +1,4 @@ //! Decorate content and apply alignment. -use std::hash::Hash; - use crate::alignment::{self, Alignment}; use crate::event::{self, Event}; use crate::layout; @@ -8,8 +6,8 @@ use crate::mouse; use crate::overlay; use crate::renderer; use crate::{ - Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding, - Point, Rectangle, Shell, Widget, + Background, Clipboard, Color, Element, Layout, Length, Padding, Point, + Rectangle, Shell, Widget, }; use std::u32; @@ -219,21 +217,6 @@ where ); } - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().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( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs index 83c24ee5..de0ffbc0 100644 --- a/native/src/widget/image.rs +++ b/native/src/widget/image.rs @@ -6,8 +6,7 @@ use crate::image; use crate::layout; use crate::renderer; use crate::{ - ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, - Vector, Widget, + ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, }; use std::hash::Hash; @@ -149,16 +148,6 @@ where render(renderer) } } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().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> diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs index 486d5fa5..840b88e5 100644 --- a/native/src/widget/image/viewer.rs +++ b/native/src/widget/image/viewer.rs @@ -5,8 +5,8 @@ use crate::layout; use crate::mouse; use crate::renderer; use crate::{ - Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Shell, Size, - Vector, Widget, + Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector, + Widget, }; use std::hash::Hash; @@ -335,17 +335,6 @@ where }); }); } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.width.hash(state); - self.height.hash(state); - self.padding.hash(state); - - self.handle.hash(state); - } } /// The local state of a [`Viewer`]. diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 5f293fa6..8ad63cf1 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -34,8 +34,8 @@ use crate::overlay; use crate::renderer; use crate::touch; use crate::{ - Clipboard, Color, Element, Hasher, Layout, Length, Point, Rectangle, Shell, - Size, Vector, Widget, + Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size, + Vector, Widget, }; 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::().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( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 6d12aa2d..8b0e8d2a 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -5,9 +5,7 @@ use crate::overlay; use crate::renderer; use crate::widget::container; use crate::widget::pane_grid::TitleBar; -use crate::{ - Clipboard, Element, Hasher, Layout, Point, Rectangle, Shell, Size, -}; +use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; /// The content of a [`Pane`]. /// @@ -236,14 +234,6 @@ where .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( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index bcc724a8..feea0dec 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -1,7 +1,7 @@ use crate::widget::pane_grid::{ Axis, Configuration, Direction, Node, Pane, Split, }; -use crate::{Hasher, Point, Rectangle, Size}; +use crate::{Point, Rectangle, Size}; use std::collections::{BTreeMap, HashMap}; @@ -292,10 +292,4 @@ impl Internal { pub fn idle(&mut self) { self.action = Action::Idle; } - - pub fn hash_layout(&self, hasher: &mut Hasher) { - use std::hash::Hash; - - self.layout.hash(hasher); - } } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index ea9ebfc4..d56972ec 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -5,7 +5,7 @@ use crate::overlay; use crate::renderer; use crate::widget::container; 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`]. @@ -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( &self, renderer: &Renderer, diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index a200fb13..3be6c20c 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -10,8 +10,8 @@ use crate::renderer; use crate::text::{self, Text}; use crate::touch; use crate::{ - Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle, - Shell, Size, Widget, + Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Size, + Widget, }; use std::borrow::Cow; @@ -220,24 +220,6 @@ where 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( &mut self, event: Event, diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index 69eb8c09..c26c38fa 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -1,11 +1,9 @@ //! Provide progress feedback to your users. use crate::layout; use crate::renderer; -use crate::{ - Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, -}; +use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget}; -use std::{hash::Hash, ops::RangeInclusive}; +use std::ops::RangeInclusive; 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::().hash(state); - - self.width.hash(state); - self.height.hash(state); - } } impl<'a, Message, Renderer> From> diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs index c4992764..fed2925b 100644 --- a/native/src/widget/radio.rs +++ b/native/src/widget/radio.rs @@ -1,6 +1,4 @@ //! Create choices using radio buttons. -use std::hash::Hash; - use crate::alignment; use crate::event::{self, Event}; use crate::layout; @@ -10,8 +8,8 @@ use crate::text; use crate::touch; use crate::widget::{self, Row, Text}; use crate::{ - Alignment, Clipboard, Color, Element, Hasher, Layout, Length, Point, - Rectangle, Shell, Widget, + Alignment, Clipboard, Color, Element, Layout, Length, Point, Rectangle, + Shell, Widget, }; 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::().hash(state); - - self.label.hash(state); - } } impl<'a, Message, Renderer> From> diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index c423d31f..e34befb2 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -5,11 +5,10 @@ use crate::mouse; use crate::overlay; use crate::renderer; use crate::{ - Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point, - Rectangle, Shell, Widget, + Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle, + Shell, Widget, }; -use std::hash::Hash; use std::u32; /// 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::().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( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs index 7c8c5dbc..b0cc3768 100644 --- a/native/src/widget/rule.rs +++ b/native/src/widget/rule.rs @@ -1,11 +1,7 @@ //! Display a horizontal or vertical rule for dividing content. use crate::layout; use crate::renderer; -use crate::{ - Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, -}; - -use std::hash::Hash; +use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget}; pub use iced_style::rule::{FillMode, Style, StyleSheet}; @@ -122,14 +118,6 @@ where style.color, ); } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.width.hash(state); - self.height.hash(state); - } } impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 4b005c6b..ce734ad8 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -7,11 +7,11 @@ use crate::renderer; use crate::touch; use crate::widget::Column; use crate::{ - Alignment, Background, Clipboard, Color, Element, Hasher, Layout, Length, - Padding, Point, Rectangle, Shell, Size, Vector, Widget, + Alignment, Background, Clipboard, Color, Element, Layout, Length, Padding, + Point, Rectangle, Shell, Size, Vector, Widget, }; -use std::{f32, hash::Hash, u32}; +use std::{f32, u32}; pub use iced_style::scrollable::StyleSheet; @@ -570,16 +570,6 @@ where } } - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.height.hash(state); - self.max_height.hash(state); - - self.content.hash_layout(state) - } - fn overlay( &mut self, layout: Layout<'_>, diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index 917bfc14..289f75f5 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -7,11 +7,10 @@ use crate::mouse; use crate::renderer; use crate::touch; use crate::{ - Background, Clipboard, Color, Element, Hasher, Layout, Length, Point, - Rectangle, Shell, Size, Widget, + Background, Clipboard, Color, Element, Layout, Length, Point, Rectangle, + Shell, Size, Widget, }; -use std::hash::Hash; use std::ops::RangeInclusive; pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet}; @@ -374,13 +373,6 @@ where mouse::Interaction::default() } } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.width.hash(state); - } } impl<'a, T, Message, Renderer> From> diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs index 3373f3b7..4135d1b8 100644 --- a/native/src/widget/space.rs +++ b/native/src/widget/space.rs @@ -1,9 +1,7 @@ //! Distribute content vertically. use crate::layout; use crate::renderer; -use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget}; - -use std::hash::Hash; +use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget}; /// An amount of empty space. /// @@ -68,13 +66,6 @@ where _viewport: &Rectangle, ) { } - - fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::().hash(state); - - self.width.hash(state); - self.height.hash(state); - } } impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs index 22aac331..008ab356 100644 --- a/native/src/widget/svg.rs +++ b/native/src/widget/svg.rs @@ -3,11 +3,9 @@ use crate::layout; use crate::renderer; use crate::svg::{self, Handle}; use crate::{ - ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, - Vector, Widget, + ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget, }; -use std::hash::Hash; use std::path::PathBuf; /// A vector graphics image. @@ -146,15 +144,6 @@ where render(renderer) } } - - fn hash_layout(&self, state: &mut Hasher) { - std::any::TypeId::of::().hash(state); - - self.handle.hash(state); - self.width.hash(state); - self.height.hash(state); - self.content_fit.hash(state); - } } impl<'a, Message, Renderer> From for Element<'a, Message, Renderer> diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs index f0b29d15..6f00c9c8 100644 --- a/native/src/widget/text.rs +++ b/native/src/widget/text.rs @@ -3,11 +3,7 @@ use crate::alignment; use crate::layout; use crate::renderer; use crate::text; -use crate::{ - Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget, -}; - -use std::hash::Hash; +use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget}; /// A paragraph of text. /// @@ -151,16 +147,6 @@ where self.vertical_alignment, ); } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().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. diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 03adeb12..e30e2343 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -20,8 +20,8 @@ use crate::renderer; use crate::text::{self, Text}; use crate::touch; use crate::{ - Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point, - Rectangle, Shell, Size, Vector, Widget, + Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle, + Shell, Size, Vector, Widget, }; use std::u32; @@ -783,17 +783,6 @@ where ) { self.draw(renderer, layout, cursor_position, None) } - - fn hash_layout(&self, state: &mut Hasher) { - use std::{any::TypeId, hash::Hash}; - struct Marker; - TypeId::of::().hash(state); - - self.width.hash(state); - self.max_width.hash(state); - self.padding.hash(state); - self.size.hash(state); - } } impl<'a, Message, Renderer> From> diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs index 002e0a4f..48237edb 100644 --- a/native/src/widget/toggler.rs +++ b/native/src/widget/toggler.rs @@ -1,5 +1,4 @@ //! Show toggle controls using togglers. -use std::hash::Hash; use crate::alignment; use crate::event; @@ -9,8 +8,8 @@ use crate::renderer; use crate::text; use crate::widget::{Row, Text}; use crate::{ - Alignment, Clipboard, Element, Event, Hasher, Layout, Length, Point, - Rectangle, Shell, Widget, + Alignment, Clipboard, Element, Event, Layout, Length, Point, Rectangle, + Shell, Widget, }; pub use iced_style::toggler::{Style, StyleSheet}; @@ -295,13 +294,6 @@ where style.foreground, ); } - - fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.label.hash(state) - } } impl<'a, Message, Renderer> From> diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs index f6630864..7989c768 100644 --- a/native/src/widget/tooltip.rs +++ b/native/src/widget/tooltip.rs @@ -1,8 +1,4 @@ //! Display a widget over another. -use std::hash::Hash; - -use iced_core::Rectangle; - use crate::event; use crate::layout; use crate::mouse; @@ -11,8 +7,8 @@ use crate::text; use crate::widget::container; use crate::widget::text::Text; use crate::{ - Clipboard, Element, Event, Hasher, Layout, Length, Padding, Point, Shell, - Size, Vector, Widget, + Clipboard, Element, Event, Layout, Length, Padding, Point, Rectangle, + Shell, Size, Vector, Widget, }; /// 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::().hash(state); - - self.content.hash_layout(state); - } } impl<'a, Message, Renderer> From> -- cgit