use super::{PropMap, PropValue};
use crate::View;
use crate::derive_support::PlushieType;
use crate::types::*;
pub struct WindowBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
pub fn window(id: &str) -> WindowBuilder {
WindowBuilder {
id: id.to_string(),
props: PropMap::new(),
children: vec![],
}
}
impl WindowBuilder {
pub fn title(mut self, title: &str) -> Self {
super::set_prop(&mut self.props, "title", title);
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn position(mut self, x: f32, y: f32) -> Self {
super::set_prop(
&mut self.props,
"position",
PropValue::Array(vec![PropValue::F64(x as f64), PropValue::F64(y as f64)]),
);
self
}
pub fn min_size(mut self, w: f32, h: f32) -> Self {
super::set_prop(
&mut self.props,
"min_size",
PropValue::Array(vec![PropValue::F64(w as f64), PropValue::F64(h as f64)]),
);
self
}
pub fn max_size(mut self, w: f32, h: f32) -> Self {
super::set_prop(
&mut self.props,
"max_size",
PropValue::Array(vec![PropValue::F64(w as f64), PropValue::F64(h as f64)]),
);
self
}
pub fn theme(mut self, theme: impl Into<Theme>) -> Self {
let theme: Theme = theme.into();
super::set_prop(&mut self.props, "theme", theme.wire_encode());
self
}
pub fn scale_factor(mut self, factor: f64) -> Self {
super::set_prop(&mut self.props, "scale_factor", factor);
self
}
pub fn maximized(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "maximized", v);
self
}
pub fn fullscreen(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "fullscreen", v);
self
}
pub fn visible(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "visible", v);
self
}
pub fn resizable(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "resizable", v);
self
}
pub fn decorations(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "decorations", v);
self
}
pub fn transparent(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "transparent", v);
self
}
pub fn closeable(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "closeable", v);
self
}
pub fn minimizable(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "minimizable", v);
self
}
pub fn blur(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "blur", v);
self
}
pub fn level(mut self, level: WindowLevel) -> Self {
super::set_prop(&mut self.props, "level", level.wire_encode());
self
}
pub fn exit_on_close_request(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "exit_on_close_request", v);
self
}
pub fn size(mut self, w: f32, h: f32) -> Self {
super::set_prop(
&mut self.props,
"size",
PropValue::Array(vec![PropValue::F64(w as f64), PropValue::F64(h as f64)]),
);
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<WindowBuilder> for View {
fn from(b: WindowBuilder) -> Self {
super::view_node(b.id, "window", b.props, b.children)
}
}
pub struct ColumnBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
#[track_caller]
pub fn column() -> ColumnBuilder {
ColumnBuilder {
id: super::auto_id("column"),
props: PropMap::new(),
children: vec![],
}
}
impl ColumnBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn padding(mut self, p: impl Into<Padding>) -> Self {
super::set_prop(
&mut self.props,
"padding",
super::padding_to_value(p.into()),
);
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn max_width(mut self, w: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "max_width", w.into().wire_encode());
self
}
pub fn align_x(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_x", super::halign_to_value(a));
self
}
pub fn clip(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "clip", v);
self
}
pub fn wrap(mut self, enabled: bool) -> Self {
super::set_prop(&mut self.props, "wrap", enabled);
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<ColumnBuilder> for View {
fn from(b: ColumnBuilder) -> Self {
super::view_node(b.id, "column", b.props, b.children)
}
}
pub struct RowBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
#[track_caller]
pub fn row() -> RowBuilder {
RowBuilder {
id: super::auto_id("row"),
props: PropMap::new(),
children: vec![],
}
}
impl RowBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn padding(mut self, p: impl Into<Padding>) -> Self {
super::set_prop(
&mut self.props,
"padding",
super::padding_to_value(p.into()),
);
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn max_width(mut self, w: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "max_width", w.into().wire_encode());
self
}
pub fn align_x(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_x", super::halign_to_value(a));
self
}
pub fn align_y(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_y", super::valign_to_value(a));
self
}
pub fn clip(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "clip", v);
self
}
pub fn wrap(mut self, enabled: bool) -> Self {
super::set_prop(&mut self.props, "wrap", enabled);
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<RowBuilder> for View {
fn from(b: RowBuilder) -> Self {
super::view_node(b.id, "row", b.props, b.children)
}
}
pub struct ContainerBuilder {
id: String,
props: PropMap,
child: Option<View>,
}
#[track_caller]
pub fn container() -> ContainerBuilder {
ContainerBuilder {
id: super::auto_id("container"),
props: PropMap::new(),
child: None,
}
}
impl ContainerBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn padding(mut self, p: impl Into<Padding>) -> Self {
super::set_prop(
&mut self.props,
"padding",
super::padding_to_value(p.into()),
);
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn max_width(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "max_width", v.into().wire_encode());
self
}
pub fn max_height(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "max_height", v.into().wire_encode());
self
}
pub fn align_x(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_x", super::halign_to_value(a));
self
}
pub fn align_y(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_y", super::valign_to_value(a));
self
}
pub fn clip(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "clip", v);
self
}
pub fn background(mut self, bg: impl Into<Animatable<Background>>) -> Self {
super::set_prop(&mut self.props, "background", bg.into().wire_encode());
self
}
pub fn color(mut self, c: impl Into<Animatable<Color>>) -> Self {
super::set_prop(&mut self.props, "color", c.into().wire_encode());
self
}
pub fn border(mut self, b: Border) -> Self {
super::set_prop(&mut self.props, "border", b.wire_encode());
self
}
pub fn shadow(mut self, s: Shadow) -> Self {
super::set_prop(&mut self.props, "shadow", s.wire_encode());
self
}
pub fn center(mut self, enabled: bool) -> Self {
super::set_prop(&mut self.props, "center", enabled);
self
}
pub fn style(mut self, s: impl Into<Style>) -> Self {
let s = s.into();
super::set_prop(&mut self.props, "style", super::style_to_value(&s));
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.child = Some(child.into());
self
}
}
impl From<ContainerBuilder> for View {
fn from(b: ContainerBuilder) -> Self {
let children = b.child.into_iter().collect();
super::view_node(b.id, "container", b.props, children)
}
}
pub struct StackBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
#[track_caller]
pub fn stack() -> StackBuilder {
StackBuilder {
id: super::auto_id("stack"),
props: PropMap::new(),
children: vec![],
}
}
impl StackBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn clip(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "clip", v);
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<StackBuilder> for View {
fn from(b: StackBuilder) -> Self {
super::view_node(b.id, "stack", b.props, b.children)
}
}
pub struct GridBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
#[track_caller]
pub fn grid() -> GridBuilder {
GridBuilder {
id: super::auto_id("grid"),
props: PropMap::new(),
children: vec![],
}
}
impl GridBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn num_columns(mut self, n: u32) -> Self {
super::set_prop(&mut self.props, "num_columns", n);
self
}
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn width(mut self, w: f32) -> Self {
super::set_prop(&mut self.props, "width", PropValue::F64(w as f64));
self
}
pub fn height(mut self, h: f32) -> Self {
super::set_prop(&mut self.props, "height", PropValue::F64(h as f64));
self
}
pub fn fluid(mut self, max_cell_width: f32) -> Self {
super::set_prop(&mut self.props, "fluid", max_cell_width);
self
}
pub fn column_width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(
&mut self.props,
"column_width",
super::length_to_value(w.into()),
);
self
}
pub fn row_height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(
&mut self.props,
"row_height",
super::length_to_value(h.into()),
);
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<GridBuilder> for View {
fn from(b: GridBuilder) -> Self {
super::view_node(b.id, "grid", b.props, b.children)
}
}
pub struct PinBuilder {
id: String,
props: PropMap,
child: Option<View>,
}
#[track_caller]
pub fn pin() -> PinBuilder {
PinBuilder {
id: super::auto_id("pin"),
props: PropMap::new(),
child: None,
}
}
impl PinBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn x(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "x", v.into().wire_encode());
self
}
pub fn y(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "y", v.into().wire_encode());
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.child = Some(child.into());
self
}
}
impl From<PinBuilder> for View {
fn from(b: PinBuilder) -> Self {
let children = b.child.into_iter().collect();
super::view_node(b.id, "pin", b.props, children)
}
}
pub struct KeyedColumnBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
#[track_caller]
pub fn keyed_column() -> KeyedColumnBuilder {
KeyedColumnBuilder {
id: super::auto_id("keyed_column"),
props: PropMap::new(),
children: vec![],
}
}
impl KeyedColumnBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn padding(mut self, p: impl Into<Padding>) -> Self {
super::set_prop(
&mut self.props,
"padding",
super::padding_to_value(p.into()),
);
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn align_x(mut self, a: Align) -> Self {
super::set_prop(&mut self.props, "align_x", super::halign_to_value(a));
self
}
pub fn max_width(mut self, w: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "max_width", w.into().wire_encode());
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<KeyedColumnBuilder> for View {
fn from(b: KeyedColumnBuilder) -> Self {
super::view_node(b.id, "keyed_column", b.props, b.children)
}
}
pub struct FloatingBuilder {
id: String,
props: PropMap,
child: Option<View>,
}
#[track_caller]
pub fn floating() -> FloatingBuilder {
FloatingBuilder {
id: super::auto_id("floating"),
props: PropMap::new(),
child: None,
}
}
impl FloatingBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn translate_x(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "translate_x", v.into().wire_encode());
self
}
pub fn translate_y(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "translate_y", v.into().wire_encode());
self
}
pub fn scale(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "scale", v.into().wire_encode());
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.child = Some(child.into());
self
}
}
impl From<FloatingBuilder> for View {
fn from(b: FloatingBuilder) -> Self {
let children = b.child.into_iter().collect();
super::view_node(b.id, "floating", b.props, children)
}
}
pub struct ResponsiveBuilder {
id: String,
props: PropMap,
child: Option<View>,
}
#[track_caller]
pub fn responsive() -> ResponsiveBuilder {
ResponsiveBuilder {
id: super::auto_id("responsive"),
props: PropMap::new(),
child: None,
}
}
impl ResponsiveBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.child = Some(child.into());
self
}
}
impl From<ResponsiveBuilder> for View {
fn from(b: ResponsiveBuilder) -> Self {
let children = b.child.into_iter().collect();
super::view_node(b.id, "responsive", b.props, children)
}
}
pub struct ScrollableBuilder {
id: String,
props: PropMap,
child: Option<View>,
}
#[track_caller]
pub fn scrollable() -> ScrollableBuilder {
ScrollableBuilder {
id: super::auto_id("scrollable"),
props: PropMap::new(),
child: None,
}
}
impl ScrollableBuilder {
pub fn id(mut self, id: &str) -> Self {
self.id = id.to_string();
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn direction(mut self, dir: Direction) -> Self {
super::set_prop(&mut self.props, "direction", dir.wire_encode());
self
}
pub fn scrollbar_width(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "scrollbar_width", v.into().wire_encode());
self
}
pub fn scrollbar_margin(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "scrollbar_margin", v.into().wire_encode());
self
}
pub fn scroller_width(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "scroller_width", v.into().wire_encode());
self
}
pub fn anchor(mut self, a: Anchor) -> Self {
super::set_prop(&mut self.props, "anchor", a.wire_encode());
self
}
pub fn on_scroll(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "on_scroll", v);
self
}
pub fn auto_scroll(mut self, v: bool) -> Self {
super::set_prop(&mut self.props, "auto_scroll", v);
self
}
pub fn scrollbar_color(mut self, c: impl Into<Animatable<Color>>) -> Self {
super::set_prop(&mut self.props, "scrollbar_color", c.into().wire_encode());
self
}
pub fn scroller_color(mut self, c: impl Into<Animatable<Color>>) -> Self {
super::set_prop(&mut self.props, "scroller_color", c.into().wire_encode());
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.child = Some(child.into());
self
}
}
impl From<ScrollableBuilder> for View {
fn from(b: ScrollableBuilder) -> Self {
let children = b.child.into_iter().collect();
super::view_node(b.id, "scrollable", b.props, children)
}
}
pub struct PaneGridBuilder {
id: String,
props: PropMap,
children: Vec<View>,
}
pub fn pane_grid(id: &str) -> PaneGridBuilder {
PaneGridBuilder {
id: id.to_string(),
props: PropMap::new(),
children: vec![],
}
}
impl PaneGridBuilder {
pub fn spacing(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "spacing", v.into().wire_encode());
self
}
pub fn width(mut self, w: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "width", super::length_to_value(w.into()));
self
}
pub fn height(mut self, h: impl Into<Length>) -> Self {
super::set_prop(&mut self.props, "height", super::length_to_value(h.into()));
self
}
pub fn split_axis(mut self, axis: &str) -> Self {
super::set_prop(&mut self.props, "split_axis", axis);
self
}
pub fn panes(mut self, pane_ids: &[&str]) -> Self {
let ids: Vec<PropValue> = pane_ids
.iter()
.map(|s| PropValue::Str(s.to_string()))
.collect();
super::set_prop(&mut self.props, "panes", PropValue::Array(ids));
self
}
pub fn min_size(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "min_size", v.into().wire_encode());
self
}
pub fn divider_color(mut self, c: impl Into<Animatable<Color>>) -> Self {
super::set_prop(&mut self.props, "divider_color", c.into().wire_encode());
self
}
pub fn divider_width(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "divider_width", v.into().wire_encode());
self
}
pub fn leeway(mut self, v: impl Into<Animatable<f32>>) -> Self {
super::set_prop(&mut self.props, "leeway", v.into().wire_encode());
self
}
pub fn event_rate(mut self, rate: u32) -> Self {
super::set_prop(&mut self.props, "event_rate", rate);
self
}
pub fn a11y(mut self, a11y: &A11y) -> Self {
super::set_prop(&mut self.props, "a11y", a11y.wire_encode());
self
}
pub fn child(mut self, child: impl Into<View>) -> Self {
self.children.push(child.into());
self
}
pub fn children<I, V>(mut self, items: I) -> Self
where
I: IntoIterator<Item = V>,
V: Into<View>,
{
self.children.extend(items.into_iter().map(Into::into));
self
}
}
impl From<PaneGridBuilder> for View {
fn from(b: PaneGridBuilder) -> Self {
super::view_node(b.id, "pane_grid", b.props, b.children)
}
}