summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-21 08:24:08 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-21 08:24:08 +0100
commitcd2130a69a6f0089f8fda378e19ade0de330ed56 (patch)
treeb7b11f45857161087217668a91b2c47b15fe0309 /examples
parent5ba818a13aa99aa6bf00e360f68140b6df2d270f (diff)
downloadiced-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 'examples')
-rw-r--r--examples/component/src/main.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/examples/component/src/main.rs b/examples/component/src/main.rs
index 81be4d7f..4670824d 100644
--- a/examples/component/src/main.rs
+++ b/examples/component/src/main.rs
@@ -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>