Merge pull request #2264 from iced-rs/column-row-ergonomics
`extend` and `from_vec` methods for `Column` and `Row`
This commit is contained in:
commit
e77a6add8a
3 changed files with 70 additions and 22 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
|
@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `extend` and `from_vec` methods for `Column` and `Row`. [#2264](https://github.com/iced-rs/iced/pull/2264)
|
||||
|
||||
### Fixed
|
||||
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
|
||||
|
||||
Many thanks to...
|
||||
|
||||
- @PolyMeilex
|
||||
|
||||
## [0.12.0] - 2024-02-15
|
||||
### Added
|
||||
|
|
@ -116,8 +125,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Alpha mode misconfiguration in `iced_wgpu`. [#2231](https://github.com/iced-rs/iced/pull/2231)
|
||||
- Outdated documentation leading to a dead link. [#2232](https://github.com/iced-rs/iced/pull/2232)
|
||||
|
||||
## Patched
|
||||
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
|
||||
|
||||
Many thanks to...
|
||||
|
||||
|
|
@ -159,7 +166,6 @@ Many thanks to...
|
|||
- @nicksenger
|
||||
- @Nisatru
|
||||
- @nyurik
|
||||
- @PolyMeilex
|
||||
- @Remmirad
|
||||
- @ripytide
|
||||
- @snaggen
|
||||
|
|
|
|||
|
|
@ -30,7 +30,27 @@ where
|
|||
{
|
||||
/// Creates an empty [`Column`].
|
||||
pub fn new() -> Self {
|
||||
Column {
|
||||
Self::from_vec(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] with the given elements.
|
||||
pub fn with_children(
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
Self::new().extend(children)
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] from an already allocated [`Vec`].
|
||||
///
|
||||
/// Keep in mind that the [`Column`] will not inspect the [`Vec`], which means
|
||||
/// it won't automatically adapt to the sizing strategy of its contents.
|
||||
///
|
||||
/// If any of the children have a [`Length::Fill`] strategy, you will need to
|
||||
/// call [`Column::width`] or [`Column::height`] accordingly.
|
||||
pub fn from_vec(
|
||||
children: Vec<Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
spacing: 0.0,
|
||||
padding: Padding::ZERO,
|
||||
width: Length::Shrink,
|
||||
|
|
@ -38,17 +58,10 @@ where
|
|||
max_width: f32::INFINITY,
|
||||
align_items: Alignment::Start,
|
||||
clip: false,
|
||||
children: Vec::new(),
|
||||
children,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] with the given elements.
|
||||
pub fn with_children(
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
children.into_iter().fold(Self::new(), Self::push)
|
||||
}
|
||||
|
||||
/// Sets the vertical spacing _between_ elements.
|
||||
///
|
||||
/// Custom margins per element do not exist in iced. You should use this
|
||||
|
|
@ -127,6 +140,14 @@ where
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Extends the [`Column`] with the given children.
|
||||
pub fn extend(
|
||||
self,
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
children.into_iter().fold(self, Self::push)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Default for Column<'a, Message, Renderer>
|
||||
|
|
|
|||
|
|
@ -28,22 +28,35 @@ where
|
|||
{
|
||||
/// Creates an empty [`Row`].
|
||||
pub fn new() -> Self {
|
||||
Row {
|
||||
spacing: 0.0,
|
||||
padding: Padding::ZERO,
|
||||
width: Length::Shrink,
|
||||
height: Length::Shrink,
|
||||
align_items: Alignment::Start,
|
||||
clip: false,
|
||||
children: Vec::new(),
|
||||
}
|
||||
Self::from_vec(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a [`Row`] with the given elements.
|
||||
pub fn with_children(
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
children.into_iter().fold(Self::new(), Self::push)
|
||||
Self::new().extend(children)
|
||||
}
|
||||
|
||||
/// Creates a [`Row`] from an already allocated [`Vec`].
|
||||
///
|
||||
/// Keep in mind that the [`Row`] will not inspect the [`Vec`], which means
|
||||
/// it won't automatically adapt to the sizing strategy of its contents.
|
||||
///
|
||||
/// If any of the children have a [`Length::Fill`] strategy, you will need to
|
||||
/// call [`Row::width`] or [`Row::height`] accordingly.
|
||||
pub fn from_vec(
|
||||
children: Vec<Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
spacing: 0.0,
|
||||
padding: Padding::ZERO,
|
||||
width: Length::Shrink,
|
||||
height: Length::Shrink,
|
||||
align_items: Alignment::Start,
|
||||
clip: false,
|
||||
children,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the horizontal spacing _between_ elements.
|
||||
|
|
@ -118,6 +131,14 @@ where
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Extends the [`Row`] with the given children.
|
||||
pub fn extend(
|
||||
self,
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
children.into_iter().fold(self, Self::push)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Default for Row<'a, Message, Renderer>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue