Simplify adapter
This commit is contained in:
parent
85f35497b6
commit
7756497933
6 changed files with 81 additions and 93 deletions
|
@ -10,14 +10,14 @@ 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, Adapter<V>>,
|
||||
pub(crate) legacy_cx: &'d mut LegacyLayoutContext<'a, 'b, 'c, V>,
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut)]
|
||||
pub struct PaintContext<'a, 'b, 'c, 'd, V> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub(crate) legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, Adapter<V>>,
|
||||
pub(crate) legacy_cx: &'d mut LegacyPaintContext<'a, 'b, 'c, V>,
|
||||
pub(crate) scene: &'d mut gpui::SceneBuilder,
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,14 @@ pub trait Element<V: 'static>: 'static + Clone {
|
|||
}
|
||||
}
|
||||
|
||||
fn adapt(self) -> Adapter<V>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Element<V>,
|
||||
{
|
||||
Adapter(self.into_any())
|
||||
}
|
||||
|
||||
// Display ////////////////////
|
||||
|
||||
fn block(mut self) -> Self
|
||||
|
@ -200,14 +208,15 @@ pub trait Element<V: 'static>: 'static + Clone {
|
|||
}
|
||||
|
||||
pub trait ElementObject<V> {
|
||||
fn clone_object(&self) -> Box<dyn ElementObject<V>>;
|
||||
fn style_mut(&mut self) -> &mut Style;
|
||||
fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<NodeId>;
|
||||
fn paint(&mut self, layout: Layout, view: &mut V, cx: &mut PaintContext<V>) -> Result<()>;
|
||||
fn clone_object(&self) -> Box<dyn ElementObject<V>>;
|
||||
}
|
||||
|
||||
impl<V: 'static, E: Element<V>> ElementObject<V> for E {
|
||||
fn clone_object(&self) -> Box<dyn ElementObject<V>> {
|
||||
Box::new(Clone::clone(self))
|
||||
fn style_mut(&mut self) -> &mut Style {
|
||||
self.style_mut()
|
||||
}
|
||||
|
||||
fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<NodeId> {
|
||||
|
@ -217,6 +226,10 @@ impl<V: 'static, E: Element<V>> ElementObject<V> for E {
|
|||
fn paint(&mut self, layout: Layout, view: &mut V, cx: &mut PaintContext<V>) -> Result<()> {
|
||||
self.paint(layout, view, cx)
|
||||
}
|
||||
|
||||
fn clone_object(&self) -> Box<dyn ElementObject<V>> {
|
||||
Box::new(Clone::clone(self))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AnyElement<V> {
|
||||
|
@ -250,3 +263,17 @@ impl<V> Clone for AnyElement<V> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static> Element<V> for AnyElement<V> {
|
||||
fn style_mut(&mut self) -> &mut Style {
|
||||
self.element.style_mut()
|
||||
}
|
||||
|
||||
fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<NodeId> {
|
||||
self.layout(view, cx)
|
||||
}
|
||||
|
||||
fn paint(&mut self, layout: Layout, view: &mut V, cx: &mut PaintContext<V>) -> Result<()> {
|
||||
self.paint(view, cx)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue