#[allow(unused_imports)]
use alloc::collections::BTreeMap;
use crate::at_inlay::Response;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Row<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub align: Option<RowAlign<S>>,
pub children: Data<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gap: Option<RowGap<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub inset: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub justify: Option<RowJustify<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub opaque: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sticky: Option<bool>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RowAlign<S: BosStr = DefaultStr> {
Start,
Center,
End,
Stretch,
Other(S),
}
impl<S: BosStr> RowAlign<S> {
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(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"stretch" => Self::Stretch,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for RowAlign<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for RowAlign<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for RowAlign<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RowAlign<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for RowAlign<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for RowAlign<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = RowAlign<S::Output>;
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<S: BosStr = DefaultStr> {
None,
Small,
Medium,
Large,
Other(S),
}
impl<S: BosStr> RowGap<S> {
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(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"none" => Self::None,
"small" => Self::Small,
"medium" => Self::Medium,
"large" => Self::Large,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for RowGap<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for RowGap<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for RowGap<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RowGap<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for RowGap<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for RowGap<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = RowGap<S::Output>;
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<S: BosStr = DefaultStr> {
Start,
Center,
End,
Between,
Other(S),
}
impl<S: BosStr> RowJustify<S> {
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(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"start" => Self::Start,
"center" => Self::Center,
"end" => Self::End,
"between" => Self::Between,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for RowJustify<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for RowJustify<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for RowJustify<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RowJustify<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for RowJustify<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for RowJustify<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = RowJustify<S::Output>;
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()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct RowOutput<S: BosStr = DefaultStr> {
#[serde(flatten)]
pub value: Response<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
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<S: BosStr> = RowOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Row<S> {
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<S: BosStr> = Row<S>;
type Response = RowResponse;
}
pub mod row_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[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<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetChildren<St> {}
impl<St: State> State for SetChildren<St> {
type Children = Set<members::children>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct children(());
}
}
pub struct RowBuilder<S: BosStr, St: row_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<RowAlign<S>>,
Option<Data<S>>,
Option<RowGap<S>>,
Option<bool>,
Option<RowJustify<S>>,
Option<bool>,
Option<bool>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Row<S> {
pub fn new() -> RowBuilder<S, row_state::Empty> {
RowBuilder::new()
}
}
impl<S: BosStr> RowBuilder<S, row_state::Empty> {
pub fn new() -> Self {
RowBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: row_state::State> RowBuilder<S, St> {
pub fn align(mut self, value: impl Into<Option<RowAlign<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_align(mut self, value: Option<RowAlign<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> RowBuilder<S, St>
where
St: row_state::State,
St::Children: row_state::IsUnset,
{
pub fn children(
mut self,
value: impl Into<Data<S>>,
) -> RowBuilder<S, row_state::SetChildren<St>> {
self._fields.1 = Option::Some(value.into());
RowBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: row_state::State> RowBuilder<S, St> {
pub fn gap(mut self, value: impl Into<Option<RowGap<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_gap(mut self, value: Option<RowGap<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: row_state::State> RowBuilder<S, St> {
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<S: BosStr, St: row_state::State> RowBuilder<S, St> {
pub fn justify(mut self, value: impl Into<Option<RowJustify<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_justify(mut self, value: Option<RowJustify<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: row_state::State> RowBuilder<S, St> {
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<S: BosStr, St: row_state::State> RowBuilder<S, St> {
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<S: BosStr, St> RowBuilder<S, St>
where
St: row_state::State,
St::Children: row_state::IsSet,
{
pub fn build(self) -> Row<S> {
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<SmolStr, Data<S>>) -> Row<S> {
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),
}
}
}