summaryrefslogtreecommitdiffstats
path: root/widget/src/lazy
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-02-21 08:43:27 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-21 08:43:27 +0100
commit56ac21cacbead255c6ae574ed2b7ba2895018c56 (patch)
tree89d146cb74335c4f479d5f2cd013930af47f9c37 /widget/src/lazy
parent5ba818a13aa99aa6bf00e360f68140b6df2d270f (diff)
parent28f0eccd8164985ea6a72b976b7b09ae81fb76ac (diff)
downloadiced-56ac21cacbead255c6ae574ed2b7ba2895018c56.tar.gz
iced-56ac21cacbead255c6ae574ed2b7ba2895018c56.tar.bz2
iced-56ac21cacbead255c6ae574ed2b7ba2895018c56.zip
Merge pull request #2275 from iced-rs/component-size-hint
`size_hint` method for `Component` trait
Diffstat (limited to 'widget/src/lazy')
-rw-r--r--widget/src/lazy/component.rs21
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(