Add negative style helpers

This commit is contained in:
Nathan Sobo 2023-09-18 20:47:40 -06:00
parent f2e87a3429
commit 2701be91e3
2 changed files with 38 additions and 15 deletions

View file

@ -44,7 +44,19 @@ fn generate_methods() -> Vec<TokenStream2> {
prefix,
suffix,
&fields,
length_tokens,
&length_tokens,
false,
doc_string,
));
}
if suffix != "auto" {
methods.push(generate_predefined_setter(
prefix,
suffix,
&fields,
&length_tokens,
true,
doc_string,
));
}
@ -63,7 +75,8 @@ fn generate_methods() -> Vec<TokenStream2> {
prefix,
suffix,
&fields,
radius_tokens,
&radius_tokens,
false,
doc_string,
));
}
@ -75,7 +88,8 @@ fn generate_methods() -> Vec<TokenStream2> {
prefix,
suffix,
&fields,
width_tokens,
&width_tokens,
false,
doc_string,
));
}
@ -84,23 +98,30 @@ fn generate_methods() -> Vec<TokenStream2> {
}
fn generate_predefined_setter(
prefix: &'static str,
suffix: &'static str,
name: &'static str,
length: &'static str,
fields: &Vec<TokenStream2>,
length_tokens: TokenStream2,
length_tokens: &TokenStream2,
negate: bool,
doc_string: &'static str,
) -> TokenStream2 {
let method_name = if suffix.is_empty() {
format_ident!("{}", prefix)
let (negation_prefix, negation_token) = if negate {
("neg_", quote! { - })
} else {
format_ident!("{}_{}", prefix, suffix)
("", quote! {})
};
let method_name = if length.is_empty() {
format_ident!("{}{}", negation_prefix, name)
} else {
format_ident!("{}{}_{}", negation_prefix, name, length)
};
let field_assignments = fields
.iter()
.map(|field_tokens| {
quote! {
style.#field_tokens = Some(gpui2::geometry::#length_tokens.into());
style.#field_tokens = Some((#negation_token gpui2::geometry::#length_tokens).into());
}
})
.collect::<Vec<_>>();
@ -114,6 +135,10 @@ fn generate_predefined_setter(
}
};
if negate {
dbg!(method.to_string());
}
method
}

View file

@ -1,6 +1,4 @@
use crate::theme::theme;
use crate::ui::Avatar;
use gpui2::geometry::rems;
use crate::{theme::theme, ui::Avatar};
use gpui2::style::StyleHelpers;
use gpui2::{elements::div, IntoElement};
use gpui2::{Element, ParentElement, ViewContext};
@ -19,9 +17,9 @@ impl Facepile {
let theme = theme(cx);
let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(ix, player)| {
let before_last = ix < player_count - 1;
let isnt_last = ix < player_count - 1;
div()
.when(before_last, |div| div.mr(-rems(0.5)))
.when(isnt_last, |div| div.neg_mr_1())
.child(player.clone())
});
div().p_1().flex().items_center().children(player_list)