use crate::builder::{Builder, LayoutBuilder};
use nemo_plugin_api::PluginValue;
pub struct Label(LayoutBuilder);
impl Label {
pub fn new(text: impl Into<String>) -> Self {
Self(LayoutBuilder::new("label").attr("text", PluginValue::String(text.into())))
}
pub fn text(mut self, text: impl Into<String>) -> Self {
self.0 = self.0.attr("text", PluginValue::String(text.into()));
self
}
pub fn size(mut self, size: impl Into<String>) -> Self {
self.0 = self.0.attr("size", PluginValue::String(size.into()));
self
}
pub fn color(mut self, color: impl Into<String>) -> Self {
self.0 = self.0.attr("color", PluginValue::String(color.into()));
self
}
pub fn weight(mut self, weight: impl Into<String>) -> Self {
self.0 = self.0.attr("weight", PluginValue::String(weight.into()));
self
}
pub fn bind_text(mut self, path: impl Into<String>) -> Self {
self.0 = self.0.bind("text", path);
self
}
pub fn width(mut self, width: i64) -> Self {
self.0 = self.0.width(width);
self
}
pub fn height(mut self, height: i64) -> Self {
self.0 = self.0.height(height);
self
}
}
impl Builder for Label {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Input(LayoutBuilder);
impl Input {
pub fn new() -> Self {
Self(LayoutBuilder::new("input"))
}
pub fn value(mut self, value: impl Into<String>) -> Self {
self.0 = self.0.attr("value", PluginValue::String(value.into()));
self
}
pub fn placeholder(mut self, placeholder: impl Into<String>) -> Self {
self.0 = self
.0
.attr("placeholder", PluginValue::String(placeholder.into()));
self
}
pub fn on_change(mut self, handler: impl Into<String>) -> Self {
self.0 = self.0.on("change", handler);
self
}
pub fn on_submit(mut self, handler: impl Into<String>) -> Self {
self.0 = self.0.on("submit", handler);
self
}
pub fn bind_value(mut self, path: impl Into<String>) -> Self {
self.0 = self.0.bind("value", path);
self
}
pub fn width(mut self, width: i64) -> Self {
self.0 = self.0.width(width);
self
}
pub fn disabled(mut self, disabled: bool) -> Self {
self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
self
}
}
impl Default for Input {
fn default() -> Self {
Self::new()
}
}
impl Builder for Input {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Button(LayoutBuilder);
impl Button {
pub fn new(label: impl Into<String>) -> Self {
Self(LayoutBuilder::new("button").attr("label", PluginValue::String(label.into())))
}
pub fn label(mut self, label: impl Into<String>) -> Self {
self.0 = self.0.attr("label", PluginValue::String(label.into()));
self
}
pub fn variant(mut self, variant: impl Into<String>) -> Self {
self.0 = self.0.attr("variant", PluginValue::String(variant.into()));
self
}
pub fn on_click(mut self, handler: impl Into<String>) -> Self {
self.0 = self.0.on("click", handler);
self
}
pub fn disabled(mut self, disabled: bool) -> Self {
self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
self
}
pub fn width(mut self, width: i64) -> Self {
self.0 = self.0.width(width);
self
}
}
impl Builder for Button {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Switch(LayoutBuilder);
impl Switch {
pub fn new() -> Self {
Self(LayoutBuilder::new("switch"))
}
pub fn label(mut self, label: impl Into<String>) -> Self {
self.0 = self.0.attr("label", PluginValue::String(label.into()));
self
}
pub fn checked(mut self, checked: bool) -> Self {
self.0 = self.0.attr("checked", PluginValue::Bool(checked));
self
}
pub fn on_click(mut self, handler: impl Into<String>) -> Self {
self.0 = self.0.on("click", handler);
self
}
pub fn bind_checked(mut self, path: impl Into<String>) -> Self {
self.0 = self.0.bind("checked", path);
self
}
pub fn disabled(mut self, disabled: bool) -> Self {
self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
self
}
}
impl Default for Switch {
fn default() -> Self {
Self::new()
}
}
impl Builder for Switch {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Slider(LayoutBuilder);
impl Slider {
pub fn new() -> Self {
Self(LayoutBuilder::new("slider"))
}
pub fn value(mut self, value: f64) -> Self {
self.0 = self.0.attr("value", PluginValue::Float(value));
self
}
pub fn min(mut self, min: f64) -> Self {
self.0 = self.0.attr("min", PluginValue::Float(min));
self
}
pub fn max(mut self, max: f64) -> Self {
self.0 = self.0.attr("max", PluginValue::Float(max));
self
}
pub fn step(mut self, step: f64) -> Self {
self.0 = self.0.attr("step", PluginValue::Float(step));
self
}
pub fn on_change(mut self, handler: impl Into<String>) -> Self {
self.0 = self.0.on("change", handler);
self
}
pub fn bind_value(mut self, path: impl Into<String>) -> Self {
self.0 = self.0.bind("value", path);
self
}
}
impl Default for Slider {
fn default() -> Self {
Self::new()
}
}
impl Builder for Slider {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Image(LayoutBuilder);
impl Image {
pub fn new(src: impl Into<String>) -> Self {
Self(LayoutBuilder::new("image").attr("src", PluginValue::String(src.into())))
}
pub fn src(mut self, src: impl Into<String>) -> Self {
self.0 = self.0.attr("src", PluginValue::String(src.into()));
self
}
pub fn alt(mut self, alt: impl Into<String>) -> Self {
self.0 = self.0.attr("alt", PluginValue::String(alt.into()));
self
}
pub fn width(mut self, width: i64) -> Self {
self.0 = self.0.width(width);
self
}
pub fn height(mut self, height: i64) -> Self {
self.0 = self.0.height(height);
self
}
}
impl Builder for Image {
fn build(self) -> PluginValue {
self.0.build()
}
}