Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'gpui2' into gpui2-ui
Marshall Bowers002458f4c8ac
diff --cc crates/gpui3/src/element.rsindex eef90f4f2d3,3b12d6acfca..65ce28ed1ae--- a/crates/gpui3/src/element.rs+++ b/crates/gpui3/src/element.rs@@@ -66,41 -82,11 +82,36 @@@ pub trait ParentElement.extend(iter.into_iter().map(|item| item.into_any()));self}++ // HACK: This is a temporary hack to get children working for the purposes+ // of building UI on top of the current version of gpui2.+ //+ // We'll (hopefully) be moving away from this in the future.+ fn children_any<I>(mut self, children: I) -> Self+ where+ I: IntoIterator<Item = AnyElement<Self::State>>,+ Self: Sized,+ {+ self.children_mut().extend(children.into_iter());+ self+ }++ // HACK: This is a temporary hack to get children working for the purposes+ // of building UI on top of the current version of gpui2.+ //+ // We'll (hopefully) be moving away from this in the future.+ fn child_any(mut self, children: AnyElement<Self::State>) -> Self+ where+ Self: Sized,+ {+ self.children_mut().push(children);+ self+ }}- trait ElementObject<S> {- fn layout(&mut self, state: &mut S, cx: &mut ViewContext<S>) -> Result<LayoutId>;- fn paint(- &mut self,- state: &mut S,- offset: Option<Point<Pixels>>,- cx: &mut ViewContext<S>,- ) -> Result<()>;+ trait ElementObject<S>: 'static + Send + Sync {+ fn layout(&mut self, state: &mut S, cx: &mut ViewContext<S>) -> LayoutId;+ fn paint(&mut self, state: &mut S, offset: Option<Point<Pixels>>, cx: &mut ViewContext<S>);}struct RenderedElement<E: Element> {diff --cc crates/gpui3/src/elements/div.rsindex e29391b189b,8d97168d2f0..feeea51d8bf--- a/crates/gpui3/src/elements/div.rs+++ b/crates/gpui3/src/elements/div.rs@@@ -43,40 -55,48 +55,54 @@@ impl<S: 'static + Send + Sync, Marker:&mut self,bounds: Bounds<Pixels>,state: &mut S,- child_layout_ids: &mut Self::FrameState,+ _: &mut (),cx: &mut ViewContext<S>,- ) -> Result<()> {+ ) {let style = self.computed_style();- cx.stack(0, |cx| style.paint(bounds, cx));+ let z_index = style.z_index.unwrap_or(0);+ cx.stack(z_index, |cx| style.paint(bounds, cx));let overflow = &style.overflow;+style.apply_text_style(cx, |cx| {- cx.stack(1, |cx| {+ cx.stack(z_index + 1, |cx| {style.apply_overflow(bounds, cx, |cx| {- self.listeners.paint(bounds, cx);- self.paint_children(overflow, state, cx)+ self.with_element_id(cx, |this, cx| {+ this.listeners.paint(bounds, cx);+ this.paint_children(overflow, state, cx)+ });})})- })?;- self.handle_scroll(bounds, style.overflow.clone(), child_layout_ids, cx);-- // todo!("enable inspector")- // if cx.is_inspector_enabled() {- // self.paint_inspector(parent_origin, layout, cx);- // }- //+ });+ }+ }- Ok(())+ impl<S> Div<S, ()>+ where+ S: 'static + Send + Sync,+ {+ pub fn id(self, id: impl Into<ElementId>) -> Div<S, HasId> {+ Div {+ styles: self.styles,+ id: Some(id.into()),+ listeners: self.listeners,+ children: self.children,+ scroll_state: self.scroll_state,+ identified: PhantomData,+ }}}- impl<S: 'static> Div<S> {+ impl<S, Marker> Div<S, Marker>+ where+ S: 'static + Send + Sync,+ Marker: 'static + Send + Sync,+ {+ pub fn z_index(mut self, z_index: u32) -> Self {+ self.declared_style().z_index = Some(z_index);+ self+ }+pub fn overflow_hidden(mut self) -> Self {self.declared_style().overflow.x = Some(Overflow::Hidden);self.declared_style().overflow.y = Some(Overflow::Hidden);diff --cc crates/gpui3/src/style_helpers.rsindex 1130610c0fc,d8015e63348..42d67fe5295--- a/crates/gpui3/src/style_helpers.rs+++ b/crates/gpui3/src/style_helpers.rs@@@ -167,10 -257,13 +167,10 @@@ pub trait StyleHelpers: Sized + Styled<self}- fn shadow_md(mut self) -> Self- where- Self: Sized,- {+ fn shadow_md(mut self) -> Self {self.declared_style().box_shadow = Some(smallvec![BoxShadow {- color: hsla(0.5, 0., 0., 1.0),+ color: hsla(0.5, 0., 0., 0.1),offset: point(px(0.), px(4.)),blur_radius: px(6.),spread_radius: px(-1.),diff --cc crates/gpui3/src/taffy.rsindex 6edbd3593b6,7f9f08d7841..47075cb0e3c--- a/crates/gpui3/src/taffy.rs+++ b/crates/gpui3/src/taffy.rs@@@ -59,81 -61,24 +61,77 @@@ impl TaffyLayoutEnginelet style = style.to_taffy(rem_size);let measurable = Box::new(Measureable(measure)) as Box<dyn Measurable>;- Ok(self- .taffy- .new_leaf_with_measure(style, MeasureFunc::Boxed(measurable))?- .into())+ self.taffy+ .new_leaf_with_measure(style, MeasureFunc::Boxed(measurable))+ .expect(EXPECT_MESSAGE)+ .into()}+ fn count_all_children(&self, parent: LayoutId) -> Result<u32> {+ let mut count = 0;++ for child in self.taffy.children(parent.0)? {+ // Count this child.+ count += 1;++ // Count all of this child's children.+ count += self.count_all_children(LayoutId(child))?+ }++ Ok(count)+ }++ fn max_depth(&self, depth: u32, parent: LayoutId) -> Result<u32> {+ println!(+ "{parent:?} at depth {depth} has {} children",+ self.taffy.child_count(parent.0)?+ );++ let mut max_child_depth = 0;++ for child in self.taffy.children(parent.0)? {+ max_child_depth = std::cmp::max(max_child_depth, self.max_depth(0, LayoutId(child))?);+ }++ Ok(depth + 1 + max_child_depth)+ }++ fn get_edges(&self, parent: LayoutId) -> Result<Vec<(LayoutId, LayoutId)>> {+ let mut edges = Vec::new();++ for child in self.taffy.children(parent.0)? {+ edges.push((parent, LayoutId(child)));++ edges.extend(self.get_edges(LayoutId(child))?);+ }++ Ok(edges)+ }+- pub fn compute_layout(- &mut self,- id: LayoutId,- available_space: Size<AvailableSpace>,- ) -> Result<()> {+ pub fn compute_layout(&mut self, id: LayoutId, available_space: Size<AvailableSpace>) {+ // println!("Laying out {} children", self.count_all_children(id)?);+ // println!("Max layout depth: {}", self.max_depth(0, id)?);++ // Output the edges (branches) of the tree in Mermaid format for visualization.+ // println!("Edges:");+ // for (a, b) in self.get_edges(id)? {+ // println!("N{} --> N{}", u64::from(a), u64::from(b));+ // }+ // println!("");++ let started_at = std::time::Instant::now();self.taffy- .compute_layout(id.into(), available_space.into())?;+ .compute_layout(id.into(), available_space.into())+ .expect(EXPECT_MESSAGE);+ println!("compute_layout took {:?}", started_at.elapsed());- Ok(())}- pub fn layout_bounds(&mut self, id: LayoutId) -> Result<Bounds<Pixels>> {+ pub fn layout_bounds(&mut self, id: LayoutId) -> Bounds<Pixels> {if let Some(layout) = self.absolute_layout_bounds.get(&id).cloned() {- return Ok(layout);+ return layout;}- let layout = self.taffy.layout(id.into())?;+ let layout = self.taffy.layout(id.into()).expect(EXPECT_MESSAGE);let mut bounds = Bounds {origin: layout.location.into(),size: layout.size.into(),diff --cc crates/ui2/src/theme.rsindex e8b8b9c2c87,da9916debc2..ac54a7b8065--- a/crates/ui2/src/theme.rs+++ b/crates/ui2/src/theme.rs@@@ -177,6 -180,6 +183,6 @@@ impl<E: Element> Element for Themed<E>}}-pub fn theme<'a>(cx: &'a WindowContext) -> &'a Theme {- cx.global()+pub fn theme(cx: &WindowContext) -> Arc<Theme> {- Arc::new(cx.state::<Theme>().clone())++ Arc::new(cx.global::<Theme>().clone())}