diff --git a/Cargo.lock b/Cargo.lock index 1c34050c7c..6d0071e860 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3363,7 +3363,7 @@ dependencies = [ "font-kit", "foreign-types 0.3.2", "futures 0.3.28", - "gpui2_macros", + "gpui3_macros", "gpui_macros", "image", "itertools", @@ -3405,6 +3405,15 @@ dependencies = [ "wgpu", ] +[[package]] +name = "gpui3_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "gpui_macros" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 4a9606ffa1..c085a609a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ members = [ "crates/gpui2", "crates/gpui2_macros", "crates/gpui3", + "crates/gpui3_macros", "crates/install_cli", "crates/journal", "crates/language", diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index b4e57df4e6..1f881db7ee 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -203,8 +203,8 @@ where impl Size { pub fn zero() -> Self { Self { - width: pixels(0.), - height: pixels(0.), + width: px(0.), + height: px(0.), } } @@ -256,10 +256,10 @@ impl Edges { pub fn zero() -> Self { Self { - top: pixels(0.), - right: pixels(0.), - bottom: pixels(0.), - left: pixels(0.), + top: px(0.), + right: px(0.), + bottom: px(0.), + left: px(0.), } } @@ -279,10 +279,10 @@ impl Edges { impl Edges { pub fn zero() -> Self { Self { - top: pixels(0.), - right: pixels(0.), - bottom: pixels(0.), - left: pixels(0.), + top: px(0.), + right: px(0.), + bottom: px(0.), + left: px(0.), } } @@ -299,10 +299,10 @@ impl Edges { impl Edges { pub fn zero() -> Self { Self { - top: pixels(0.), - right: pixels(0.), - bottom: pixels(0.), - left: pixels(0.), + top: px(0.), + right: px(0.), + bottom: px(0.), + left: px(0.), } } @@ -436,6 +436,10 @@ pub fn rems>(rems: f32) -> T { AbsoluteLength::Rems(rems).into() } +pub fn px>(pixels: f32) -> T { + AbsoluteLength::Pixels(pixels).into() +} + pub fn pixels>(pixels: f32) -> T { AbsoluteLength::Pixels(pixels).into() } diff --git a/crates/gpui3/Cargo.toml b/crates/gpui3/Cargo.toml index 68a6ed0812..bc52090c83 100644 --- a/crates/gpui3/Cargo.toml +++ b/crates/gpui3/Cargo.toml @@ -16,7 +16,7 @@ doctest = false [dependencies] collections = { path = "../collections" } gpui_macros = { path = "../gpui_macros" } -gpui2_macros = { path = "../gpui2_macros" } +gpui3_macros = { path = "../gpui3_macros" } util = { path = "../util" } sum_tree = { path = "../sum_tree" } sqlez = { path = "../sqlez" } diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rs index e5ba1815a5..1915f44194 100644 --- a/crates/gpui3/src/element.rs +++ b/crates/gpui3/src/element.rs @@ -32,6 +32,15 @@ pub trait ParentElement { self.children_mut().push(child.into_any()); self } + + fn children(mut self, iter: impl IntoIterator>) -> Self + where + Self: Sized, + { + self.children_mut() + .extend(iter.into_iter().map(|item| item.into_any())); + self + } } trait ElementObject { diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index 9faad7a3e4..9ed9f8de98 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -1,6 +1,6 @@ use crate::{ AnyElement, Bounds, Element, Layout, LayoutId, Overflow, ParentElement, Pixels, Point, - Refineable, RefinementCascade, Result, Style, Styled, ViewContext, + Refineable, RefinementCascade, Result, Style, StyleHelpers, Styled, ViewContext, }; use smallvec::SmallVec; use std::{cell::Cell, rc::Rc}; @@ -257,6 +257,8 @@ impl Styled for Div { } } +impl StyleHelpers for Div {} + // impl Interactive for Div { // fn interaction_handlers(&mut self) -> &mut InteractionHandlers { // &mut self.handlers diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 36d2432cee..0bef59e422 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,4 +1,4 @@ -use crate::{Element, Layout, LayoutId, Result, Style, Styled}; +use crate::{Element, Layout, LayoutId, Result, Style, StyleHelpers, Styled}; use refineable::RefinementCascade; use std::marker::PhantomData; use util::arc_cow::ArcCow; @@ -98,3 +98,5 @@ impl Styled for Img { self.style.base() } } + +impl StyleHelpers for Img {} diff --git a/crates/gpui3/src/elements/svg.rs b/crates/gpui3/src/elements/svg.rs index 70b96e7755..b57fafe98c 100644 --- a/crates/gpui3/src/elements/svg.rs +++ b/crates/gpui3/src/elements/svg.rs @@ -1,4 +1,4 @@ -use crate::{Element, Layout, LayoutId, Result, Style, Styled}; +use crate::{Element, Layout, LayoutId, Result, Style, StyleHelpers, Styled}; use refineable::RefinementCascade; use std::{borrow::Cow, marker::PhantomData}; @@ -77,3 +77,5 @@ impl Styled for Svg { self.style.base() } } + +impl StyleHelpers for Svg {} diff --git a/crates/gpui3/src/geometry.rs b/crates/gpui3/src/geometry.rs index bb9214e07c..1a88fc37fe 100644 --- a/crates/gpui3/src/geometry.rs +++ b/crates/gpui3/src/geometry.rs @@ -100,8 +100,8 @@ impl From>> for Size> { impl Size { pub fn full() -> Self { Self { - width: relative(1.), - height: relative(1.), + width: relative(1.).into(), + height: relative(1.).into(), } } } @@ -410,7 +410,7 @@ impl Debug for Length { } } -pub fn relative>(fraction: f32) -> T { +pub fn relative(fraction: f32) -> DefiniteLength { DefiniteLength::Fraction(fraction).into() } diff --git a/crates/gpui3/src/gpui3.rs b/crates/gpui3/src/gpui3.rs index 07e7ddce9b..25ffe4d8e7 100644 --- a/crates/gpui3/src/gpui3.rs +++ b/crates/gpui3/src/gpui3.rs @@ -8,6 +8,7 @@ mod platform; mod renderer; mod scene; mod style; +mod style_helpers; mod styled; mod taffy; mod text_system; @@ -30,6 +31,7 @@ pub use smallvec; pub use smol::Timer; use std::ops::{Deref, DerefMut}; pub use style::*; +pub use style_helpers::*; pub use styled::*; use taffy::TaffyLayoutEngine; pub use taffy::{AvailableSpace, LayoutId}; diff --git a/crates/gpui3/src/style.rs b/crates/gpui3/src/style.rs index f3ea72a8f3..37fc700b05 100644 --- a/crates/gpui3/src/style.rs +++ b/crates/gpui3/src/style.rs @@ -289,10 +289,10 @@ impl From for Fill { #[derive(Clone, Refineable, Default, Debug)] #[refineable(debug)] pub struct CornerRadii { - top_left: AbsoluteLength, - top_right: AbsoluteLength, - bottom_left: AbsoluteLength, - bottom_right: AbsoluteLength, + pub top_left: AbsoluteLength, + pub top_right: AbsoluteLength, + pub bottom_left: AbsoluteLength, + pub bottom_right: AbsoluteLength, } impl From for HighlightStyle { diff --git a/crates/gpui3/src/style_helpers.rs b/crates/gpui3/src/style_helpers.rs new file mode 100644 index 0000000000..74287aef18 --- /dev/null +++ b/crates/gpui3/src/style_helpers.rs @@ -0,0 +1,288 @@ +use crate::{ + self as gpui2, relative, rems, AlignItems, Display, Fill, FlexDirection, Hsla, JustifyContent, + Length, Position, SharedString, Style, Styled, +}; + +pub trait StyleHelpers: Styled