diff options
author | 2024-02-21 08:24:08 +0100 | |
---|---|---|
committer | 2024-02-21 08:24:08 +0100 | |
commit | cd2130a69a6f0089f8fda378e19ade0de330ed56 (patch) | |
tree | b7b11f45857161087217668a91b2c47b15fe0309 /widget | |
parent | 5ba818a13aa99aa6bf00e360f68140b6df2d270f (diff) | |
download | iced-cd2130a69a6f0089f8fda378e19ade0de330ed56.tar.gz iced-cd2130a69a6f0089f8fda378e19ade0de330ed56.tar.bz2 iced-cd2130a69a6f0089f8fda378e19ade0de330ed56.zip |
Add `size_hint` method to `Component` trait
This can be used to aid the sizing strategy of
some containers directly in the component definition,
instead of stating the sizes explicitly in `view`
logic.
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/lazy/component.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index edecbdaa..a512e0de 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -62,6 +62,17 @@ pub trait Component<Message, Theme = crate::Theme, Renderer = crate::Renderer> { _operation: &mut dyn widget::Operation<Message>, ) { } + + /// Returns a [`Size`] hint for laying out the [`Component`]. + /// + /// This hint may be used by some widget containers to adjust their sizing strategy + /// during construction. + fn size_hint(&self) -> Size<Length> { + Size { + width: Length::Shrink, + height: Length::Shrink, + } + } } struct Tag<T>(T); @@ -255,10 +266,12 @@ where } fn size_hint(&self) -> Size<Length> { - Size { - width: Length::Shrink, - height: Length::Shrink, - } + self.state + .borrow() + .as_ref() + .expect("Borrow instance state") + .borrow_component() + .size_hint() } fn layout( |