From d278bfd21d0399009e652560afb9a4d185e92637 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Jan 2024 17:46:33 +0100 Subject: Replace `width` and `height` with `Widget::size` --- widget/src/button.rs | 13 ++++++------- widget/src/canvas.rs | 16 ++++++++-------- widget/src/checkbox.rs | 11 +++++------ widget/src/column.rs | 13 ++++++------- widget/src/combo_box.rs | 12 +++++------- widget/src/container.rs | 11 +++++------ widget/src/image.rs | 11 +++++------ widget/src/image/viewer.rs | 11 +++++------ widget/src/keyed/column.rs | 13 ++++++------- widget/src/lazy.rs | 8 ++------ widget/src/lazy/component.rs | 8 ++------ widget/src/lazy/responsive.rs | 11 +++++------ widget/src/mouse_area.rs | 10 +++------- widget/src/overlay/menu.rs | 11 +++++------ widget/src/pane_grid.rs | 11 +++++------ widget/src/pick_list.rs | 11 +++++------ widget/src/progress_bar.rs | 11 +++++------ widget/src/qr_code.rs | 11 +++++------ widget/src/radio.rs | 11 +++++------ widget/src/row.rs | 13 ++++++------- widget/src/rule.rs | 11 +++++------ widget/src/scrollable.rs | 11 +++++------ widget/src/shader.rs | 11 +++++------ widget/src/slider.rs | 11 +++++------ widget/src/space.rs | 11 +++++------ widget/src/svg.rs | 11 +++++------ widget/src/text_editor.rs | 13 ++++++------- widget/src/text_input.rs | 11 +++++------ widget/src/toggler.rs | 11 +++++------ widget/src/tooltip.rs | 8 ++------ widget/src/vertical_slider.rs | 11 +++++------ 31 files changed, 152 insertions(+), 195 deletions(-) (limited to 'widget') diff --git a/widget/src/button.rs b/widget/src/button.rs index ba68caa5..1ce4f662 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -11,7 +11,7 @@ use crate::core::widget::tree::{self, Tree}; use crate::core::widget::Operation; use crate::core::{ Background, Clipboard, Color, Element, Layout, Length, Padding, Point, - Rectangle, Shell, Vector, Widget, + Rectangle, Shell, Size, Vector, Widget, }; pub use iced_style::button::{Appearance, StyleSheet}; @@ -149,12 +149,11 @@ where tree.diff_children(std::slice::from_ref(&self.content)); } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/canvas.rs b/widget/src/canvas.rs index 9e33c113..2bf09eec 100644 --- a/widget/src/canvas.rs +++ b/widget/src/canvas.rs @@ -14,8 +14,9 @@ use crate::core::layout::{self, Layout}; use crate::core::mouse; use crate::core::renderer; use crate::core::widget::tree::{self, Tree}; -use crate::core::{Clipboard, Element, Shell, Widget}; -use crate::core::{Length, Rectangle, Size, Vector}; +use crate::core::{ + Clipboard, Element, Length, Rectangle, Shell, Size, Vector, Widget, +}; use crate::graphics::geometry; use std::marker::PhantomData; @@ -119,12 +120,11 @@ where tree::State::new(P::State::default()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index a0d9559b..0353b3ad 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -174,12 +174,11 @@ where tree::State::new(widget::text::State::::default()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/column.rs b/widget/src/column.rs index 52cf35ce..9867d97e 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -7,7 +7,7 @@ use crate::core::renderer; use crate::core::widget::{Operation, Tree}; use crate::core::{ Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, - Shell, Widget, + Shell, Size, Widget, }; /// A container that distributes its contents vertically. @@ -129,12 +129,11 @@ where tree.diff_children(&self.children); } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 31ec27fc..1b2fa947 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -8,7 +8,9 @@ use crate::core::renderer; use crate::core::text; use crate::core::time::Instant; use crate::core::widget::{self, Widget}; -use crate::core::{Clipboard, Element, Length, Padding, Rectangle, Shell}; +use crate::core::{ + Clipboard, Element, Length, Padding, Rectangle, Shell, Size, +}; use crate::overlay::menu; use crate::text::LineHeight; use crate::{container, scrollable, text_input, TextInput}; @@ -297,12 +299,8 @@ where + scrollable::StyleSheet + menu::StyleSheet, { - fn width(&self) -> Length { - Widget::::width(&self.text_input) - } - - fn height(&self) -> Length { - Widget::::height(&self.text_input) + fn size(&self) -> Size { + Widget::::size(&self.text_input) } fn layout( diff --git a/widget/src/container.rs b/widget/src/container.rs index fbc68db7..93d8daba 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -163,12 +163,11 @@ where self.content.as_widget().diff(tree); } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/image.rs b/widget/src/image.rs index b5f1e907..6750c1b3 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -164,12 +164,11 @@ where Renderer: image::Renderer, Handle: Clone + Hash, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 23c4fe86..dc910f1f 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -97,12 +97,11 @@ where tree::State::new(State::new()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs index 1b53b43a..32320300 100644 --- a/widget/src/keyed/column.rs +++ b/widget/src/keyed/column.rs @@ -8,7 +8,7 @@ use crate::core::widget::tree::{self, Tree}; use crate::core::widget::Operation; use crate::core::{ Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, - Shell, Widget, + Shell, Size, Widget, }; /// A container that distributes its contents vertically. @@ -173,12 +173,11 @@ where } } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs index 4f6513db..e9edbb4c 100644 --- a/widget/src/lazy.rs +++ b/widget/src/lazy.rs @@ -142,12 +142,8 @@ where } } - fn width(&self) -> Length { - self.with_element(|element| element.as_widget().width()) - } - - fn height(&self) -> Length { - self.with_element(|element| element.as_widget().height()) + fn size(&self) -> Size { + self.with_element(|element| element.as_widget().size()) } fn size_hint(&self) -> Size { diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index 0aff7485..3684e0c9 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -244,12 +244,8 @@ where self.rebuild_element_if_necessary(); } - fn width(&self) -> Length { - self.with_element(|element| element.as_widget().width()) - } - - fn height(&self) -> Length { - self.with_element(|element| element.as_widget().height()) + fn size(&self) -> Size { + self.with_element(|element| element.as_widget().size()) } fn size_hint(&self) -> Size { diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs index 86d37b6c..1df0866f 100644 --- a/widget/src/lazy/responsive.rs +++ b/widget/src/lazy/responsive.rs @@ -135,12 +135,11 @@ where }) } - fn width(&self) -> Length { - Length::Fill - } - - fn height(&self) -> Length { - Length::Fill + fn size(&self) -> Size { + Size { + width: Length::Fill, + height: Length::Fill, + } } fn layout( diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index 3a5b01a3..87cac3a7 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -8,7 +8,7 @@ use crate::core::renderer; use crate::core::touch; use crate::core::widget::{tree, Operation, Tree}; use crate::core::{ - Clipboard, Element, Layout, Length, Rectangle, Shell, Widget, + Clipboard, Element, Layout, Length, Rectangle, Shell, Size, Widget, }; /// Emit messages on mouse events. @@ -110,12 +110,8 @@ where tree.diff_children(std::slice::from_ref(&self.content)); } - fn width(&self) -> Length { - self.content.as_widget().width() - } - - fn height(&self) -> Length { - self.content.as_widget().height() + fn size(&self) -> Size { + self.content.as_widget().size() } fn layout( diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index ef39a952..b9e06de8 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -342,12 +342,11 @@ where Renderer: text::Renderer, Renderer::Theme: StyleSheet, { - fn width(&self) -> Length { - Length::Fill - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: Length::Fill, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 3d799fd3..36c785b7 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -265,12 +265,11 @@ where } } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 13110725..d83b0624 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -164,12 +164,11 @@ where tree::State::new(State::::new()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/progress_bar.rs b/widget/src/progress_bar.rs index b84ab2dd..a05923a2 100644 --- a/widget/src/progress_bar.rs +++ b/widget/src/progress_bar.rs @@ -85,12 +85,11 @@ where Renderer: crate::core::Renderer, Renderer::Theme: StyleSheet, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT)) + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height.unwrap_or(Length::Fixed(Self::DEFAULT_HEIGHT)), + } } fn layout( diff --git a/widget/src/qr_code.rs b/widget/src/qr_code.rs index 1dc4da7f..a229eb59 100644 --- a/widget/src/qr_code.rs +++ b/widget/src/qr_code.rs @@ -50,12 +50,11 @@ impl<'a> QRCode<'a> { } impl<'a, Message, Theme> Widget> for QRCode<'a> { - fn width(&self) -> Length { - Length::Shrink - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: Length::Shrink, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/radio.rs b/widget/src/radio.rs index ae2365dd..f91b20b1 100644 --- a/widget/src/radio.rs +++ b/widget/src/radio.rs @@ -201,12 +201,11 @@ where tree::State::new(widget::text::State::::default()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/row.rs b/widget/src/row.rs index ef371ddb..bcbe9267 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -7,7 +7,7 @@ use crate::core::renderer; use crate::core::widget::{Operation, Tree}; use crate::core::{ Alignment, Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, - Widget, + Size, Widget, }; /// A container that distributes its contents horizontally. @@ -123,12 +123,11 @@ where tree.diff_children(&self.children); } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/rule.rs b/widget/src/rule.rs index ecaedf60..4ab16c40 100644 --- a/widget/src/rule.rs +++ b/widget/src/rule.rs @@ -62,12 +62,11 @@ where Renderer: crate::core::Renderer, Renderer::Theme: StyleSheet, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 525463c4..5197afde 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -220,12 +220,11 @@ where tree.diff_children(std::slice::from_ref(&self.content)); } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/shader.rs b/widget/src/shader.rs index 5b18ec7d..82432c6c 100644 --- a/widget/src/shader.rs +++ b/widget/src/shader.rs @@ -70,12 +70,11 @@ where tree::State::new(P::State::default()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/slider.rs b/widget/src/slider.rs index 2b600d9d..27588852 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -159,12 +159,11 @@ where tree::State::new(State::new()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/space.rs b/widget/src/space.rs index afa9a7c8..9fd4dcb9 100644 --- a/widget/src/space.rs +++ b/widget/src/space.rs @@ -45,12 +45,11 @@ impl Widget for Space where Renderer: core::Renderer, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 8367ad18..75ab238a 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -96,12 +96,11 @@ where Renderer: svg::Renderer, Renderer::Theme: iced_style::svg::StyleSheet, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 214bce17..9118d124 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -9,7 +9,7 @@ use crate::core::text::highlighter::{self, Highlighter}; use crate::core::text::{self, LineHeight}; use crate::core::widget::{self, Widget}; use crate::core::{ - Clipboard, Color, Element, Length, Padding, Pixels, Rectangle, Shell, + Clipboard, Color, Element, Length, Padding, Pixels, Rectangle, Shell, Size, Vector, }; @@ -316,12 +316,11 @@ where }) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 03eb2fd0..7e91105c 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -283,12 +283,11 @@ where } } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index d8723080..941159ea 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -168,12 +168,11 @@ where tree::State::new(widget::text::State::::default()) } - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - Length::Shrink + fn size(&self) -> Size { + Size { + width: self.width, + height: Length::Shrink, + } } fn layout( diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index adef13e4..d09a9255 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -131,12 +131,8 @@ where widget::tree::Tag::of::() } - fn width(&self) -> Length { - self.content.as_widget().width() - } - - fn height(&self) -> Length { - self.content.as_widget().height() + fn size(&self) -> Size { + self.content.as_widget().size() } fn layout( diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index e489104c..35bc2fe2 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -156,12 +156,11 @@ where tree::State::new(State::new()) } - fn width(&self) -> Length { - Length::Shrink - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: Length::Shrink, + height: self.height, + } } fn layout( -- cgit