WIP
This commit is contained in:
parent
a8ecc1a643
commit
fea987b459
4 changed files with 46 additions and 20 deletions
|
@ -14,19 +14,16 @@ impl<V: 'static> gpui::Element<V> for Adapter<V> {
|
|||
&mut self,
|
||||
constraint: gpui::SizeConstraint,
|
||||
view: &mut V,
|
||||
legacy_cx: &mut gpui::LayoutContext<V>,
|
||||
cx: &mut LayoutContext<V>,
|
||||
) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) {
|
||||
legacy_cx.push_layout_engine(LayoutEngine::new());
|
||||
let node = self
|
||||
.0
|
||||
.layout(view, &mut LayoutContext { legacy_cx })
|
||||
.log_err();
|
||||
cx.push_layout_engine(LayoutEngine::new());
|
||||
let node = self.0.layout(view, cx).log_err();
|
||||
|
||||
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();
|
||||
}
|
||||
let layout_engine = legacy_cx.pop_layout_engine();
|
||||
let layout_engine = cx.pop_layout_engine();
|
||||
debug_assert!(layout_engine.is_some());
|
||||
(constraint.max, layout_engine)
|
||||
}
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
use std::{any::Any, rc::Rc};
|
||||
|
||||
use crate::{
|
||||
adapter::Adapter,
|
||||
style::{Display, ElementStyle, Fill, Overflow, Position},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
pub use gpui::LayoutContext;
|
||||
use gpui::{
|
||||
geometry::{DefinedLength, Length},
|
||||
scene::MouseClick,
|
||||
EngineLayout, LayoutContext as LegacyLayoutContext, PaintContext as LegacyPaintContext,
|
||||
EngineLayout, PaintContext as LegacyPaintContext,
|
||||
};
|
||||
use playground_macros::tailwind_lengths;
|
||||
use std::{any::Any, rc::Rc};
|
||||
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)]
|
||||
pub struct PaintContext<'a, 'b, 'c, 'd, V> {
|
||||
#[deref]
|
||||
|
@ -355,12 +350,9 @@ impl<V: 'static, E: Element<V>> ElementObject<V> for E {
|
|||
|
||||
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> {
|
||||
element: Box<dyn ElementObject<V>>,
|
||||
layout: Option<(NodeId, Box<dyn Any>)>,
|
||||
|
|
|
@ -18,6 +18,7 @@ mod components;
|
|||
mod element;
|
||||
mod frame;
|
||||
mod style;
|
||||
mod text;
|
||||
mod themes;
|
||||
mod view;
|
||||
|
||||
|
|
36
crates/gpui/playground/src/text.rs
Normal file
36
crates/gpui/playground/src/text.rs
Normal 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!()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue