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.
This commit is contained in:
parent
5ba818a13a
commit
cd2130a69a
2 changed files with 25 additions and 5 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue