Pass a MutableAppContext to Element::layout and ::dispatch_event
We need to mutate the app in these cases to relay layout state, so this just makes things easier. We won't be able to perform layout in parallel but it's questionable whether we'll ever actually do that. If we do, we can revisit. Co-Authored-By: Antonio Scandurra <me@as-cii.com> Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
co-authored by
Antonio Scandurra
Max Brunsfeld
parent
61f45800d3
commit
11285f3762
@@ -24,7 +24,7 @@ impl MouseEventHandler {
|
||||
F: FnOnce(MouseState) -> ElementBox,
|
||||
{
|
||||
let state_handle = cx.value::<Tag, _>(id);
|
||||
let state = state_handle.read(cx, |state| *state);
|
||||
let state = state_handle.read(cx.as_ref(), |state| *state);
|
||||
let child = render_child(state);
|
||||
Self {
|
||||
state: state_handle,
|
||||
@@ -81,7 +81,7 @@ impl Element for MouseEventHandler {
|
||||
|
||||
let handled_in_child = self.child.dispatch_event(event, cx);
|
||||
|
||||
self.state.update(cx.app, |state| match event {
|
||||
self.state.update(cx, |state, cx| match event {
|
||||
Event::MouseMoved { position } => {
|
||||
let mouse_in = bounds.contains_point(*position);
|
||||
if state.hovered != mouse_in {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use super::{
|
||||
AfterLayoutContext, AppContext, Element, Event, EventContext, LayoutContext, PaintContext,
|
||||
SizeConstraint,
|
||||
AfterLayoutContext, Element, Event, EventContext, LayoutContext, PaintContext, SizeConstraint,
|
||||
};
|
||||
use crate::{
|
||||
geometry::{
|
||||
@@ -8,7 +7,7 @@ use crate::{
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json::{self, json},
|
||||
ElementBox,
|
||||
AppContext, ElementBox,
|
||||
};
|
||||
use json::ToJson;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
Reference in New Issue
Block a user