Iced: Create Containers with multiple known children

Created on 15 Mar 2020  路  4Comments  路  Source: hecrj/iced

I have a vec of n Elements I've built from server JSON. I'd like to push these all into a Column. I tried to do a for loop and push onto an existing Column, but I think because push captures self not &self I can't do this because of the borrow checker (I'm new to Rust, please correct me).

I have a local fork with a new instantiation method. It seems to hold true to the spirit of immutability.

    /// Creates an full [`Column`].
    ///
    /// [`Column`]: struct.Column.html
    pub fn new_with_children(
        children: Vec<Element<'a, Message, Renderer>>,
    ) -> Self {
        Column {
            spacing: 0,
            padding: 0,
            width: Length::Shrink,
            height: Length::Shrink,
            max_width: u32::MAX,
            max_height: u32::MAX,
            align_items: Align::Start,
            children,
        }
    }

Is that a welcome PR, or is there a better way?

feature question

All 4 comments

I do something like what you want with Airshipper, check out https://github.com/Songtronix/Airshipper/blob/master/client/src/gui/mod.rs
You probably are interested in the news part but sadly can't explain more right now but if needed I can sure help you tomorrow.

@rowungiles You should be able to fold an iterator. The todos example does this to generate the list of tasks:

https://github.com/hecrj/iced/blob/36e617ae70cc7a86ce998cbd61f6aa702bb42933/examples/todos/src/main.rs#L170-L178

That said, I agree Column::with_children and Row::with_children would be nice additions. By all means, feel free to open a PR!

Super, I'll do that. Thank you.

And yes, of course you were both correct. fold did exactly what I wanted.

Closed by #220. Thank you! :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Gohla picture Gohla  路  4Comments

aentity picture aentity  路  4Comments

jiminycrick picture jiminycrick  路  3Comments

aentity picture aentity  路  3Comments

porglezomp picture porglezomp  路  3Comments