#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::at_inlay::Response;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Stack<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub align: Option<StackAlign<S>>,
pub children: Data<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub gap: Option<StackGap<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub inset: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub justify: Option<StackJustify<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub opaque: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub separator: 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 StackAlign<S: BosStr = DefaultStr> {
Start,
Center,
End,
Stretch,
Other(S),
}
impl<S: BosStr> StackAlign<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 StackAlign<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for StackAlign<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for StackAlign<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 StackAlign<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 StackAlign<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for StackAlign<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = StackAlign<S::Output>;
fn into_static(self) -> Self::Output {
match self {
StackAlign::Start => StackAlign::Start,
StackAlign::Center => StackAlign::Center,
StackAlign::End => StackAlign::End,
StackAlign::Stretch => StackAlign::Stretch,
StackAlign::Other(v) => StackAlign::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackGap<S: BosStr = DefaultStr> {
None,
Small,
Medium,
Large,
Other(S),
}
impl<S: BosStr> StackGap<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 StackGap<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for StackGap<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for StackGap<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 StackGap<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 StackGap<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for StackGap<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = StackGap<S::Output>;
fn into_static(self) -> Self::Output {
match self {
StackGap::None => StackGap::None,
StackGap::Small => StackGap::Small,
StackGap::Medium => StackGap::Medium,
StackGap::Large => StackGap::Large,
StackGap::Other(v) => StackGap::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StackJustify<S: BosStr = DefaultStr> {
Start,
Center,
End,
Between,
Other(S),
}
impl<S: BosStr> StackJustify<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 StackJustify<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for StackJustify<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for StackJustify<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 StackJustify<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 StackJustify<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for StackJustify<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = StackJustify<S::Output>;
fn into_static(self) -> Self::Output {
match self {
StackJustify::Start => StackJustify::Start,
StackJustify::Center => StackJustify::Center,
StackJustify::End => StackJustify::End,
StackJustify::Between => StackJustify::Between,
StackJustify::Other(v) => StackJustify::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StackOutput<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 StackResponse;
impl jacquard_common::xrpc::XrpcResp for StackResponse {
const NSID: &'static str = "org.atsui.Stack";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = StackOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Stack<S> {
const NSID: &'static str = "org.atsui.Stack";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = StackResponse;
}
pub struct StackRequest;
impl jacquard_common::xrpc::XrpcEndpoint for StackRequest {
const PATH: &'static str = "/xrpc/org.atsui.Stack";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = Stack<S>;
type Response = StackResponse;
}
pub mod stack_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<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 StackBuilder<S: BosStr, St: stack_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<StackAlign<S>>,
Option<Data<S>>,
Option<StackGap<S>>,
Option<bool>,
Option<StackJustify<S>>,
Option<bool>,
Option<bool>,
Option<bool>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Stack<S> {
pub fn new() -> StackBuilder<S, stack_state::Empty> {
StackBuilder::new()
}
}
impl<S: BosStr> StackBuilder<S, stack_state::Empty> {
pub fn new() -> Self {
StackBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: stack_state::State> StackBuilder<S, St> {
pub fn align(mut self, value: impl Into<Option<StackAlign<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_align(mut self, value: Option<StackAlign<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> StackBuilder<S, St>
where
St: stack_state::State,
St::Children: stack_state::IsUnset,
{
pub fn children(
mut self,
value: impl Into<Data<S>>,
) -> StackBuilder<S, stack_state::SetChildren<St>> {
self._fields.1 = Option::Some(value.into());
StackBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: stack_state::State> StackBuilder<S, St> {
pub fn gap(mut self, value: impl Into<Option<StackGap<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_gap(mut self, value: Option<StackGap<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: stack_state::State> StackBuilder<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: stack_state::State> StackBuilder<S, St> {
pub fn justify(mut self, value: impl Into<Option<StackJustify<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_justify(mut self, value: Option<StackJustify<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: stack_state::State> StackBuilder<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: stack_state::State> StackBuilder<S, St> {
pub fn separator(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_separator(mut self, value: Option<bool>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: stack_state::State> StackBuilder<S, St> {
pub fn sticky(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_sticky(mut self, value: Option<bool>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> StackBuilder<S, St>
where
St: stack_state::State,
St::Children: stack_state::IsSet,
{
pub fn build(self) -> Stack<S> {
Stack {
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,
separator: self._fields.6,
sticky: self._fields.7,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Stack<S> {
Stack {
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,
separator: self._fields.6,
sticky: self._fields.7,
extra_data: Some(extra_data),
}
}
}