use std::panic::Location;
use crate::image::Image;
use crate::layout::VirtualItems;
use super::layout_types::{Align, Axis, Size};
use super::node::El;
use super::semantics::Kind;
#[track_caller]
pub fn column<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
El::new(Kind::Group)
.at_loc(Location::caller())
.children(children)
.axis(Axis::Column)
}
#[track_caller]
pub fn row<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
El::new(Kind::Group)
.at_loc(Location::caller())
.children(children)
.axis(Axis::Row)
}
#[track_caller]
pub fn stack<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
El::new(Kind::Group)
.at_loc(Location::caller())
.children(children)
.axis(Axis::Overlay)
}
#[track_caller]
pub fn scroll<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
El::new(Kind::Scroll)
.at_loc(Location::caller())
.children(children)
.axis(Axis::Column)
.width(Size::Fill(1.0))
.height(Size::Fill(1.0))
.clip()
.scrollable()
.scrollbar()
}
#[track_caller]
pub fn text_runs<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
El::new(Kind::Inlines)
.at_loc(Location::caller())
.axis(Axis::Column)
.align(Align::Start)
.width(Size::Fill(1.0))
.children(children)
}
#[track_caller]
pub fn hard_break() -> El {
El::new(Kind::HardBreak)
.at_loc(Location::caller())
.width(Size::Hug)
.height(Size::Hug)
}
#[track_caller]
pub fn virtual_list<F>(count: usize, row_height: f32, build_row: F) -> El
where
F: Fn(usize) -> El + Send + Sync + 'static,
{
let mut el = El::new(Kind::VirtualList)
.at_loc(Location::caller())
.axis(Axis::Column)
.align(Align::Stretch)
.width(Size::Fill(1.0))
.height(Size::Fill(1.0))
.clip()
.scrollable()
.scrollbar();
el.virtual_items = Some(VirtualItems::new(count, row_height, build_row));
el
}
#[track_caller]
pub fn spacer() -> El {
El::new(Kind::Spacer)
.at_loc(Location::caller())
.width(Size::Fill(1.0))
.height(Size::Fill(1.0))
}
#[track_caller]
pub fn image(img: impl Into<Image>) -> El {
El::new(Kind::Image).at_loc(Location::caller()).image(img)
}
#[track_caller]
pub fn divider() -> El {
El::new(Kind::Divider)
.at_loc(Location::caller())
.height(Size::Fixed(1.0))
.width(Size::Fill(1.0))
.fill(crate::tokens::BORDER)
}
impl From<&str> for El {
fn from(s: &str) -> Self {
crate::widgets::text::text(s)
}
}
impl From<String> for El {
fn from(s: String) -> Self {
crate::widgets::text::text(s)
}
}
impl From<&String> for El {
fn from(s: &String) -> Self {
crate::widgets::text::text(s.as_str())
}
}