Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend and from_vec methods for Column and Row #2264

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...

Expand Down Expand Up @@ -159,7 +166,6 @@ Many thanks to...
- @nicksenger
- @Nisatru
- @nyurik
- @PolyMeilex
- @Remmirad
- @ripytide
- @snaggen
Expand Down
39 changes: 30 additions & 9 deletions widget/src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,38 @@ 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,
height: Length::Shrink,
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
Expand Down Expand Up @@ -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>
Expand Down
39 changes: 30 additions & 9 deletions widget/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,37 @@ where
{
/// Creates an empty [`Row`].
pub fn new() -> Self {
Row {
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 {
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: Vec::new(),
children,
}
}

/// 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)
}

/// Sets the horizontal spacing _between_ elements.
///
/// Custom margins per element do not exist in iced. You should use this
Expand Down Expand Up @@ -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>
Expand Down
Loading