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:
Héctor Ramón Jiménez 2024-02-21 08:24:08 +01:00
parent 5ba818a13a
commit cd2130a69a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 25 additions and 5 deletions

View file

@ -48,7 +48,7 @@ impl Sandbox for Component {
mod numeric_input {
use iced::alignment::{self, Alignment};
use iced::widget::{button, component, row, text, text_input, Component};
use iced::{Element, Length};
use iced::{Element, Length, Size};
pub struct NumericInput<Message> {
value: Option<u32>,
@ -143,6 +143,13 @@ mod numeric_input {
.spacing(10)
.into()
}
fn size_hint(&self) -> Size<Length> {
Size {
width: Length::Fill,
height: Length::Shrink,
}
}
}
impl<'a, Message> From<NumericInput<Message>> for Element<'a, Message>