mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
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:
parent
fa3d29087d
commit
143035b1ed
@ -5,8 +5,9 @@ use crate::{
|
||||
SharedString, StyleRefinement, WhiteSpace,
|
||||
};
|
||||
pub use gpui_macros::{
|
||||
box_shadow_style_methods, cursor_style_methods, margin_style_methods, overflow_style_methods,
|
||||
padding_style_methods, position_style_methods, visibility_style_methods,
|
||||
border_style_methods, box_shadow_style_methods, cursor_style_methods, margin_style_methods,
|
||||
overflow_style_methods, padding_style_methods, position_style_methods,
|
||||
visibility_style_methods,
|
||||
};
|
||||
use taffy::style::{AlignContent, Display};
|
||||
|
||||
@ -23,6 +24,7 @@ pub trait Styled: Sized {
|
||||
gpui_macros::position_style_methods!();
|
||||
gpui_macros::overflow_style_methods!();
|
||||
gpui_macros::cursor_style_methods!();
|
||||
gpui_macros::border_style_methods!();
|
||||
gpui_macros::box_shadow_style_methods!();
|
||||
|
||||
/// Sets the display type of the element to `block`.
|
||||
@ -303,16 +305,6 @@ pub trait Styled: Sized {
|
||||
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.
|
||||
fn text_style(&mut self) -> &mut Option<TextStyleRefinement> {
|
||||
let style: &mut StyleRefinement = self.style();
|
||||
|
@ -70,6 +70,12 @@ pub fn cursor_style_methods(input: TokenStream) -> TokenStream {
|
||||
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.
|
||||
#[proc_macro]
|
||||
pub fn box_shadow_style_methods(input: TokenStream) -> TokenStream {
|
||||
|
@ -317,6 +317,55 @@ pub fn cursor_style_methods(input: TokenStream) -> TokenStream {
|
||||
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 {
|
||||
let input = parse_macro_input!(input as StyleableMacroInput);
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user