mod canvas;
mod display;
mod input;
mod interactive;
mod layout;
mod memo;
mod table;
pub use canvas::*;
pub use display::*;
pub use input::*;
pub use interactive::*;
pub use layout::*;
pub use memo::*;
pub use table::*;
pub(crate) use plushie_core::protocol::{PropMap, PropValue};
use crate::View;
use crate::derive_support::PlushieType;
use crate::types::*;
pub(crate) fn view_node(id: String, type_name: &str, props: PropMap, children: Vec<View>) -> View {
View::new(
id,
type_name,
plushie_core::protocol::Props::from(props),
children,
)
}
pub(crate) fn view_leaf(id: String, type_name: &str, props: PropMap) -> View {
view_node(id, type_name, props, vec![])
}
#[track_caller]
pub(crate) fn auto_id(prefix: &str) -> String {
let loc = std::panic::Location::caller();
let file = loc.file().replace('\\', "/");
format!("auto:{prefix}:{file}:{}", loc.line())
}
pub(crate) fn set_prop(props: &mut PropMap, key: &str, value: impl Into<PropValue>) {
props.insert(key, value.into());
}
pub(crate) fn set_opt<T: Into<PropValue>>(props: &mut PropMap, key: &str, value: Option<T>) {
if let Some(v) = value {
props.insert(key, v.into());
}
}
pub(crate) fn length_to_value(l: Length) -> PropValue {
l.wire_encode()
}
pub(crate) fn padding_to_value(p: Padding) -> PropValue {
p.wire_encode()
}
pub(crate) fn style_to_value(s: &Style) -> PropValue {
s.wire_encode()
}
pub(crate) fn color_to_value(c: &Color) -> PropValue {
c.wire_encode()
}
pub(crate) fn background_to_value(bg: &Background) -> PropValue {
bg.wire_encode()
}
pub(crate) fn halign_to_value(a: Align) -> PropValue {
PropValue::Str(
match a {
Align::Start => "left",
Align::Center => "center",
Align::End => "right",
}
.into(),
)
}
pub(crate) fn valign_to_value(a: Align) -> PropValue {
PropValue::Str(
match a {
Align::Start => "top",
Align::Center => "center",
Align::End => "bottom",
}
.into(),
)
}
pub(crate) fn cross_align_to_value(a: Align) -> PropValue {
PropValue::Str(
match a {
Align::Start => "start",
Align::Center => "center",
Align::End => "end",
}
.into(),
)
}