summaryrefslogtreecommitdiffstats
path: root/widget/src/column.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-19 08:49:28 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-19 08:49:28 +0100
commite60dabddefd6608a34ecb3f21a0fd53fef6d1f07 (patch)
tree7cd5e0f2376988521dc49b7bc48d042329a8ad87 /widget/src/column.rs
parent9f0bbf6020146d16521dd301b925f710d85dc92d (diff)
downloadiced-e60dabddefd6608a34ecb3f21a0fd53fef6d1f07.tar.gz
iced-e60dabddefd6608a34ecb3f21a0fd53fef6d1f07.tar.bz2
iced-e60dabddefd6608a34ecb3f21a0fd53fef6d1f07.zip
Add `from_vec` method to `Column` and `Row`
Diffstat (limited to 'widget/src/column.rs')
-rw-r--r--widget/src/column.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/widget/src/column.rs b/widget/src/column.rs
index 0c5ea75e..e59a0809 100644
--- a/widget/src/column.rs
+++ b/widget/src/column.rs
@@ -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 {
- Self::new().extend(children)
- }
-
/// Sets the vertical spacing _between_ elements.
///
/// Custom margins per element do not exist in iced. You should use this