use crate::builder::{Builder, LayoutBuilder};
use nemo_plugin_api::PluginValue;
pub struct Panel(LayoutBuilder);
impl Panel {
pub fn new() -> Self {
Self(LayoutBuilder::new("panel"))
}
pub fn padding(mut self, padding: i64) -> Self {
self.0 = self.0.padding(padding);
self
}
pub fn margin(mut self, margin: i64) -> Self {
self.0 = self.0.margin(margin);
self
}
pub fn border(mut self, border: i64) -> Self {
self.0 = self.0.border(border);
self
}
pub fn border_color(mut self, color: impl Into<String>) -> Self {
self.0 = self.0.border_color(color);
self
}
pub fn bg_color(mut self, color: impl Into<String>) -> Self {
self.0 = self.0.bg_color(color);
self
}
pub fn shadow(mut self, shadow: impl Into<String>) -> Self {
self.0 = self.0.shadow(shadow);
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
}
pub fn child(mut self, id: impl Into<String>, child: impl Builder) -> Self {
self.0 = self.0.child(id, child);
self
}
pub fn children(mut self, children: impl IntoIterator<Item = (String, PluginValue)>) -> Self {
self.0 = self.0.children(children);
self
}
}
impl Default for Panel {
fn default() -> Self {
Self::new()
}
}
impl Builder for Panel {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Stack(LayoutBuilder);
impl Stack {
pub fn vertical() -> Self {
Self(
LayoutBuilder::new("stack")
.attr("direction", PluginValue::String("vertical".to_string())),
)
}
pub fn horizontal() -> Self {
Self(
LayoutBuilder::new("stack")
.attr("direction", PluginValue::String("horizontal".to_string())),
)
}
pub fn spacing(mut self, spacing: i64) -> Self {
self.0 = self.0.attr("spacing", PluginValue::Integer(spacing));
self
}
pub fn padding(mut self, padding: i64) -> Self {
self.0 = self.0.padding(padding);
self
}
pub fn align(mut self, align: impl Into<String>) -> Self {
self.0 = self.0.attr("align", PluginValue::String(align.into()));
self
}
pub fn justify(mut self, justify: impl Into<String>) -> Self {
self.0 = self.0.attr("justify", PluginValue::String(justify.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
}
pub fn child(mut self, id: impl Into<String>, child: impl Builder) -> Self {
self.0 = self.0.child(id, child);
self
}
pub fn children(mut self, children: impl IntoIterator<Item = (String, PluginValue)>) -> Self {
self.0 = self.0.children(children);
self
}
}
impl Builder for Stack {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct Grid(LayoutBuilder);
impl Grid {
pub fn new(columns: i64) -> Self {
Self(LayoutBuilder::new("grid").attr("columns", PluginValue::Integer(columns)))
}
pub fn columns(mut self, columns: i64) -> Self {
self.0 = self.0.attr("columns", PluginValue::Integer(columns));
self
}
pub fn gap(mut self, gap: i64) -> Self {
self.0 = self.0.attr("gap", PluginValue::Integer(gap));
self
}
pub fn padding(mut self, padding: i64) -> Self {
self.0 = self.0.padding(padding);
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
}
pub fn child(mut self, id: impl Into<String>, child: impl Builder) -> Self {
self.0 = self.0.child(id, child);
self
}
pub fn children(mut self, children: impl IntoIterator<Item = (String, PluginValue)>) -> Self {
self.0 = self.0.children(children);
self
}
}
impl Builder for Grid {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub struct ScrollView(LayoutBuilder);
impl ScrollView {
pub fn new() -> Self {
Self(LayoutBuilder::new("scroll"))
}
pub fn direction(mut self, direction: impl Into<String>) -> Self {
self.0 = self
.0
.attr("direction", PluginValue::String(direction.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
}
pub fn child(mut self, id: impl Into<String>, child: impl Builder) -> Self {
self.0 = self.0.child(id, child);
self
}
}
impl Default for ScrollView {
fn default() -> Self {
Self::new()
}
}
impl Builder for ScrollView {
fn build(self) -> PluginValue {
self.0.build()
}
}
pub fn input_row(
label_text: impl Into<String>,
label_width: Option<i64>,
component: impl Builder,
spacing: Option<i64>,
) -> Stack {
let mut label = crate::components::Label::new(label_text);
if let Some(width) = label_width {
label = label.width(width);
}
let mut stack = Stack::horizontal()
.child("label", label)
.child("component", component);
if let Some(spacing) = spacing {
stack = stack.spacing(spacing);
}
stack
}
pub fn row(spacing: i64) -> Stack {
Stack::horizontal().spacing(spacing)
}
pub fn column(spacing: i64) -> Stack {
Stack::vertical().spacing(spacing)
}