Checkpoint
This commit is contained in:
parent
a5e4ceb735
commit
c7a3186d08
4 changed files with 45 additions and 43 deletions
|
@ -194,8 +194,8 @@ where
|
||||||
impl Size<DefiniteLength> {
|
impl Size<DefiniteLength> {
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: pixels(0.),
|
width: pixels(0.).into(),
|
||||||
height: pixels(0.),
|
height: pixels(0.).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,10 +258,10 @@ impl Edges<Length> {
|
||||||
|
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Self {
|
Self {
|
||||||
top: pixels(0.),
|
top: pixels(0.).into(),
|
||||||
right: pixels(0.),
|
right: pixels(0.).into(),
|
||||||
bottom: pixels(0.),
|
bottom: pixels(0.).into(),
|
||||||
left: pixels(0.),
|
left: pixels(0.).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,10 +281,10 @@ impl Edges<Length> {
|
||||||
impl Edges<DefiniteLength> {
|
impl Edges<DefiniteLength> {
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Self {
|
Self {
|
||||||
top: pixels(0.),
|
top: pixels(0.).into(),
|
||||||
right: pixels(0.),
|
right: pixels(0.).into(),
|
||||||
bottom: pixels(0.),
|
bottom: pixels(0.).into(),
|
||||||
left: pixels(0.),
|
left: pixels(0.).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,16 +430,16 @@ impl std::fmt::Debug for Length {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn relative<T: From<DefiniteLength>>(fraction: f32) -> T {
|
pub fn relative(fraction: f32) -> DefiniteLength {
|
||||||
DefiniteLength::Relative(fraction).into()
|
DefiniteLength::Relative(fraction)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rems<T: From<AbsoluteLength>>(rems: f32) -> T {
|
pub fn rems(rems: f32) -> AbsoluteLength {
|
||||||
AbsoluteLength::Rems(rems).into()
|
AbsoluteLength::Rems(rems)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pixels<T: From<AbsoluteLength>>(pixels: f32) -> T {
|
pub fn pixels(pixels: f32) -> AbsoluteLength {
|
||||||
AbsoluteLength::Pixels(pixels).into()
|
AbsoluteLength::Pixels(pixels)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auto() -> Length {
|
pub fn auto() -> Length {
|
||||||
|
|
|
@ -328,8 +328,8 @@ pub trait StyleHelpers: Styleable<Style = Style> {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
self.declared_style().size.width = Some(relative(1.));
|
self.declared_style().size.width = Some(relative(1.).into());
|
||||||
self.declared_style().size.height = Some(relative(1.));
|
self.declared_style().size.height = Some(relative(1.).into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ pub trait StyleHelpers: Styleable<Style = Style> {
|
||||||
{
|
{
|
||||||
self.declared_style().flex_grow = Some(1.);
|
self.declared_style().flex_grow = Some(1.);
|
||||||
self.declared_style().flex_shrink = 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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ fn generate_methods() -> Vec<TokenStream2> {
|
||||||
let mut methods = Vec::new();
|
let mut methods = Vec::new();
|
||||||
|
|
||||||
for (prefix, auto_allowed, fields) in box_prefixes() {
|
for (prefix, auto_allowed, fields) in box_prefixes() {
|
||||||
methods.push(generate_method_with_parameter(
|
methods.push(generate_custom_value_setter(
|
||||||
prefix,
|
prefix,
|
||||||
if auto_allowed {
|
if auto_allowed {
|
||||||
quote! { Length }
|
quote! { Length }
|
||||||
|
@ -40,7 +40,7 @@ fn generate_methods() -> Vec<TokenStream2> {
|
||||||
|
|
||||||
for (suffix, length_tokens, doc_string) in box_suffixes() {
|
for (suffix, length_tokens, doc_string) in box_suffixes() {
|
||||||
if suffix != "auto" || auto_allowed {
|
if suffix != "auto" || auto_allowed {
|
||||||
methods.push(generate_method(
|
methods.push(generate_predefined_setter(
|
||||||
prefix,
|
prefix,
|
||||||
suffix,
|
suffix,
|
||||||
&fields,
|
&fields,
|
||||||
|
@ -52,14 +52,14 @@ fn generate_methods() -> Vec<TokenStream2> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (prefix, fields) in corner_prefixes() {
|
for (prefix, fields) in corner_prefixes() {
|
||||||
methods.push(generate_method_with_parameter(
|
methods.push(generate_custom_value_setter(
|
||||||
prefix,
|
prefix,
|
||||||
quote! { AbsoluteLength },
|
quote! { AbsoluteLength },
|
||||||
&fields,
|
&fields,
|
||||||
));
|
));
|
||||||
|
|
||||||
for (suffix, radius_tokens, doc_string) in corner_suffixes() {
|
for (suffix, radius_tokens, doc_string) in corner_suffixes() {
|
||||||
methods.push(generate_method(
|
methods.push(generate_predefined_setter(
|
||||||
prefix,
|
prefix,
|
||||||
suffix,
|
suffix,
|
||||||
&fields,
|
&fields,
|
||||||
|
@ -71,7 +71,7 @@ fn generate_methods() -> Vec<TokenStream2> {
|
||||||
|
|
||||||
for (prefix, fields) in border_prefixes() {
|
for (prefix, fields) in border_prefixes() {
|
||||||
for (suffix, width_tokens, doc_string) in border_suffixes() {
|
for (suffix, width_tokens, doc_string) in border_suffixes() {
|
||||||
methods.push(generate_method(
|
methods.push(generate_predefined_setter(
|
||||||
prefix,
|
prefix,
|
||||||
suffix,
|
suffix,
|
||||||
&fields,
|
&fields,
|
||||||
|
@ -83,7 +83,7 @@ fn generate_methods() -> Vec<TokenStream2> {
|
||||||
methods
|
methods
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_method(
|
fn generate_predefined_setter(
|
||||||
prefix: &'static str,
|
prefix: &'static str,
|
||||||
suffix: &'static str,
|
suffix: &'static str,
|
||||||
fields: &Vec<TokenStream2>,
|
fields: &Vec<TokenStream2>,
|
||||||
|
@ -100,7 +100,7 @@ fn generate_method(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field_tokens| {
|
.map(|field_tokens| {
|
||||||
quote! {
|
quote! {
|
||||||
style.#field_tokens = Some(gpui2::geometry::#length_tokens);
|
style.#field_tokens = Some(gpui2::geometry::#length_tokens.into());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -117,24 +117,28 @@ fn generate_method(
|
||||||
method
|
method
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_method_with_parameter(
|
fn generate_custom_value_setter(
|
||||||
prefix: &'static str,
|
prefix: &'static str,
|
||||||
length_type: TokenStream2,
|
length_type: TokenStream2,
|
||||||
fields: &Vec<TokenStream2>,
|
fields: &Vec<TokenStream2>,
|
||||||
) -> TokenStream2 {
|
) -> TokenStream2 {
|
||||||
let method_name = format_ident!("{}", prefix);
|
let method_name = format_ident!("{}", prefix);
|
||||||
|
|
||||||
let field_assignments = fields
|
let mut iter = fields.into_iter();
|
||||||
.iter()
|
let last = iter.next_back().unwrap();
|
||||||
|
let field_assignments = iter
|
||||||
.map(|field_tokens| {
|
.map(|field_tokens| {
|
||||||
quote! {
|
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<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let method = quote! {
|
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();
|
let mut style = self.declared_style();
|
||||||
#(#field_assignments)*
|
#(#field_assignments)*
|
||||||
self
|
self
|
||||||
|
|
|
@ -17,17 +17,15 @@ pub fn facepile(players: Vec<Avatar>) -> Facepile {
|
||||||
impl Facepile {
|
impl Facepile {
|
||||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
let player_list = self
|
let player_count = self.players.len();
|
||||||
.players
|
let player_list = self.players.iter().enumerate().map(|(i, player)| {
|
||||||
.iter()
|
let element = div().child(player.clone());
|
||||||
.map(|player| div().right_1().child(player.clone()));
|
if i < player_count - 1 {
|
||||||
|
element.mr(-rems(0.5))
|
||||||
div()
|
} else {
|
||||||
.relative()
|
element
|
||||||
.p_1()
|
}
|
||||||
.mx(rems(-0.125))
|
});
|
||||||
.flex()
|
div().p_1().flex().items_center().children(player_list)
|
||||||
.items_center()
|
|
||||||
.children(player_list)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue