mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
Add negative style helpers
This commit is contained in:
parent
f2e87a3429
commit
2701be91e3
2 changed files with 38 additions and 15 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue