Skip to content

Creating a Column with a Vector of Strings #2022

Answered by lufte
aadityadhruv asked this question in Q&A
Discussion options

You must be logged in to vote

You will need to create a Text widget for each String in you collection and then you can either use with_children to create the Column with all its children in one go or push to add items one by one.

    fn view(&self) -> iced::Element<Message> {
        let mut window = iced::widget::Column::with_children(vec![
            iced::widget::Text::new("hello").into(),
            iced::widget::Text::new("world").into(),
        ]);
        window = window.push(iced::widget::Text::new("!"));
        return window.into();
    }

Notice how with_children requires a vector of Elements, so I call into() on my widgets, but push only requires an Into<Element> so I can pass the widget directly.

There …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aadityadhruv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants