Checkpoint

This commit is contained in:
Nathan Sobo
2023-10-12 13:27:46 -06:00
parent 2044ccdc0b
commit ce8533f83b
11 changed files with 161 additions and 181 deletions
+4 -4
View File
@@ -102,10 +102,10 @@ impl<T> core::ops::DerefMut for Lease<T> {
impl<T> Drop for Lease<T> {
fn drop(&mut self) {
assert!(
self.entity.is_none(),
"Leases must be ended with EntityMap::end_lease"
);
if self.entity.is_some() {
// We don't panic here, because other panics can cause us to drop the lease without ending it cleanly.
log::error!("Leases must be ended with EntityMap::end_lease")
}
}
}
+6 -6
View File
@@ -33,8 +33,8 @@ pub fn view<S, E>(
render: impl Fn(&mut S, &mut ViewContext<S>) -> E + Send + Sync + 'static,
) -> View<S>
where
E: IntoAnyElement<S>,
S: 'static + Send + Sync,
E: Element<ViewState = S>,
{
View {
state,
@@ -86,6 +86,8 @@ impl<S: 'static + Send + Sync> Element for View<S> {
}
}
impl<S: Send + Sync + 'static> IdentifiedElement for View<S> {}
struct EraseViewState<ViewState: 'static + Send + Sync, ParentViewState> {
view: View<ViewState>,
parent_view_state_type: PhantomData<ParentViewState>,
@@ -137,11 +139,9 @@ where
trait ViewObject: 'static + Send + Sync {
fn entity_id(&self) -> EntityId;
fn layout(&mut self, cx: &mut WindowContext) -> (LayoutId, AnyBox);
fn paint(&mut self, bounds: Bounds<Pixels>, element: &mut dyn Any, cx: &mut WindowContext);
fn paint(&mut self, bounds: Bounds<Pixels>, element: &mut AnyBox, cx: &mut WindowContext);
}
impl<S: Send + Sync + 'static> IdentifiedElement for View<S> {}
impl<S: Send + Sync + 'static> ViewObject for View<S> {
fn entity_id(&self) -> EntityId {
self.state.id
@@ -158,7 +158,7 @@ impl<S: Send + Sync + 'static> ViewObject for View<S> {
})
}
fn paint(&mut self, _: Bounds<Pixels>, element: &mut dyn Any, cx: &mut WindowContext) {
fn paint(&mut self, _: Bounds<Pixels>, element: &mut AnyBox, cx: &mut WindowContext) {
cx.with_element_id(IdentifiedElement::element_id(self), |cx| {
self.state.update(cx, |state, cx| {
let element = element.downcast_mut::<AnyElement<S>>().unwrap();
@@ -208,7 +208,7 @@ impl Element for AnyView {
element: &mut AnyBox,
cx: &mut ViewContext<Self::ViewState>,
) {
self.view.lock().paint(bounds, element.as_mut(), cx)
self.view.lock().paint(bounds, element, cx)
}
}