Eliminate ElementStateContext trait
We now always have a RenderContext when rendering MouseEventHandlers or scrollable Flex columns/rows. Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
b6b16fc9c3
commit
bd62a68234
4 changed files with 32 additions and 54 deletions
|
@ -127,26 +127,6 @@ pub trait UpdateView {
|
|||
T: View;
|
||||
}
|
||||
|
||||
pub trait ElementStateContext: DerefMut<Target = MutableAppContext> {
|
||||
fn current_view_id(&self) -> usize;
|
||||
|
||||
fn element_state<Tag: 'static, T: 'static + Default>(
|
||||
&mut self,
|
||||
element_id: usize,
|
||||
) -> ElementStateHandle<T> {
|
||||
let id = ElementStateId {
|
||||
view_id: self.current_view_id(),
|
||||
element_id,
|
||||
tag: TypeId::of::<Tag>(),
|
||||
};
|
||||
self.cx
|
||||
.element_states
|
||||
.entry(id)
|
||||
.or_insert_with(|| Box::new(T::default()));
|
||||
ElementStateHandle::new(id, self.frame_count, &self.cx.ref_counts)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Menu<'a> {
|
||||
pub name: &'a str,
|
||||
pub items: Vec<MenuItem<'a>>,
|
||||
|
@ -3444,7 +3424,7 @@ pub struct MouseState {
|
|||
pub clicked: bool,
|
||||
}
|
||||
|
||||
impl<'a, T: View> RenderContext<'a, T> {
|
||||
impl<'a, V: View> RenderContext<'a, V> {
|
||||
fn new(params: RenderParams, app: &'a mut MutableAppContext) -> Self {
|
||||
Self {
|
||||
app,
|
||||
|
@ -3458,7 +3438,7 @@ impl<'a, T: View> RenderContext<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> WeakViewHandle<T> {
|
||||
pub fn handle(&self) -> WeakViewHandle<V> {
|
||||
WeakViewHandle::new(self.window_id, self.view_id)
|
||||
}
|
||||
|
||||
|
@ -3477,6 +3457,22 @@ impl<'a, T: View> RenderContext<'a, T> {
|
|||
clicked: self.clicked_region_id == region_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn element_state<Tag: 'static, T: 'static + Default>(
|
||||
&mut self,
|
||||
element_id: usize,
|
||||
) -> ElementStateHandle<T> {
|
||||
let id = ElementStateId {
|
||||
view_id: self.view_id(),
|
||||
element_id,
|
||||
tag: TypeId::of::<Tag>(),
|
||||
};
|
||||
self.cx
|
||||
.element_states
|
||||
.entry(id)
|
||||
.or_insert_with(|| Box::new(T::default()));
|
||||
ElementStateHandle::new(id, self.frame_count, &self.cx.ref_counts)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<AppContext> for &AppContext {
|
||||
|
@ -3521,12 +3517,6 @@ impl<V: View> ReadView for RenderContext<'_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ElementStateContext for RenderContext<'_, V> {
|
||||
fn current_view_id(&self) -> usize {
|
||||
self.view_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<M> AsRef<AppContext> for ViewContext<'_, M> {
|
||||
fn as_ref(&self) -> &AppContext {
|
||||
&self.app.cx
|
||||
|
@ -3625,12 +3615,6 @@ impl<V: View> UpdateView for ViewContext<'_, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> ElementStateContext for ViewContext<'_, V> {
|
||||
fn current_view_id(&self) -> usize {
|
||||
self.view_id
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Handle<T> {
|
||||
type Weak: 'static;
|
||||
fn id(&self) -> usize;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue