Confusion in display items using rows and columns #1243
Answered
by
genusistimelord
tareksalem
asked this question in
Q&A
-
I am trying to distribute my content into something like cards each row has about two cards here is my elements use iced::{Row, Text, Container, Length, Space, Align, Column};
use super::state::{Message, MarkData};
pub fn render_mark_components<'a>() -> Container<'a, Message>
{
// let mut content = Row::new();
let container: Column<Message> = Column::with_children(
MarkData::all().iter_mut()
.map(| mark_data | {
let mut content = Column::new().spacing(15).width(Length::Fill).height(Length::Units(50));
content = content.push(
Column::new().push(Text::new(&mark_data.title).size(25)).width(Length::Fill)
).push(
Column::new().push(Text::new(&mark_data.description)).width(Length::Fill)
).push(
Space::with_height(Length::Units(100))
)
.width(Length::Fill);
Row::new().width(Length::Fill).spacing(20).align_items(Align::Center).push(content)
.into()
}).collect()
).width(Length::Fill).align_items(Align::End);
// content = content.push(container);
Container::new(container)
} however it doesn't work, it put each one in a separate line |
Beta Was this translation helpful? Give feedback.
Answered by
genusistimelord
Feb 9, 2022
Replies: 1 comment
-
Well you are adding one card to a Row so you need to make a builder to add 2 then make a new row after 2. So something like this: pub fn render_mark_components<'a>() -> Container<'a, Message> {
let mut row = Row::new().width(Length::Fill).spacing(20).align_items(Align::Center);
let mut container = Column::new().width(Length::Fill).align_items(Align::End);
let mut count = 0;
for mark_data in MarkData::all().iter_mut() {
if count >= 2 {
container = container.push(row);
row = Row::new().width(Length::Fill).spacing(20).align_items(Align::Center);
count = 0;
} else {
count += 1;
}
row = row.push(Column::new().spacing(15).width(Length::Fill).height(Length::Units(50)).push(
Column::new().push(Text::new(&mark_data.title).size(25)).width(Length::Fill)
).push(
Column::new().push(Text::new(&mark_data.description)).width(Length::Fill)
).push(
Space::with_height(Length::Units(100))
).width(Length::Fill));
}
Container::new(container)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tareksalem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well you are adding one card to a Row so you need to make a builder to add 2 then make a new row after 2. So something like this: