use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use syn::{
Token, Visibility, braced,
parse::{Parse, ParseStream, Result},
parse_macro_input,
};
#[derive(Debug)]
struct StyleableMacroInput {
method_visibility: Visibility,
}
impl Parse for StyleableMacroInput {
fn parse(input: ParseStream) -> Result<Self> {
if !input.peek(syn::token::Brace) {
return Ok(Self {
method_visibility: Visibility::Inherited,
});
}
let content;
braced!(content in input);
let mut method_visibility = None;
let ident: syn::Ident = content.parse()?;
if ident == "visibility" {
let _colon: Token![:] = content.parse()?;
method_visibility = Some(content.parse()?);
}
Ok(Self {
method_visibility: method_visibility.unwrap_or(Visibility::Inherited),
})
}
}
pub fn style_helpers(input: TokenStream) -> TokenStream {
let _ = parse_macro_input!(input as StyleableMacroInput);
let methods = generate_methods();
let output = quote! {
#(#methods)*
};
output.into()
}
struct StyleTransitionSpec {
name: &'static str,
fields: Vec<StyleTransitionField>,
}
struct StyleTransitionField {
path: TokenStream2,
kind: StyleTransitionFieldKind,
}
struct CanonicalStyleTransitionField {
config_name: syn::Ident,
path: TokenStream2,
kind: StyleTransitionFieldKind,
}
#[derive(Clone, Copy, PartialEq, Eq)]
enum StyleTransitionFieldKind {
Required,
Optional,
InsetTop,
InsetRight,
InsetBottom,
InsetLeft,
AutoSizeWidth,
AutoSizeHeight,
CornerRadius,
}
impl StyleTransitionField {
fn required(path: TokenStream2) -> Self {
Self {
path,
kind: StyleTransitionFieldKind::Required,
}
}
fn optional(path: TokenStream2) -> Self {
Self {
path,
kind: StyleTransitionFieldKind::Optional,
}
}
fn required_or_special_length(path: TokenStream2) -> Self {
let kind = match style_transition_key(&path).as_str() {
"size.width" => StyleTransitionFieldKind::AutoSizeWidth,
"size.height" => StyleTransitionFieldKind::AutoSizeHeight,
"inset.top" => StyleTransitionFieldKind::InsetTop,
"inset.right" => StyleTransitionFieldKind::InsetRight,
"inset.bottom" => StyleTransitionFieldKind::InsetBottom,
"inset.left" => StyleTransitionFieldKind::InsetLeft,
_ => StyleTransitionFieldKind::Required,
};
Self { path, kind }
}
fn corner_radius(path: TokenStream2) -> Self {
Self {
path,
kind: StyleTransitionFieldKind::CornerRadius,
}
}
}
fn style_transition_key(path: &TokenStream2) -> String {
path.to_string().split_whitespace().collect()
}
fn style_transition_config_name(key: &str) -> syn::Ident {
format_ident!("transition_{}", key.replace('.', "_"))
}
fn canonical_style_transition_fields(
specs: &[StyleTransitionSpec],
) -> Vec<CanonicalStyleTransitionField> {
let mut fields = Vec::<CanonicalStyleTransitionField>::new();
let mut field_indices = std::collections::HashMap::<String, usize>::new();
let mut config_names = std::collections::HashMap::<String, String>::new();
for field in specs.iter().flat_map(|spec| &spec.fields) {
let key = style_transition_key(&field.path);
if let Some(index) = field_indices.get(&key).copied() {
let canonical = &fields[index];
if canonical.kind != field.kind {
panic!("style transition field `{key}` has conflicting metadata");
}
continue;
}
let config_name = style_transition_config_name(&key);
let config_name_string = config_name.to_string();
if let Some(existing_key) = config_names.insert(config_name_string.clone(), key.clone())
&& existing_key != key
{
panic!(
"style transition fields `{existing_key}` and `{key}` map to the same config field `{config_name_string}`"
);
}
field_indices.insert(key.clone(), fields.len());
fields.push(CanonicalStyleTransitionField {
config_name,
path: field.path.clone(),
kind: field.kind,
});
}
fields
}
pub fn style_transitions(input: TokenStream) -> TokenStream {
let _ = parse_macro_input!(input as StyleableMacroInput);
let specs = style_transition_specs();
let canonical_fields = canonical_style_transition_fields(&specs);
let config_fields = canonical_fields.iter().map(|field| {
let name = &field.config_name;
quote! {
#name: Option<crate::AnyMotion>
}
});
let builders = specs.iter().map(|spec| {
let name = format_ident!("{}", spec.name);
let config_names = spec
.fields
.iter()
.map(|field| style_transition_config_name(&style_transition_key(&field.path)));
quote! {
#[doc = concat!("Transitions changes made by [`Styled::", stringify!(#name), "`].")]
pub fn #name(mut self, motion: impl Into<crate::AnyMotion>) -> Self {
let motion = motion.into();
#(self.#config_names = Some(motion.clone());)*
self
}
}
});
let applications = canonical_fields.iter().map(generate_transition_application);
quote! {
#[derive(Default)]
pub struct StyleTransitions {
#(#config_fields,)*
}
impl StyleTransitions {
pub fn new() -> Self {
Self::default()
}
#(#builders)*
pub(crate) fn apply(
&self,
style: &mut crate::Style,
state: &mut StyleTransitionState,
context: StyleTransitionContext,
now: scheduler::Instant,
reduce_motion: bool,
) -> bool {
let mut in_progress = false;
#(#applications)*
in_progress
}
}
}
.into()
}
fn generate_transition_application(field: &CanonicalStyleTransitionField) -> TokenStream2 {
let motion_name = &field.config_name;
let path = &field.path;
match field.kind {
StyleTransitionFieldKind::Required => quote! {
in_progress |= apply_required(
&mut state.#path,
&mut style.#path,
self.#motion_name.as_ref(),
now,
reduce_motion,
);
},
StyleTransitionFieldKind::Optional => quote! {
in_progress |= apply_optional(
&mut state.#path,
&mut style.#path,
self.#motion_name.as_ref(),
now,
reduce_motion,
);
},
StyleTransitionFieldKind::InsetTop
| StyleTransitionFieldKind::InsetRight
| StyleTransitionFieldKind::InsetBottom
| StyleTransitionFieldKind::InsetLeft => {
let edge = match field.kind {
StyleTransitionFieldKind::InsetTop => quote! { StyleTransitionEdge::Top },
StyleTransitionFieldKind::InsetRight => quote! { StyleTransitionEdge::Right },
StyleTransitionFieldKind::InsetBottom => quote! { StyleTransitionEdge::Bottom },
StyleTransitionFieldKind::InsetLeft => quote! { StyleTransitionEdge::Left },
_ => unreachable!(),
};
quote! {
in_progress |= apply_inset(
&mut state.#path,
&mut style.#path,
#edge,
self.#motion_name.as_ref(),
context,
now,
reduce_motion,
);
}
}
StyleTransitionFieldKind::AutoSizeWidth => quote! {
in_progress |= apply_auto_size(
&mut state.#path,
&mut style.#path,
StyleTransitionAxis::Width,
self.#motion_name.as_ref(),
context,
now,
reduce_motion,
);
},
StyleTransitionFieldKind::AutoSizeHeight => quote! {
in_progress |= apply_auto_size(
&mut state.#path,
&mut style.#path,
StyleTransitionAxis::Height,
self.#motion_name.as_ref(),
context,
now,
reduce_motion,
);
},
StyleTransitionFieldKind::CornerRadius => quote! {
let target = context.bounds.map(|bounds| {
let max_corner_radius = std::cmp::min(
bounds.size.width,
bounds.size.height,
) / 2.0;
crate::AbsoluteLength::Pixels(std::cmp::min(
style.#path.to_pixels(context.rem_size),
max_corner_radius,
))
});
in_progress |= apply_required_target(
&mut state.#path,
&mut style.#path,
target,
self.#motion_name.as_ref(),
now,
reduce_motion,
);
},
}
}
fn style_transition_specs() -> Vec<StyleTransitionSpec> {
let mut specs = Vec::new();
for prefix in box_prefixes()
.into_iter()
.chain(margin_box_style_prefixes())
.chain(padding_box_style_prefixes())
.chain(position_box_style_prefixes())
{
specs.push(StyleTransitionSpec {
name: prefix.prefix,
fields: prefix
.fields
.into_iter()
.map(StyleTransitionField::required_or_special_length)
.collect(),
});
}
for prefix in corner_prefixes() {
specs.push(StyleTransitionSpec {
name: prefix.prefix,
fields: prefix
.fields
.into_iter()
.map(StyleTransitionField::corner_radius)
.collect(),
});
}
for prefix in border_prefixes() {
specs.push(StyleTransitionSpec {
name: prefix.prefix,
fields: prefix
.fields
.into_iter()
.map(StyleTransitionField::required)
.collect(),
});
}
specs.extend([
StyleTransitionSpec {
name: "scrollbar_width",
fields: vec![StyleTransitionField::required(quote! { scrollbar_width })],
},
StyleTransitionSpec {
name: "aspect_ratio",
fields: vec![StyleTransitionField::optional(quote! { aspect_ratio })],
},
StyleTransitionSpec {
name: "flex_basis",
fields: vec![StyleTransitionField::required(quote! { flex_basis })],
},
StyleTransitionSpec {
name: "flex_grow",
fields: vec![StyleTransitionField::required(quote! { flex_grow })],
},
StyleTransitionSpec {
name: "flex_shrink",
fields: vec![StyleTransitionField::required(quote! { flex_shrink })],
},
StyleTransitionSpec {
name: "bg",
fields: vec![StyleTransitionField::optional(quote! { background })],
},
StyleTransitionSpec {
name: "border_color",
fields: vec![StyleTransitionField::optional(quote! { border_color })],
},
StyleTransitionSpec {
name: "ring",
fields: vec![
StyleTransitionField::required(quote! { ring.width }),
StyleTransitionField::required(quote! { ring.color }),
],
},
StyleTransitionSpec {
name: "ring_color",
fields: vec![StyleTransitionField::required(quote! { ring.color })],
},
StyleTransitionSpec {
name: "inset_ring",
fields: vec![
StyleTransitionField::required(quote! { inset_ring.width }),
StyleTransitionField::required(quote! { inset_ring.color }),
],
},
StyleTransitionSpec {
name: "inset_ring_color",
fields: vec![StyleTransitionField::required(quote! { inset_ring.color })],
},
StyleTransitionSpec {
name: "text_color",
fields: vec![StyleTransitionField::optional(quote! { text.color })],
},
StyleTransitionSpec {
name: "text_bg",
fields: vec![StyleTransitionField::optional(
quote! { text.background_color },
)],
},
StyleTransitionSpec {
name: "text_size",
fields: vec![StyleTransitionField::optional(quote! { text.font_size })],
},
StyleTransitionSpec {
name: "line_height",
fields: vec![StyleTransitionField::optional(quote! { text.line_height })],
},
StyleTransitionSpec {
name: "letter_spacing",
fields: vec![StyleTransitionField::optional(
quote! { text.letter_spacing },
)],
},
StyleTransitionSpec {
name: "line_clamp",
fields: vec![StyleTransitionField::optional(quote! { text.line_clamp })],
},
StyleTransitionSpec {
name: "opacity",
fields: vec![StyleTransitionField::optional(quote! { opacity })],
},
StyleTransitionSpec {
name: "rounded_smoothing",
fields: vec![StyleTransitionField::optional(quote! { corner_smoothing })],
},
]);
specs
}
pub fn visibility_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let output = quote! {
#visibility fn visible(mut self) -> Self {
self.style().visibility = Some(gpui::Visibility::Visible);
self
}
#visibility fn invisible(mut self) -> Self {
self.style().visibility = Some(gpui::Visibility::Hidden);
self
}
};
output.into()
}
pub fn margin_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let methods = generate_box_style_methods(
margin_box_style_prefixes(),
box_style_suffixes(),
input.method_visibility,
);
let output = quote! {
#(#methods)*
};
output.into()
}
pub fn padding_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let methods = generate_box_style_methods(
padding_box_style_prefixes(),
box_style_suffixes(),
input.method_visibility,
);
let output = quote! {
#(#methods)*
};
output.into()
}
pub fn position_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let methods = generate_box_style_methods(
position_box_style_prefixes(),
box_style_suffixes(),
visibility.clone(),
);
let output = quote! {
#visibility fn relative(mut self) -> Self {
self.style().position = Some(gpui::Position::Relative);
self
}
#visibility fn absolute(mut self) -> Self {
self.style().position = Some(gpui::Position::Absolute);
self
}
#(#methods)*
};
output.into()
}
pub fn overflow_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let output = quote! {
#visibility fn overflow_hidden(mut self) -> Self {
self.style().overflow.x = Some(gpui::Overflow::Hidden);
self.style().overflow.y = Some(gpui::Overflow::Hidden);
self
}
#visibility fn overflow_x_hidden(mut self) -> Self {
self.style().overflow.x = Some(gpui::Overflow::Hidden);
self
}
#visibility fn overflow_y_hidden(mut self) -> Self {
self.style().overflow.y = Some(gpui::Overflow::Hidden);
self
}
};
output.into()
}
pub fn cursor_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let output = quote! {
#visibility fn cursor(mut self, cursor: CursorStyle) -> Self {
self.style().mouse_cursor = Some(cursor);
self
}
#visibility fn cursor_default(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::Arrow);
self
}
#visibility fn cursor_pointer(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::PointingHand);
self
}
#visibility fn cursor_text(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::IBeam);
self
}
#visibility fn cursor_move(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ClosedHand);
self
}
#visibility fn cursor_not_allowed(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::OperationNotAllowed);
self
}
#visibility fn cursor_context_menu(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ContextualMenu);
self
}
#visibility fn cursor_crosshair(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::Crosshair);
self
}
#visibility fn cursor_vertical_text(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::IBeamCursorForVerticalLayout);
self
}
#visibility fn cursor_alias(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::DragLink);
self
}
#visibility fn cursor_copy(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::DragCopy);
self
}
#visibility fn cursor_no_drop(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::OperationNotAllowed);
self
}
#visibility fn cursor_grab(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::OpenHand);
self
}
#visibility fn cursor_grabbing(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ClosedHand);
self
}
#visibility fn cursor_ew_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeLeftRight);
self
}
#visibility fn cursor_ns_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUpDown);
self
}
#visibility fn cursor_nesw_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUpRightDownLeft);
self
}
#visibility fn cursor_nwse_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUpLeftDownRight);
self
}
#visibility fn cursor_col_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeColumn);
self
}
#visibility fn cursor_row_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeRow);
self
}
#visibility fn cursor_n_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUp);
self
}
#visibility fn cursor_e_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeRight);
self
}
#visibility fn cursor_s_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeDown);
self
}
#visibility fn cursor_w_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeLeft);
self
}
#visibility fn cursor_nw_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUpLeft);
self
}
#visibility fn cursor_ne_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeUpRight);
self
}
#visibility fn cursor_sw_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeDownLeft);
self
}
#visibility fn cursor_se_resize(mut self) -> Self {
self.style().mouse_cursor = Some(gpui::CursorStyle::ResizeDownRight);
self
}
};
output.into()
}
pub fn border_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let mut methods = Vec::new();
for border_style_prefix in border_prefixes() {
methods.push(generate_custom_value_setter(
visibility.clone(),
border_style_prefix.prefix,
quote! { AbsoluteLength },
&border_style_prefix.fields,
border_style_prefix.doc_string_prefix,
));
for border_style_suffix in border_suffixes() {
methods.push(generate_predefined_setter(
visibility.clone(),
border_style_prefix.prefix,
border_style_suffix.suffix,
&border_style_prefix.fields,
&border_style_suffix.width_tokens,
false,
&format!(
"{prefix}\n\n{suffix}",
prefix = border_style_prefix.doc_string_prefix,
suffix = border_style_suffix.doc_string_suffix,
),
));
}
}
let output = quote! {
#visibility fn border_color<C>(mut self, border_color: C) -> Self
where
C: Into<gpui::Background>,
Self: Sized,
{
self.style().border_color = Some(border_color.into());
self
}
#(#methods)*
};
output.into()
}
pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility;
let ring_width_methods = border_suffixes()
.into_iter()
.filter(|suffix| matches!(suffix.suffix, "0" | "1" | "2" | "4" | "8"))
.flat_map(|suffix| {
let visibility = visibility.clone();
["ring", "inset_ring"].map(move |prefix| {
let visibility = visibility.clone();
let width = suffix.width_tokens.clone();
let method = format_ident!("{}_{}", prefix, suffix.suffix);
let field = format_ident!("{}", prefix);
quote! {
#[doc = concat!("Sets the ", #prefix, " width to ", stringify!(#width), ".")]
#visibility fn #method(mut self) -> Self {
use gpui::px;
self.style().#field.width = Some(#width);
self
}
}
})
});
let output = quote! {
#visibility fn shadow(mut self, shadows: std::vec::Vec<gpui::BoxShadow>) -> Self {
self.style().box_shadow = Some(shadows);
self
}
#visibility fn shadow_none(mut self) -> Self {
self.style().box_shadow = Some(Default::default());
self
}
#visibility fn ring(mut self, width: impl Into<gpui::Pixels>) -> Self {
self.style().ring.width = Some(width.into());
self
}
#visibility fn ring_color<C>(mut self, color: C) -> Self
where
C: Into<gpui::Background>,
Self: Sized,
{
self.style().ring.color = Some(gpui::RingColor::Color(color.into()));
self
}
#visibility fn inset_ring(mut self, width: impl Into<gpui::Pixels>) -> Self {
self.style().inset_ring.width = Some(width.into());
self
}
#visibility fn inset_ring_color<C>(mut self, color: C) -> Self
where
C: Into<gpui::Background>,
Self: Sized,
{
self.style().inset_ring.color = Some(gpui::RingColor::Color(color.into()));
self
}
#(#ring_width_methods)*
#visibility fn shadow_2xs(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(1.), hsla(0., 0., 0., 0.05))
]);
self
}
#visibility fn shadow_xs(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(1.), hsla(0., 0., 0., 0.05)).blur_radius(px(2.))
]);
self
}
#visibility fn shadow_sm(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(1.), hsla(0., 0., 0., 0.1)).blur_radius(px(3.)),
BoxShadow::new(px(0.), px(1.), hsla(0., 0., 0., 0.1)).blur_radius(px(2.)).spread_radius(px(-1.)),
]);
self
}
#visibility fn shadow_md(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(4.), hsla(0., 0., 0., 0.1)).blur_radius(px(6.)).spread_radius(px(-1.)),
BoxShadow::new(px(0.), px(2.), hsla(0., 0., 0., 0.1)).blur_radius(px(4.)).spread_radius(px(-2.)),
]);
self
}
#visibility fn shadow_lg(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(10.), hsla(0., 0., 0., 0.1)).blur_radius(px(15.)).spread_radius(px(-3.)),
BoxShadow::new(px(0.), px(4.), hsla(0., 0., 0., 0.1)).blur_radius(px(6.)).spread_radius(px(-4.)),
]);
self
}
#visibility fn shadow_xl(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(20.), hsla(0., 0., 0., 0.1)).blur_radius(px(25.)).spread_radius(px(-5.)),
BoxShadow::new(px(0.), px(8.), hsla(0., 0., 0., 0.1)).blur_radius(px(10.)).spread_radius(px(-6.)),
]);
self
}
#visibility fn shadow_2xl(mut self) -> Self {
use gpui::{BoxShadow, hsla, px};
use std::vec;
self.style().box_shadow = Some(vec![
BoxShadow::new(px(0.), px(25.), hsla(0., 0., 0., 0.25)).blur_radius(px(50.)).spread_radius(px(-12.))
]);
self
}
};
output.into()
}
struct BoxStylePrefix {
prefix: &'static str,
auto_allowed: bool,
fields: Vec<TokenStream2>,
doc_string_prefix: &'static str,
}
struct BoxStyleSuffix {
suffix: &'static str,
length_tokens: TokenStream2,
doc_string_suffix: &'static str,
}
struct CornerStylePrefix {
prefix: &'static str,
fields: Vec<TokenStream2>,
doc_string_prefix: &'static str,
}
struct CornerStyleSuffix {
suffix: &'static str,
radius_tokens: TokenStream2,
doc_string_suffix: &'static str,
}
struct CornerSmoothingStyleSuffix {
suffix: &'static str,
amount_tokens: TokenStream2,
doc_string: &'static str,
}
struct BorderStylePrefix {
prefix: &'static str,
fields: Vec<TokenStream2>,
doc_string_prefix: &'static str,
}
struct BorderStyleSuffix {
suffix: &'static str,
width_tokens: TokenStream2,
doc_string_suffix: &'static str,
}
fn generate_box_style_methods(
prefixes: Vec<BoxStylePrefix>,
suffixes: Vec<BoxStyleSuffix>,
visibility: Visibility,
) -> Vec<TokenStream2> {
let mut methods = Vec::new();
for box_style_prefix in prefixes {
methods.push(generate_custom_value_setter(
visibility.clone(),
box_style_prefix.prefix,
if box_style_prefix.auto_allowed {
quote! { Length }
} else {
quote! { DefiniteLength }
},
&box_style_prefix.fields,
box_style_prefix.doc_string_prefix,
));
for box_style_suffix in &suffixes {
if box_style_suffix.suffix != "auto" || box_style_prefix.auto_allowed {
methods.push(generate_predefined_setter(
visibility.clone(),
box_style_prefix.prefix,
box_style_suffix.suffix,
&box_style_prefix.fields,
&box_style_suffix.length_tokens,
false,
&format!(
"{prefix}\n\n{suffix}",
prefix = box_style_prefix.doc_string_prefix,
suffix = box_style_suffix.doc_string_suffix,
),
));
}
if box_style_suffix.suffix != "auto" {
methods.push(generate_predefined_setter(
visibility.clone(),
box_style_prefix.prefix,
box_style_suffix.suffix,
&box_style_prefix.fields,
&box_style_suffix.length_tokens,
true,
&format!(
"{prefix}\n\n{suffix}",
prefix = box_style_prefix.doc_string_prefix,
suffix = box_style_suffix.doc_string_suffix,
),
));
}
}
}
methods
}
fn generate_methods() -> Vec<TokenStream2> {
let visibility = Visibility::Inherited;
let mut methods =
generate_box_style_methods(box_prefixes(), box_style_suffixes(), visibility.clone());
for corner_style_prefix in corner_prefixes() {
methods.push(generate_custom_value_setter(
visibility.clone(),
corner_style_prefix.prefix,
quote! { AbsoluteLength },
&corner_style_prefix.fields,
corner_style_prefix.doc_string_prefix,
));
for corner_style_suffix in corner_suffixes() {
methods.push(generate_predefined_setter(
visibility.clone(),
corner_style_prefix.prefix,
corner_style_suffix.suffix,
&corner_style_prefix.fields,
&corner_style_suffix.radius_tokens,
false,
&format!(
"{prefix}\n\n{suffix}",
prefix = corner_style_prefix.doc_string_prefix,
suffix = corner_style_suffix.doc_string_suffix,
),
));
}
}
methods.extend(generate_corner_smoothing_methods(visibility));
methods
}
fn generate_corner_smoothing_methods(visibility: Visibility) -> Vec<TokenStream2> {
corner_smoothing_suffixes()
.into_iter()
.map(|suffix| {
let method_name = format_ident!("rounded_smoothing_{}", suffix.suffix);
let amount_tokens = suffix.amount_tokens;
let doc_string = suffix.doc_string;
quote! {
#[doc = #doc_string]
#visibility fn #method_name(mut self) -> Self {
self.style().corner_smoothing = Some(#amount_tokens);
self
}
}
})
.collect()
}
fn generate_predefined_setter(
visibility: Visibility,
name: &'static str,
length: &'static str,
fields: &[TokenStream2],
length_tokens: &TokenStream2,
negate: bool,
doc_string: &str,
) -> TokenStream2 {
let (negation_qualifier, negation_token) = if negate {
("_neg", quote! { - })
} else {
("", quote! {})
};
let method_name = if length.is_empty() {
format_ident!("{name}{negation_qualifier}")
} else {
format_ident!("{name}{negation_qualifier}_{length}")
};
let field_assignments = fields
.iter()
.map(|field_tokens| {
quote! {
style.#field_tokens = Some((#negation_token gpui::#length_tokens).into());
}
})
.collect::<Vec<_>>();
let method = quote! {
#[doc = #doc_string]
#visibility fn #method_name(mut self) -> Self {
let style = self.style();
#(#field_assignments)*
self
}
};
method
}
fn generate_custom_value_setter(
visibility: Visibility,
prefix: &str,
length_type: TokenStream2,
fields: &[TokenStream2],
doc_string: &str,
) -> TokenStream2 {
let method_name = format_ident!("{}", prefix);
let mut iter = fields.iter();
let last = iter.next_back().unwrap();
let field_assignments = iter
.map(|field_tokens| {
quote! {
style.#field_tokens = Some(length.clone().into());
}
})
.chain(std::iter::once(quote! {
style.#last = Some(length.into());
}))
.collect::<Vec<_>>();
let method = quote! {
#[doc = #doc_string]
#visibility fn #method_name(mut self, length: impl std::clone::Clone + Into<gpui::#length_type>) -> Self {
let style = self.style();
#(#field_assignments)*
self
}
};
method
}
fn margin_box_style_prefixes() -> Vec<BoxStylePrefix> {
vec![
BoxStylePrefix {
prefix: "m",
auto_allowed: true,
fields: vec![
quote! { margin.top },
quote! { margin.bottom },
quote! { margin.left },
quote! { margin.right },
],
doc_string_prefix: "Sets the margin of the element. [Docs](https://tailwindcss.com/docs/margin)",
},
BoxStylePrefix {
prefix: "mt",
auto_allowed: true,
fields: vec![quote! { margin.top }],
doc_string_prefix: "Sets the top margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-margin-to-a-single-side)",
},
BoxStylePrefix {
prefix: "mb",
auto_allowed: true,
fields: vec![quote! { margin.bottom }],
doc_string_prefix: "Sets the bottom margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-margin-to-a-single-side)",
},
BoxStylePrefix {
prefix: "my",
auto_allowed: true,
fields: vec![quote! { margin.top }, quote! { margin.bottom }],
doc_string_prefix: "Sets the vertical margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-vertical-margin)",
},
BoxStylePrefix {
prefix: "mx",
auto_allowed: true,
fields: vec![quote! { margin.left }, quote! { margin.right }],
doc_string_prefix: "Sets the horizontal margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-horizontal-margin)",
},
BoxStylePrefix {
prefix: "ml",
auto_allowed: true,
fields: vec![quote! { margin.left }],
doc_string_prefix: "Sets the left margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-margin-to-a-single-side)",
},
BoxStylePrefix {
prefix: "mr",
auto_allowed: true,
fields: vec![quote! { margin.right }],
doc_string_prefix: "Sets the right margin of the element. [Docs](https://tailwindcss.com/docs/margin#add-margin-to-a-single-side)",
},
]
}
fn padding_box_style_prefixes() -> Vec<BoxStylePrefix> {
vec![
BoxStylePrefix {
prefix: "p",
auto_allowed: false,
fields: vec![
quote! { padding.top },
quote! { padding.bottom },
quote! { padding.left },
quote! { padding.right },
],
doc_string_prefix: "Sets the padding of the element. [Docs](https://tailwindcss.com/docs/padding)",
},
BoxStylePrefix {
prefix: "pt",
auto_allowed: false,
fields: vec![quote! { padding.top }],
doc_string_prefix: "Sets the top padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-padding-to-a-single-side)",
},
BoxStylePrefix {
prefix: "pb",
auto_allowed: false,
fields: vec![quote! { padding.bottom }],
doc_string_prefix: "Sets the bottom padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-padding-to-a-single-side)",
},
BoxStylePrefix {
prefix: "px",
auto_allowed: false,
fields: vec![quote! { padding.left }, quote! { padding.right }],
doc_string_prefix: "Sets the horizontal padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-horizontal-padding)",
},
BoxStylePrefix {
prefix: "py",
auto_allowed: false,
fields: vec![quote! { padding.top }, quote! { padding.bottom }],
doc_string_prefix: "Sets the vertical padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-vertical-padding)",
},
BoxStylePrefix {
prefix: "pl",
auto_allowed: false,
fields: vec![quote! { padding.left }],
doc_string_prefix: "Sets the left padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-padding-to-a-single-side)",
},
BoxStylePrefix {
prefix: "pr",
auto_allowed: false,
fields: vec![quote! { padding.right }],
doc_string_prefix: "Sets the right padding of the element. [Docs](https://tailwindcss.com/docs/padding#add-padding-to-a-single-side)",
},
]
}
fn position_box_style_prefixes() -> Vec<BoxStylePrefix> {
vec![
BoxStylePrefix {
prefix: "inset",
auto_allowed: true,
fields: vec![
quote! { inset.top },
quote! { inset.right },
quote! { inset.bottom },
quote! { inset.left },
],
doc_string_prefix: "Sets the top, right, bottom, and left values of a positioned element. [Docs](https://tailwindcss.com/docs/top-right-bottom-left)",
},
BoxStylePrefix {
prefix: "top",
auto_allowed: true,
fields: vec![quote! { inset.top }],
doc_string_prefix: "Sets the top value of a positioned element. [Docs](https://tailwindcss.com/docs/top-right-bottom-left)",
},
BoxStylePrefix {
prefix: "bottom",
auto_allowed: true,
fields: vec![quote! { inset.bottom }],
doc_string_prefix: "Sets the bottom value of a positioned element. [Docs](https://tailwindcss.com/docs/top-right-bottom-left)",
},
BoxStylePrefix {
prefix: "left",
auto_allowed: true,
fields: vec![quote! { inset.left }],
doc_string_prefix: "Sets the left value of a positioned element. [Docs](https://tailwindcss.com/docs/top-right-bottom-left)",
},
BoxStylePrefix {
prefix: "right",
auto_allowed: true,
fields: vec![quote! { inset.right }],
doc_string_prefix: "Sets the right value of a positioned element. [Docs](https://tailwindcss.com/docs/top-right-bottom-left)",
},
]
}
fn box_prefixes() -> Vec<BoxStylePrefix> {
vec![
BoxStylePrefix {
prefix: "w",
auto_allowed: true,
fields: vec![quote! { size.width }],
doc_string_prefix: "Sets the width of the element. [Docs](https://tailwindcss.com/docs/width)",
},
BoxStylePrefix {
prefix: "h",
auto_allowed: true,
fields: vec![quote! { size.height }],
doc_string_prefix: "Sets the height of the element. [Docs](https://tailwindcss.com/docs/height)",
},
BoxStylePrefix {
prefix: "size",
auto_allowed: true,
fields: vec![quote! {size.width}, quote! {size.height}],
doc_string_prefix: "Sets the width and height of the element.",
},
BoxStylePrefix {
prefix: "min_size",
auto_allowed: true,
fields: vec![quote! {min_size.width}, quote! {min_size.height}],
doc_string_prefix: "Sets the minimum width and height of the element.",
},
BoxStylePrefix {
prefix: "min_w",
auto_allowed: true,
fields: vec![quote! { min_size.width }],
doc_string_prefix: "Sets the minimum width of the element. [Docs](https://tailwindcss.com/docs/min-width)",
},
BoxStylePrefix {
prefix: "min_h",
auto_allowed: true,
fields: vec![quote! { min_size.height }],
doc_string_prefix: "Sets the minimum height of the element. [Docs](https://tailwindcss.com/docs/min-height)",
},
BoxStylePrefix {
prefix: "max_size",
auto_allowed: true,
fields: vec![quote! {max_size.width}, quote! {max_size.height}],
doc_string_prefix: "Sets the maximum width and height of the element.",
},
BoxStylePrefix {
prefix: "max_w",
auto_allowed: true,
fields: vec![quote! { max_size.width }],
doc_string_prefix: "Sets the maximum width of the element. [Docs](https://tailwindcss.com/docs/max-width)",
},
BoxStylePrefix {
prefix: "max_h",
auto_allowed: true,
fields: vec![quote! { max_size.height }],
doc_string_prefix: "Sets the maximum height of the element. [Docs](https://tailwindcss.com/docs/max-height)",
},
BoxStylePrefix {
prefix: "gap",
auto_allowed: false,
fields: vec![quote! { gap.width }, quote! { gap.height }],
doc_string_prefix: "Sets the gap between rows and columns of a flex or grid container. [Docs](https://tailwindcss.com/docs/gap)",
},
BoxStylePrefix {
prefix: "gap_x",
auto_allowed: false,
fields: vec![quote! { gap.width }],
doc_string_prefix: "Sets the gap between columns of a flex or grid container. [Docs](https://tailwindcss.com/docs/gap#changing-row-and-column-gaps-independently)",
},
BoxStylePrefix {
prefix: "gap_y",
auto_allowed: false,
fields: vec![quote! { gap.height }],
doc_string_prefix: "Sets the gap between rows of a flex or grid container. [Docs](https://tailwindcss.com/docs/gap#changing-row-and-column-gaps-independently)",
},
]
}
fn box_style_suffixes() -> Vec<BoxStyleSuffix> {
vec![
BoxStyleSuffix {
suffix: "0",
length_tokens: quote! { px(0.) },
doc_string_suffix: "0px",
},
BoxStyleSuffix {
suffix: "0p5",
length_tokens: quote! { rems(0.125) },
doc_string_suffix: "0.125rem (2px at the default rem size)",
},
BoxStyleSuffix {
suffix: "1",
length_tokens: quote! { rems(0.25) },
doc_string_suffix: "0.25rem (4px at the default rem size)",
},
BoxStyleSuffix {
suffix: "1p5",
length_tokens: quote! { rems(0.375) },
doc_string_suffix: "0.375rem (6px at the default rem size)",
},
BoxStyleSuffix {
suffix: "2",
length_tokens: quote! { rems(0.5) },
doc_string_suffix: "0.5rem (8px at the default rem size)",
},
BoxStyleSuffix {
suffix: "2p5",
length_tokens: quote! { rems(0.625) },
doc_string_suffix: "0.625rem (10px at the default rem size)",
},
BoxStyleSuffix {
suffix: "3",
length_tokens: quote! { rems(0.75) },
doc_string_suffix: "0.75rem (12px at the default rem size)",
},
BoxStyleSuffix {
suffix: "3p5",
length_tokens: quote! { rems(0.875) },
doc_string_suffix: "0.875rem (14px at the default rem size)",
},
BoxStyleSuffix {
suffix: "4",
length_tokens: quote! { rems(1.) },
doc_string_suffix: "1rem (16px at the default rem size)",
},
BoxStyleSuffix {
suffix: "5",
length_tokens: quote! { rems(1.25) },
doc_string_suffix: "1.25rem (20px at the default rem size)",
},
BoxStyleSuffix {
suffix: "6",
length_tokens: quote! { rems(1.5) },
doc_string_suffix: "1.5rem (24px at the default rem size)",
},
BoxStyleSuffix {
suffix: "7",
length_tokens: quote! { rems(1.75) },
doc_string_suffix: "1.75rem (28px at the default rem size)",
},
BoxStyleSuffix {
suffix: "8",
length_tokens: quote! { rems(2.0) },
doc_string_suffix: "2rem (32px at the default rem size)",
},
BoxStyleSuffix {
suffix: "9",
length_tokens: quote! { rems(2.25) },
doc_string_suffix: "2.25rem (36px at the default rem size)",
},
BoxStyleSuffix {
suffix: "10",
length_tokens: quote! { rems(2.5) },
doc_string_suffix: "2.5rem (40px at the default rem size)",
},
BoxStyleSuffix {
suffix: "11",
length_tokens: quote! { rems(2.75) },
doc_string_suffix: "2.75rem (44px at the default rem size)",
},
BoxStyleSuffix {
suffix: "12",
length_tokens: quote! { rems(3.) },
doc_string_suffix: "3rem (48px at the default rem size)",
},
BoxStyleSuffix {
suffix: "16",
length_tokens: quote! { rems(4.) },
doc_string_suffix: "4rem (64px at the default rem size)",
},
BoxStyleSuffix {
suffix: "20",
length_tokens: quote! { rems(5.) },
doc_string_suffix: "5rem (80px at the default rem size)",
},
BoxStyleSuffix {
suffix: "24",
length_tokens: quote! { rems(6.) },
doc_string_suffix: "6rem (96px at the default rem size)",
},
BoxStyleSuffix {
suffix: "32",
length_tokens: quote! { rems(8.) },
doc_string_suffix: "8rem (128px at the default rem size)",
},
BoxStyleSuffix {
suffix: "40",
length_tokens: quote! { rems(10.) },
doc_string_suffix: "10rem (160px at the default rem size)",
},
BoxStyleSuffix {
suffix: "48",
length_tokens: quote! { rems(12.) },
doc_string_suffix: "12rem (192px at the default rem size)",
},
BoxStyleSuffix {
suffix: "56",
length_tokens: quote! { rems(14.) },
doc_string_suffix: "14rem (224px at the default rem size)",
},
BoxStyleSuffix {
suffix: "64",
length_tokens: quote! { rems(16.) },
doc_string_suffix: "16rem (256px at the default rem size)",
},
BoxStyleSuffix {
suffix: "72",
length_tokens: quote! { rems(18.) },
doc_string_suffix: "18rem (288px at the default rem size)",
},
BoxStyleSuffix {
suffix: "80",
length_tokens: quote! { rems(20.) },
doc_string_suffix: "20rem (320px at the default rem size)",
},
BoxStyleSuffix {
suffix: "96",
length_tokens: quote! { rems(24.) },
doc_string_suffix: "24rem (384px at the default rem size)",
},
BoxStyleSuffix {
suffix: "112",
length_tokens: quote! { rems(28.) },
doc_string_suffix: "28rem (448px at the default rem size)",
},
BoxStyleSuffix {
suffix: "128",
length_tokens: quote! { rems(32.) },
doc_string_suffix: "32rem (512px at the default rem size)",
},
BoxStyleSuffix {
suffix: "auto",
length_tokens: quote! { auto() },
doc_string_suffix: "Auto",
},
BoxStyleSuffix {
suffix: "px",
length_tokens: quote! { px(1.) },
doc_string_suffix: "1px",
},
BoxStyleSuffix {
suffix: "full",
length_tokens: quote! { relative(1.) },
doc_string_suffix: "100%",
},
BoxStyleSuffix {
suffix: "1_2",
length_tokens: quote! { relative(0.5) },
doc_string_suffix: "50% (1/2)",
},
BoxStyleSuffix {
suffix: "1_3",
length_tokens: quote! { relative(1./3.) },
doc_string_suffix: "33% (1/3)",
},
BoxStyleSuffix {
suffix: "2_3",
length_tokens: quote! { relative(2./3.) },
doc_string_suffix: "66% (2/3)",
},
BoxStyleSuffix {
suffix: "1_4",
length_tokens: quote! { relative(0.25) },
doc_string_suffix: "25% (1/4)",
},
BoxStyleSuffix {
suffix: "2_4",
length_tokens: quote! { relative(0.5) },
doc_string_suffix: "50% (2/4)",
},
BoxStyleSuffix {
suffix: "3_4",
length_tokens: quote! { relative(0.75) },
doc_string_suffix: "75% (3/4)",
},
BoxStyleSuffix {
suffix: "1_5",
length_tokens: quote! { relative(0.2) },
doc_string_suffix: "20% (1/5)",
},
BoxStyleSuffix {
suffix: "2_5",
length_tokens: quote! { relative(0.4) },
doc_string_suffix: "40% (2/5)",
},
BoxStyleSuffix {
suffix: "3_5",
length_tokens: quote! { relative(0.6) },
doc_string_suffix: "60% (3/5)",
},
BoxStyleSuffix {
suffix: "4_5",
length_tokens: quote! { relative(0.8) },
doc_string_suffix: "80% (4/5)",
},
BoxStyleSuffix {
suffix: "1_6",
length_tokens: quote! { relative(1./6.) },
doc_string_suffix: "16% (1/6)",
},
BoxStyleSuffix {
suffix: "5_6",
length_tokens: quote! { relative(5./6.) },
doc_string_suffix: "83% (5/6)",
},
BoxStyleSuffix {
suffix: "1_12",
length_tokens: quote! { relative(1./12.) },
doc_string_suffix: "8% (1/12)",
},
]
}
fn corner_prefixes() -> Vec<CornerStylePrefix> {
vec![
CornerStylePrefix {
prefix: "rounded",
fields: vec![
quote! { corner_radii.top_left },
quote! { corner_radii.top_right },
quote! { corner_radii.bottom_right },
quote! { corner_radii.bottom_left },
],
doc_string_prefix: "Sets the border radius of the element. [Docs](https://tailwindcss.com/docs/border-radius)",
},
CornerStylePrefix {
prefix: "rounded_t",
fields: vec![
quote! { corner_radii.top_left },
quote! { corner_radii.top_right },
],
doc_string_prefix: "Sets the border radius of the top side of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-sides-separately)",
},
CornerStylePrefix {
prefix: "rounded_b",
fields: vec![
quote! { corner_radii.bottom_left },
quote! { corner_radii.bottom_right },
],
doc_string_prefix: "Sets the border radius of the bottom side of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-sides-separately)",
},
CornerStylePrefix {
prefix: "rounded_r",
fields: vec![
quote! { corner_radii.top_right },
quote! { corner_radii.bottom_right },
],
doc_string_prefix: "Sets the border radius of the right side of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-sides-separately)",
},
CornerStylePrefix {
prefix: "rounded_l",
fields: vec![
quote! { corner_radii.top_left },
quote! { corner_radii.bottom_left },
],
doc_string_prefix: "Sets the border radius of the left side of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-sides-separately)",
},
CornerStylePrefix {
prefix: "rounded_tl",
fields: vec![quote! { corner_radii.top_left }],
doc_string_prefix: "Sets the border radius of the top left corner of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-corners-separately)",
},
CornerStylePrefix {
prefix: "rounded_tr",
fields: vec![quote! { corner_radii.top_right }],
doc_string_prefix: "Sets the border radius of the top right corner of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-corners-separately)",
},
CornerStylePrefix {
prefix: "rounded_bl",
fields: vec![quote! { corner_radii.bottom_left }],
doc_string_prefix: "Sets the border radius of the bottom left corner of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-corners-separately)",
},
CornerStylePrefix {
prefix: "rounded_br",
fields: vec![quote! { corner_radii.bottom_right }],
doc_string_prefix: "Sets the border radius of the bottom right corner of the element. [Docs](https://tailwindcss.com/docs/border-radius#rounding-corners-separately)",
},
]
}
fn corner_suffixes() -> Vec<CornerStyleSuffix> {
vec![
CornerStyleSuffix {
suffix: "none",
radius_tokens: quote! { px(0.) },
doc_string_suffix: "0px",
},
CornerStyleSuffix {
suffix: "xs",
radius_tokens: quote! { rems(0.125) },
doc_string_suffix: "0.125rem (2px at the default rem size)",
},
CornerStyleSuffix {
suffix: "sm",
radius_tokens: quote! { rems(0.25) },
doc_string_suffix: "0.25rem (4px at the default rem size)",
},
CornerStyleSuffix {
suffix: "md",
radius_tokens: quote! { rems(0.375) },
doc_string_suffix: "0.375rem (6px at the default rem size)",
},
CornerStyleSuffix {
suffix: "lg",
radius_tokens: quote! { rems(0.5) },
doc_string_suffix: "0.5rem (8px at the default rem size)",
},
CornerStyleSuffix {
suffix: "xl",
radius_tokens: quote! { rems(0.75) },
doc_string_suffix: "0.75rem (12px at the default rem size)",
},
CornerStyleSuffix {
suffix: "2xl",
radius_tokens: quote! { rems(1.) },
doc_string_suffix: "1rem (16px at the default rem size)",
},
CornerStyleSuffix {
suffix: "3xl",
radius_tokens: quote! { rems(1.5) },
doc_string_suffix: "1.5rem (24px at the default rem size)",
},
CornerStyleSuffix {
suffix: "full",
radius_tokens: quote! { px(9999.) },
doc_string_suffix: "9999px (fully rounded)",
},
]
}
fn corner_smoothing_suffixes() -> Vec<CornerSmoothingStyleSuffix> {
vec![
CornerSmoothingStyleSuffix {
suffix: "0",
amount_tokens: quote! { 0.0 },
doc_string: "Keeps circular corners by setting rounded corner smoothing to `0.0`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p1",
amount_tokens: quote! { 0.1 },
doc_string: "Sets rounded corner smoothing to `0.1`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p2",
amount_tokens: quote! { 0.2 },
doc_string: "Sets rounded corner smoothing to `0.2`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p3",
amount_tokens: quote! { 0.3 },
doc_string: "Sets rounded corner smoothing to `0.3`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p4",
amount_tokens: quote! { 0.4 },
doc_string: "Sets rounded corner smoothing to `0.4`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p5",
amount_tokens: quote! { 0.5 },
doc_string: "Sets rounded corner smoothing to `0.5`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p6",
amount_tokens: quote! { 0.6 },
doc_string: "Sets rounded corner smoothing to `0.6`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p7",
amount_tokens: quote! { 0.7 },
doc_string: "Sets rounded corner smoothing to `0.7`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p8",
amount_tokens: quote! { 0.8 },
doc_string: "Sets rounded corner smoothing to `0.8`.",
},
CornerSmoothingStyleSuffix {
suffix: "0p9",
amount_tokens: quote! { 0.9 },
doc_string: "Sets rounded corner smoothing to `0.9`.",
},
CornerSmoothingStyleSuffix {
suffix: "1",
amount_tokens: quote! { 1.0 },
doc_string: "Requests maximum rounded corner smoothing by setting it to `1.0`.",
},
]
}
fn border_prefixes() -> Vec<BorderStylePrefix> {
vec![
BorderStylePrefix {
prefix: "border",
fields: vec![
quote! { border_widths.top },
quote! { border_widths.right },
quote! { border_widths.bottom },
quote! { border_widths.left },
],
doc_string_prefix: "Sets the border width of the element. [Docs](https://tailwindcss.com/docs/border-width)",
},
BorderStylePrefix {
prefix: "border_t",
fields: vec![quote! { border_widths.top }],
doc_string_prefix: "Sets the border width of the top side of the element. [Docs](https://tailwindcss.com/docs/border-width#individual-sides)",
},
BorderStylePrefix {
prefix: "border_b",
fields: vec![quote! { border_widths.bottom }],
doc_string_prefix: "Sets the border width of the bottom side of the element. [Docs](https://tailwindcss.com/docs/border-width#individual-sides)",
},
BorderStylePrefix {
prefix: "border_r",
fields: vec![quote! { border_widths.right }],
doc_string_prefix: "Sets the border width of the right side of the element. [Docs](https://tailwindcss.com/docs/border-width#individual-sides)",
},
BorderStylePrefix {
prefix: "border_l",
fields: vec![quote! { border_widths.left }],
doc_string_prefix: "Sets the border width of the left side of the element. [Docs](https://tailwindcss.com/docs/border-width#individual-sides)",
},
BorderStylePrefix {
prefix: "border_x",
fields: vec![
quote! { border_widths.left },
quote! { border_widths.right },
],
doc_string_prefix: "Sets the border width of the vertical sides of the element. [Docs](https://tailwindcss.com/docs/border-width#horizontal-and-vertical-sides)",
},
BorderStylePrefix {
prefix: "border_y",
fields: vec![
quote! { border_widths.top },
quote! { border_widths.bottom },
],
doc_string_prefix: "Sets the border width of the horizontal sides of the element. [Docs](https://tailwindcss.com/docs/border-width#horizontal-and-vertical-sides)",
},
]
}
fn border_suffixes() -> Vec<BorderStyleSuffix> {
vec![
BorderStyleSuffix {
suffix: "0",
width_tokens: quote! { px(0.)},
doc_string_suffix: "0px",
},
BorderStyleSuffix {
suffix: "1",
width_tokens: quote! { px(1.) },
doc_string_suffix: "1px",
},
BorderStyleSuffix {
suffix: "2",
width_tokens: quote! { px(2.) },
doc_string_suffix: "2px",
},
BorderStyleSuffix {
suffix: "3",
width_tokens: quote! { px(3.) },
doc_string_suffix: "3px",
},
BorderStyleSuffix {
suffix: "4",
width_tokens: quote! { px(4.) },
doc_string_suffix: "4px",
},
BorderStyleSuffix {
suffix: "5",
width_tokens: quote! { px(5.) },
doc_string_suffix: "5px",
},
BorderStyleSuffix {
suffix: "6",
width_tokens: quote! { px(6.) },
doc_string_suffix: "6px",
},
BorderStyleSuffix {
suffix: "7",
width_tokens: quote! { px(7.) },
doc_string_suffix: "7px",
},
BorderStyleSuffix {
suffix: "8",
width_tokens: quote! { px(8.) },
doc_string_suffix: "8px",
},
BorderStyleSuffix {
suffix: "9",
width_tokens: quote! { px(9.) },
doc_string_suffix: "9px",
},
BorderStyleSuffix {
suffix: "10",
width_tokens: quote! { px(10.) },
doc_string_suffix: "10px",
},
BorderStyleSuffix {
suffix: "11",
width_tokens: quote! { px(11.) },
doc_string_suffix: "11px",
},
BorderStyleSuffix {
suffix: "12",
width_tokens: quote! { px(12.) },
doc_string_suffix: "12px",
},
BorderStyleSuffix {
suffix: "16",
width_tokens: quote! { px(16.) },
doc_string_suffix: "16px",
},
BorderStyleSuffix {
suffix: "20",
width_tokens: quote! { px(20.) },
doc_string_suffix: "20px",
},
BorderStyleSuffix {
suffix: "24",
width_tokens: quote! { px(24.) },
doc_string_suffix: "24px",
},
BorderStyleSuffix {
suffix: "32",
width_tokens: quote! { px(32.) },
doc_string_suffix: "32px",
},
]
}