gpui_macros: Extract border_style_methods macro (#14514)

This PR extracts a separate `border_style_methods` macro so that it can
be used independently from `style_helpers!`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-15 15:51:29 -04:00 committed by GitHub
parent fa3d29087d
commit 143035b1ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 37 deletions

View File

@ -5,8 +5,9 @@ use crate::{
SharedString, StyleRefinement, WhiteSpace, SharedString, StyleRefinement, WhiteSpace,
}; };
pub use gpui_macros::{ pub use gpui_macros::{
box_shadow_style_methods, cursor_style_methods, margin_style_methods, overflow_style_methods, border_style_methods, box_shadow_style_methods, cursor_style_methods, margin_style_methods,
padding_style_methods, position_style_methods, visibility_style_methods, overflow_style_methods, padding_style_methods, position_style_methods,
visibility_style_methods,
}; };
use taffy::style::{AlignContent, Display}; use taffy::style::{AlignContent, Display};
@ -23,6 +24,7 @@ pub trait Styled: Sized {
gpui_macros::position_style_methods!(); gpui_macros::position_style_methods!();
gpui_macros::overflow_style_methods!(); gpui_macros::overflow_style_methods!();
gpui_macros::cursor_style_methods!(); gpui_macros::cursor_style_methods!();
gpui_macros::border_style_methods!();
gpui_macros::box_shadow_style_methods!(); gpui_macros::box_shadow_style_methods!();
/// Sets the display type of the element to `block`. /// Sets the display type of the element to `block`.
@ -303,16 +305,6 @@ pub trait Styled: Sized {
self self
} }
/// Sets the border color of the element.
fn border_color<C>(mut self, border_color: C) -> Self
where
C: Into<Hsla>,
Self: Sized,
{
self.style().border_color = Some(border_color.into());
self
}
/// Get the text style that has been configured on this element. /// Get the text style that has been configured on this element.
fn text_style(&mut self) -> &mut Option<TextStyleRefinement> { fn text_style(&mut self) -> &mut Option<TextStyleRefinement> {
let style: &mut StyleRefinement = self.style(); let style: &mut StyleRefinement = self.style();

View File

@ -70,6 +70,12 @@ pub fn cursor_style_methods(input: TokenStream) -> TokenStream {
styles::cursor_style_methods(input) styles::cursor_style_methods(input)
} }
/// Generates methods for border styles.
#[proc_macro]
pub fn border_style_methods(input: TokenStream) -> TokenStream {
styles::border_style_methods(input)
}
/// Generates methods for box shadow styles. /// Generates methods for box shadow styles.
#[proc_macro] #[proc_macro]
pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream { pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream {

View File

@ -317,6 +317,55 @@ pub fn cursor_style_methods(input: TokenStream) -> TokenStream {
output.into() 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! {
/// Sets the border color of the element.
#visibility fn border_color<C>(mut self, border_color: C) -> Self
where
C: Into<Hsla>,
Self: Sized,
{
self.style().border_color = Some(border_color.into());
self
}
#(#methods)*
};
output.into()
}
pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream { pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as StyleableMacroInput); let input = parse_macro_input!(input as StyleableMacroInput);
let visibility = input.method_visibility; let visibility = input.method_visibility;
@ -564,31 +613,6 @@ fn generate_methods() -> Vec<TokenStream2> {
} }
} }
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,
),
));
}
}
methods methods
} }