snowcap/conversion/
row.rs1use iced::{widget::Row, Element};
2
3use crate::{error::ConversionError, parser::Attributes, Error, MarkupTree, Message};
4
5pub struct SnowcapRow;
6
7impl SnowcapRow {
8 pub fn convert<'a, SnowcapMessage, AppMessage>(
9 attrs: &Attributes,
10 contents: &'a Vec<MarkupTree<AppMessage>>,
11 ) -> Result<Element<'a, SnowcapMessage>, Error>
12 where
13 SnowcapMessage: 'a + Clone + From<Message<AppMessage>>,
14 AppMessage: 'a + Clone + std::fmt::Debug,
15 {
16 let children: Result<Vec<Element<'a, SnowcapMessage>>, Error> =
17 contents.into_iter().map(|item| item.try_into()).collect(); let mut row = Row::with_children(children?);
20
21 for attr in attrs {
22 row = match attr.name().as_str() {
23 "spacing" => {
24 let spacing: Result<iced::Pixels, Error> = (&*attr.value()).try_into();
25 row.spacing(spacing?)
26 }
27 "padding" => {
28 let padding: Result<iced::Padding, Error> = (&*attr.value()).try_into();
29 row.padding(padding?)
30 }
31 "width" => {
32 let width: Result<iced::Length, Error> = (&*attr.value()).try_into();
33 row.width(width?)
34 }
35 "height" => {
36 let height: Result<iced::Length, Error> = (&*attr.value()).try_into();
37 row.height(height?)
38 }
39 "align" => {
40 let align: Result<iced::alignment::Vertical, Error> =
41 (&*attr.value()).try_into();
42 row.align_y(align?)
43 }
44 "clip" => todo!(),
45 _ => {
46 return Err(Error::Conversion(ConversionError::UnsupportedAttribute(
47 attr.name().clone(),
48 )))
49 }
50 };
51 }
52
53 Ok(row.into())
54 }
55}