Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-18 20:17:27 -06:00
parent a5e4ceb735
commit c7a3186d08
4 changed files with 45 additions and 43 deletions

View File

@ -194,8 +194,8 @@ where
impl Size<DefiniteLength> {
pub fn zero() -> Self {
Self {
width: pixels(0.),
height: pixels(0.),
width: pixels(0.).into(),
height: pixels(0.).into(),
}
}
@ -258,10 +258,10 @@ impl Edges<Length> {
pub fn zero() -> Self {
Self {
top: pixels(0.),
right: pixels(0.),
bottom: pixels(0.),
left: pixels(0.),
top: pixels(0.).into(),
right: pixels(0.).into(),
bottom: pixels(0.).into(),
left: pixels(0.).into(),
}
}
@ -281,10 +281,10 @@ impl Edges<Length> {
impl Edges<DefiniteLength> {
pub fn zero() -> Self {
Self {
top: pixels(0.),
right: pixels(0.),
bottom: pixels(0.),
left: pixels(0.),
top: pixels(0.).into(),
right: pixels(0.).into(),
bottom: pixels(0.).into(),
left: pixels(0.).into(),
}
}
@ -430,16 +430,16 @@ impl std::fmt::Debug for Length {
}
}
pub fn relative<T: From<DefiniteLength>>(fraction: f32) -> T {
DefiniteLength::Relative(fraction).into()
pub fn relative(fraction: f32) -> DefiniteLength {
DefiniteLength::Relative(fraction)
}
pub fn rems<T: From<AbsoluteLength>>(rems: f32) -> T {
AbsoluteLength::Rems(rems).into()
pub fn rems(rems: f32) -> AbsoluteLength {
AbsoluteLength::Rems(rems)
}
pub fn pixels<T: From<AbsoluteLength>>(pixels: f32) -> T {
AbsoluteLength::Pixels(pixels).into()
pub fn pixels(pixels: f32) -> AbsoluteLength {
AbsoluteLength::Pixels(pixels)
}
pub fn auto() -> Length {

View File

@ -328,8 +328,8 @@ pub trait StyleHelpers: Styleable<Style = Style> {
where
Self: Sized,
{
self.declared_style().size.width = Some(relative(1.));
self.declared_style().size.height = Some(relative(1.));
self.declared_style().size.width = Some(relative(1.).into());
self.declared_style().size.height = Some(relative(1.).into());
self
}
@ -387,7 +387,7 @@ pub trait StyleHelpers: Styleable<Style = Style> {
{
self.declared_style().flex_grow = Some(1.);
self.declared_style().flex_shrink = Some(1.);
self.declared_style().flex_basis = Some(relative(0.));
self.declared_style().flex_basis = Some(relative(0.).into());
self
}

View File

@ -28,7 +28,7 @@ fn generate_methods() -> Vec<TokenStream2> {
let mut methods = Vec::new();
for (prefix, auto_allowed, fields) in box_prefixes() {
methods.push(generate_method_with_parameter(
methods.push(generate_custom_value_setter(
prefix,
if auto_allowed {
quote! { Length }
@ -40,7 +40,7 @@ fn generate_methods() -> Vec<TokenStream2> {
for (suffix, length_tokens, doc_string) in box_suffixes() {
if suffix != "auto" || auto_allowed {
methods.push(generate_method(
methods.push(generate_predefined_setter(
prefix,
suffix,
&fields,
@ -52,14 +52,14 @@ fn generate_methods() -> Vec<TokenStream2> {
}
for (prefix, fields) in corner_prefixes() {
methods.push(generate_method_with_parameter(
methods.push(generate_custom_value_setter(
prefix,
quote! { AbsoluteLength },
&fields,
));
for (suffix, radius_tokens, doc_string) in corner_suffixes() {
methods.push(generate_method(
methods.push(generate_predefined_setter(
prefix,
suffix,
&fields,
@ -71,7 +71,7 @@ fn generate_methods() -> Vec<TokenStream2> {
for (prefix, fields) in border_prefixes() {
for (suffix, width_tokens, doc_string) in border_suffixes() {
methods.push(generate_method(
methods.push(generate_predefined_setter(
prefix,
suffix,
&fields,
@ -83,7 +83,7 @@ fn generate_methods() -> Vec<TokenStream2> {
methods
}
fn generate_method(
fn generate_predefined_setter(
prefix: &'static str,
suffix: &'static str,
fields: &Vec<TokenStream2>,
@ -100,7 +100,7 @@ fn generate_method(
.iter()
.map(|field_tokens| {
quote! {
style.#field_tokens = Some(gpui2::geometry::#length_tokens);
style.#field_tokens = Some(gpui2::geometry::#length_tokens.into());
}
})
.collect::<Vec<_>>();
@ -117,24 +117,28 @@ fn generate_method(
method
}
fn generate_method_with_parameter(
fn generate_custom_value_setter(
prefix: &'static str,
length_type: TokenStream2,
fields: &Vec<TokenStream2>,
) -> TokenStream2 {
let method_name = format_ident!("{}", prefix);
let field_assignments = fields
.iter()
let mut iter = fields.into_iter();
let last = iter.next_back().unwrap();
let field_assignments = iter
.map(|field_tokens| {
quote! {
style.#field_tokens = Some(length);
style.#field_tokens = Some(length.clone().into());
}
})
.chain(std::iter::once(quote! {
style.#last = Some(length.into());
}))
.collect::<Vec<_>>();
let method = quote! {
fn #method_name(mut self, length: gpui2::geometry::#length_type) -> Self where Self: std::marker::Sized {
fn #method_name(mut self, length: impl std::clone::Clone + Into<gpui2::geometry::#length_type>) -> Self where Self: std::marker::Sized {
let mut style = self.declared_style();
#(#field_assignments)*
self

View File

@ -17,17 +17,15 @@ pub fn facepile(players: Vec<Avatar>) -> Facepile {
impl Facepile {
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
let theme = theme(cx);
let player_list = self
.players
.iter()
.map(|player| div().right_1().child(player.clone()));
div()
.relative()
.p_1()
.mx(rems(-0.125))
.flex()
.items_center()
.children(player_list)
let player_count = self.players.len();
let player_list = self.players.iter().enumerate().map(|(i, player)| {
let element = div().child(player.clone());
if i < player_count - 1 {
element.mr(-rems(0.5))
} else {
element
}
});
div().p_1().flex().items_center().children(player_list)
}
}