#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::at_inlay::Response;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Row<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub align: Option<RowAlign<'a>>,
#[serde(borrow)]
pub children: Data<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub gap: Option<RowGap<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub inset: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub justify: Option<RowJustify<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub opaque: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sticky: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RowAlign<'a> {
Start,
Center,
End,
Stretch,
Other(CowStr<'a>),
}
impl<'a> RowAlign<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Start => "start",
Self::Center => "center",
Self::End => "end",
Self::Stretch => "stretch",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RowAlign<'a> {
fn from(s: &'a str) -> Self {
match s {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"stretch" => Self::Stretch,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RowAlign<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"stretch" => Self::Stretch,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RowAlign<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RowAlign<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RowAlign<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for RowAlign<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for RowAlign<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RowAlign<'_> {
type Output = RowAlign<'static>;
fn into_static(self) -> Self::Output {
match self {
RowAlign::Start => RowAlign::Start,
RowAlign::Center => RowAlign::Center,
RowAlign::End => RowAlign::End,
RowAlign::Stretch => RowAlign::Stretch,
RowAlign::Other(v) => RowAlign::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RowGap<'a> {
None,
Small,
Medium,
Large,
Other(CowStr<'a>),
}
impl<'a> RowGap<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::None => "none",
Self::Small => "small",
Self::Medium => "medium",
Self::Large => "large",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RowGap<'a> {
fn from(s: &'a str) -> Self {
match s {
"none" => Self::None,
"small" => Self::Small,
"medium" => Self::Medium,
"large" => Self::Large,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RowGap<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"none" => Self::None,
"small" => Self::Small,
"medium" => Self::Medium,
"large" => Self::Large,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RowGap<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RowGap<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RowGap<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for RowGap<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for RowGap<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RowGap<'_> {
type Output = RowGap<'static>;
fn into_static(self) -> Self::Output {
match self {
RowGap::None => RowGap::None,
RowGap::Small => RowGap::Small,
RowGap::Medium => RowGap::Medium,
RowGap::Large => RowGap::Large,
RowGap::Other(v) => RowGap::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RowJustify<'a> {
Start,
Center,
End,
Between,
Other(CowStr<'a>),
}
impl<'a> RowJustify<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Start => "start",
Self::Center => "center",
Self::End => "end",
Self::Between => "between",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RowJustify<'a> {
fn from(s: &'a str) -> Self {
match s {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"between" => Self::Between,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RowJustify<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"between" => Self::Between,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RowJustify<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RowJustify<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RowJustify<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for RowJustify<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for RowJustify<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RowJustify<'_> {
type Output = RowJustify<'static>;
fn into_static(self) -> Self::Output {
match self {
RowJustify::Start => RowJustify::Start,
RowJustify::Center => RowJustify::Center,
RowJustify::End => RowJustify::End,
RowJustify::Between => RowJustify::Between,
RowJustify::Other(v) => RowJustify::Other(v.into_static()),
}
}
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RowOutput<'a> {
#[serde(flatten)]
#[serde(borrow)]
pub value: Response<'a>,
}
pub struct RowResponse;
impl jacquard_common::xrpc::XrpcResp for RowResponse {
const NSID: &'static str = "org.atsui.Row";
const ENCODING: &'static str = "application/json";
type Output<'de> = RowOutput<'de>;
type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for Row<'a> {
const NSID: &'static str = "org.atsui.Row";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = RowResponse;
}
pub struct RowRequest;
impl jacquard_common::xrpc::XrpcEndpoint for RowRequest {
const PATH: &'static str = "/xrpc/org.atsui.Row";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = Row<'de>;
type Response = RowResponse;
}
pub mod row_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Children;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Children = Unset;
}
pub struct SetChildren<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetChildren<S> {}
impl<S: State> State for SetChildren<S> {
type Children = Set<members::children>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct children(());
}
}
pub struct RowBuilder<'a, S: row_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<RowAlign<'a>>,
Option<Data<'a>>,
Option<RowGap<'a>>,
Option<bool>,
Option<RowJustify<'a>>,
Option<bool>,
Option<bool>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Row<'a> {
pub fn new() -> RowBuilder<'a, row_state::Empty> {
RowBuilder::new()
}
}
impl<'a> RowBuilder<'a, row_state::Empty> {
pub fn new() -> Self {
RowBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn align(mut self, value: impl Into<Option<RowAlign<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_align(mut self, value: Option<RowAlign<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> RowBuilder<'a, S>
where
S: row_state::State,
S::Children: row_state::IsUnset,
{
pub fn children(
mut self,
value: impl Into<Data<'a>>,
) -> RowBuilder<'a, row_state::SetChildren<S>> {
self._fields.1 = Option::Some(value.into());
RowBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn gap(mut self, value: impl Into<Option<RowGap<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_gap(mut self, value: Option<RowGap<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn inset(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_inset(mut self, value: Option<bool>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn justify(mut self, value: impl Into<Option<RowJustify<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_justify(mut self, value: Option<RowJustify<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn opaque(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_opaque(mut self, value: Option<bool>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: row_state::State> RowBuilder<'a, S> {
pub fn sticky(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_sticky(mut self, value: Option<bool>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> RowBuilder<'a, S>
where
S: row_state::State,
S::Children: row_state::IsSet,
{
pub fn build(self) -> Row<'a> {
Row {
align: self._fields.0,
children: self._fields.1.unwrap(),
gap: self._fields.2,
inset: self._fields.3,
justify: self._fields.4,
opaque: self._fields.5,
sticky: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Row<'a> {
Row {
align: self._fields.0,
children: self._fields.1.unwrap(),
gap: self._fields.2,
inset: self._fields.3,
justify: self._fields.4,
opaque: self._fields.5,
sticky: self._fields.6,
extra_data: Some(extra_data),
}
}
}