Remove state erasure for now

This commit is contained in:
Nathan Sobo 2023-10-10 12:44:40 -06:00
parent e714653478
commit 61b8ad38bd
3 changed files with 0 additions and 42 deletions

View file

@ -3,7 +3,6 @@ mod hoverable;
mod identified;
mod img;
mod pressable;
mod stateless;
mod svg;
mod text;
@ -12,6 +11,5 @@ pub use hoverable::*;
pub use identified::*;
pub use img::*;
pub use pressable::*;
pub use stateless::*;
pub use svg::*;
pub use text::*;

View file

@ -1,30 +0,0 @@
use crate::{Bounds, Element, Pixels};
use std::marker::PhantomData;
pub struct Stateless<E: Element<State = ()>, S> {
element: E,
parent_state_type: PhantomData<S>,
}
impl<E: Element<State = ()>, S: Send + Sync + 'static> Element for Stateless<E, S> {
type State = S;
type FrameState = E::FrameState;
fn layout(
&mut self,
_: &mut Self::State,
cx: &mut crate::ViewContext<Self::State>,
) -> anyhow::Result<(crate::LayoutId, Self::FrameState)> {
cx.erase_state(|cx| self.element.layout(&mut (), cx))
}
fn paint(
&mut self,
bounds: Bounds<Pixels>,
_: &mut Self::State,
frame_state: &mut Self::FrameState,
cx: &mut crate::ViewContext<Self::State>,
) -> anyhow::Result<()> {
cx.erase_state(|cx| self.element.paint(bounds, &mut (), frame_state, cx))
}
}

View file

@ -926,16 +926,6 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
})
});
}
pub(crate) fn erase_state<R>(&mut self, f: impl FnOnce(&mut ViewContext<()>) -> R) -> R {
let entity_id = self.unit_entity.id;
let mut cx = ViewContext::mutable(
&mut *self.window_cx.app,
&mut *self.window_cx.window,
entity_id,
);
f(&mut cx)
}
}
impl<'a, 'w, S> Context for ViewContext<'a, 'w, S> {