Merge pull request #2275 from iced-rs/component-size-hint
`size_hint` method for `Component` trait
This commit is contained in:
commit
56ac21cacb
3 changed files with 26 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- `clipboard` module in `advanced` module. [#2272](https://github.com/iced-rs/iced/pull/2272)
|
- `clipboard` module in `advanced` module. [#2272](https://github.com/iced-rs/iced/pull/2272)
|
||||||
- Default `disabled` style for `checkbox` and `hovered` style for `Svg`. [#2273](https://github.com/iced-rs/iced/pull/2273)
|
- Default `disabled` style for `checkbox` and `hovered` style for `Svg`. [#2273](https://github.com/iced-rs/iced/pull/2273)
|
||||||
- `From<u16>` and `From<i32>` implementations for `border::Radius`. [#2274](https://github.com/iced-rs/iced/pull/2274)
|
- `From<u16>` and `From<i32>` implementations for `border::Radius`. [#2274](https://github.com/iced-rs/iced/pull/2274)
|
||||||
|
- `size_hint` method for `Component` trait. [#2275](https://github.com/iced-rs/iced/pull/2275)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
|
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Sandbox for Component {
|
||||||
mod numeric_input {
|
mod numeric_input {
|
||||||
use iced::alignment::{self, Alignment};
|
use iced::alignment::{self, Alignment};
|
||||||
use iced::widget::{button, component, row, text, text_input, Component};
|
use iced::widget::{button, component, row, text, text_input, Component};
|
||||||
use iced::{Element, Length};
|
use iced::{Element, Length, Size};
|
||||||
|
|
||||||
pub struct NumericInput<Message> {
|
pub struct NumericInput<Message> {
|
||||||
value: Option<u32>,
|
value: Option<u32>,
|
||||||
|
|
@ -143,6 +143,13 @@ mod numeric_input {
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> Size<Length> {
|
||||||
|
Size {
|
||||||
|
width: Length::Fill,
|
||||||
|
height: Length::Shrink,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message> From<NumericInput<Message>> for Element<'a, Message>
|
impl<'a, Message> From<NumericInput<Message>> for Element<'a, Message>
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,17 @@ pub trait Component<Message, Theme = crate::Theme, Renderer = crate::Renderer> {
|
||||||
_operation: &mut dyn widget::Operation<Message>,
|
_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);
|
struct Tag<T>(T);
|
||||||
|
|
@ -255,10 +266,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> Size<Length> {
|
fn size_hint(&self) -> Size<Length> {
|
||||||
Size {
|
self.state
|
||||||
width: Length::Shrink,
|
.borrow()
|
||||||
height: Length::Shrink,
|
.as_ref()
|
||||||
}
|
.expect("Borrow instance state")
|
||||||
|
.borrow_component()
|
||||||
|
.size_hint()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout(
|
fn layout(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue