From 0655a20ad119e2e9790afcc45039fd4ac0e7d432 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 16 Mar 2023 20:23:25 +0100 Subject: Make `Shrink` have priority over `Fill` in layout --- widget/src/button.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'widget/src/button.rs') diff --git a/widget/src/button.rs b/widget/src/button.rs index 384a3156..ba68caa5 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -433,13 +433,18 @@ pub fn layout( ) -> layout::Node { let limits = limits.width(width).height(height); - let mut content = layout_content(&limits.pad(padding)); + let content = layout_content(&limits.shrink(padding)); let padding = padding.fit(content.size(), limits.max()); - let size = limits.pad(padding).resolve(content.size()).pad(padding); - content.move_to(Point::new(padding.left, padding.top)); + let size = limits + .shrink(padding) + .resolve(content.size(), width, height) + .expand(padding); - layout::Node::with_children(size, vec![content]) + layout::Node::with_children( + size, + vec![content.move_to(Point::new(padding.left, padding.top))], + ) } /// Returns the [`mouse::Interaction`] of a [`Button`]. -- cgit 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 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'widget/src/button.rs') 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( -- cgit From d62bb8193c1c43f565fcc5c52293d564c91e215d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Jan 2024 06:35:33 +0100 Subject: Introduce useful helpers in `layout` module --- widget/src/button.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'widget/src/button.rs') diff --git a/widget/src/button.rs b/widget/src/button.rs index 1ce4f662..86abee77 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -10,8 +10,8 @@ use crate::core::touch; 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, Size, Vector, Widget, + Background, Clipboard, Color, Element, Layout, Length, Padding, Rectangle, + Shell, Size, Vector, Widget, }; pub use iced_style::button::{Appearance, StyleSheet}; @@ -430,20 +430,7 @@ pub fn layout( padding: Padding, layout_content: impl FnOnce(&layout::Limits) -> layout::Node, ) -> layout::Node { - let limits = limits.width(width).height(height); - - let content = layout_content(&limits.shrink(padding)); - let padding = padding.fit(content.size(), limits.max()); - - let size = limits - .shrink(padding) - .resolve(content.size(), width, height) - .expand(padding); - - layout::Node::with_children( - size, - vec![content.move_to(Point::new(padding.left, padding.top))], - ) + layout::padded(limits, width, height, padding, layout_content) } /// Returns the [`mouse::Interaction`] of a [`Button`]. -- cgit From 03c901d49b7cce901cfd76100f08dcff31420af8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 Jan 2024 06:12:19 +0100 Subject: Make `Button` sizing strategy adaptive --- widget/src/button.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'widget/src/button.rs') diff --git a/widget/src/button.rs b/widget/src/button.rs index 86abee77..0ebb8dcc 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -71,11 +71,14 @@ where { /// Creates a new [`Button`] with the given content. pub fn new(content: impl Into>) -> Self { + let content = content.into(); + let size = content.as_widget().size_hint(); + Button { - content: content.into(), + content, on_press: None, - width: Length::Shrink, - height: Length::Shrink, + width: size.width.fluid(), + height: size.height.fluid(), padding: Padding::new(5.0), style: ::Style::default(), } -- cgit