use crate::{
style::Style,
widgets::{Element, ToSpan},
};
#[derive(Debug)]
pub struct Row<M: 'static> {
pub(crate) cells: Vec<Element<M>>,
pub(crate) style: Style,
}
impl<M> Row<M> {
#[must_use]
pub fn new<T>(cells: T) -> Self
where
T: IntoIterator,
T::Item: Into<Element<M>>,
{
Self {
cells: cells.into_iter().map(Into::into).collect(),
..Default::default()
}
}
#[must_use]
pub fn style<S>(mut self, style: S) -> Self
where
S: Into<Style>,
{
self.style = style.into();
self
}
}
impl<M> Default for Row<M> {
fn default() -> Self {
Self {
cells: Default::default(),
style: Default::default(),
}
}
}
impl<M, I> FromIterator<I> for Row<M>
where
I: Into<Element<M>>,
{
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self {
Self::new(iter)
}
}
impl<M, T> From<Vec<T>> for Row<M>
where
T: Into<Element<M>>,
{
fn from(vec: Vec<T>) -> Self {
vec.into_iter().map(Into::into).collect()
}
}
impl<M, T> From<&Vec<T>> for Row<M>
where
M: Clone + 'static,
for<'a> &'a T: ToSpan,
{
fn from(vec: &Vec<T>) -> Self {
vec.iter()
.map(|item| Element::from(item.to_span()))
.collect()
}
}