Creating a Column
with a Vector of Strings
#2022
-
I am still new to Rust, so I am not sure if this stems from my lack of understanding of Rust or Iced. I am trying to learn Iced & Rust, and am experimenting with the library. I have a Secondly, how would I go about making a column with a vector of strings? I could |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You will need to create a 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 There are also some macros and helper functions that make the whole thing look simpler, although I'm just finding out about them now. fn view(&self) -> iced::Element<Message> {
let mut window = iced::widget::column![
iced::widget::text("hello"),
iced::widget::text("world"),
];
window = window.push(iced::widget::text("!"));
return window.into();
} |
Beta Was this translation helpful? Give feedback.
You will need to create a
Text
widget for eachString
in you collection and then you can either usewith_children
to create theColumn
with all its children in one go orpush
to add items one by one.Notice how
with_children
requires a vector ofElements
, so I callinto()
on my widgets, butpush
only requires anInto<Element>
so I can pass the widget directly.There …