This commit is contained in:
Nathan Sobo 2023-08-16 06:22:47 -06:00
parent a8ecc1a643
commit fea987b459
4 changed files with 46 additions and 20 deletions

View file

@ -14,19 +14,16 @@ impl<V: 'static> gpui::Element<V> for Adapter<V> {
&mut self, &mut self,
constraint: gpui::SizeConstraint, constraint: gpui::SizeConstraint,
view: &mut V, view: &mut V,
legacy_cx: &mut gpui::LayoutContext<V>, cx: &mut LayoutContext<V>,
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) { ) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
legacy_cx.push_layout_engine(LayoutEngine::new()); cx.push_layout_engine(LayoutEngine::new());
let node = self let node = self.0.layout(view, cx).log_err();
.0
.layout(view, &mut LayoutContext { legacy_cx })
.log_err();
if let Some(node) = node { if let Some(node) = node {
let layout_engine = legacy_cx.layout_engine().unwrap(); let layout_engine = cx.layout_engine().unwrap();
layout_engine.compute_layout(node, constraint.max).log_err(); layout_engine.compute_layout(node, constraint.max).log_err();
} }
let layout_engine = legacy_cx.pop_layout_engine(); let layout_engine = cx.pop_layout_engine();
debug_assert!(layout_engine.is_some()); debug_assert!(layout_engine.is_some());
(constraint.max, layout_engine) (constraint.max, layout_engine)
} }

View file

@ -1,24 +1,19 @@
use std::{any::Any, rc::Rc};
use crate::{ use crate::{
adapter::Adapter, adapter::Adapter,
style::{Display, ElementStyle, Fill, Overflow, Position}, style::{Display, ElementStyle, Fill, Overflow, Position},
}; };
use anyhow::Result; use anyhow::Result;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
pub use gpui::LayoutContext;
use gpui::{ use gpui::{
geometry::{DefinedLength, Length}, geometry::{DefinedLength, Length},
scene::MouseClick, scene::MouseClick,
EngineLayout, LayoutContext as LegacyLayoutContext, PaintContext as LegacyPaintContext, EngineLayout, PaintContext as LegacyPaintContext,
}; };
use playground_macros::tailwind_lengths; use playground_macros::tailwind_lengths;
use std::{any::Any, rc::Rc};
pub use taffy::tree::NodeId; pub use taffy::tree::NodeId;
#[derive(Deref, DerefMut)]
pub struct LayoutContext<'a, 'b, 'c, 'd, V> {
pub(crate) legacy_cx: &'d mut LegacyLayoutContext<'a, 'b, 'c, V>,
}
#[derive(Deref, DerefMut)] #[derive(Deref, DerefMut)]
pub struct PaintContext<'a, 'b, 'c, 'd, V> { pub struct PaintContext<'a, 'b, 'c, 'd, V> {
#[deref] #[deref]
@ -355,12 +350,9 @@ impl<V: 'static, E: Element<V>> ElementObject<V> for E {
self.paint(layout, view, cx) self.paint(layout, view, cx)
} }
// fn clone_object(&self) -> Box<dyn ElementObject<V>> {
// Box::new(Clone::clone(self))
// }
} }
/// A dynamically typed element.
pub struct AnyElement<V> { pub struct AnyElement<V> {
element: Box<dyn ElementObject<V>>, element: Box<dyn ElementObject<V>>,
layout: Option<(NodeId, Box<dyn Any>)>, layout: Option<(NodeId, Box<dyn Any>)>,

View file

@ -18,6 +18,7 @@ mod components;
mod element; mod element;
mod frame; mod frame;
mod style; mod style;
mod text;
mod themes; mod themes;
mod view; mod view;

View file

@ -0,0 +1,36 @@
use std::borrow::Cow;
use crate::element::Element;
impl<V, S> Element<V> for S
where
V: 'static,
S: 'static + Into<Cow<'static, str>>,
{
type Layout = Cow<'static, str>;
fn style_mut(&mut self) -> &mut crate::style::ElementStyle {
todo!()
}
fn handlers_mut(&mut self) -> &mut crate::element::ElementHandlers<V> {
todo!()
}
fn layout(
&mut self,
view: &mut V,
cx: &mut crate::element::LayoutContext<V>,
) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> {
todo!()
}
fn paint<'a>(
&mut self,
layout: crate::element::Layout<Self::Layout>,
view: &mut V,
cx: &mut crate::element::PaintContext<V>,
) -> anyhow::Result<()> {
todo!()
}
}