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
Textwidget for eachStringin you collection and then you can either usewith_childrento create theColumnwith all its children in one go orpushto add items one by one.Notice how
with_childrenrequires a vector ofElements, so I callinto()on my widgets, butpushonly requires anInto<Element>so I can pass the widget directly.There …