Checkpoint
This commit is contained in:
parent
54a817a5ab
commit
4a3a1ad0c3
5 changed files with 35 additions and 40 deletions
|
@ -2455,7 +2455,7 @@ impl Element<Editor> for EditorElement {
|
||||||
editor.style = Some(self.style.clone()); // Long-term, we'd like to eliminate this.
|
editor.style = Some(self.style.clone()); // Long-term, we'd like to eliminate this.
|
||||||
|
|
||||||
let dispatch_context = editor.dispatch_context(cx);
|
let dispatch_context = editor.dispatch_context(cx);
|
||||||
cx.with_element_id(cx.view().entity_id(), |global_id, cx| {
|
cx.with_element_id(Some(cx.view().entity_id()), |cx| {
|
||||||
cx.with_key_dispatch(
|
cx.with_key_dispatch(
|
||||||
dispatch_context,
|
dispatch_context,
|
||||||
Some(editor.focus_handle.clone()),
|
Some(editor.focus_handle.clone()),
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, ElementInteractivity,
|
point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, ElementInteractivity,
|
||||||
FocusHandle, FocusListeners, Focusable, FocusableKeyDispatch, GlobalElementId, GroupBounds,
|
FocusHandle, FocusListeners, Focusable, FocusableKeyDispatch, GroupBounds,
|
||||||
InteractiveElementState, KeyContext, KeyDispatch, LayoutId, NonFocusableKeyDispatch, Overflow,
|
InteractiveElementState, KeyContext, KeyDispatch, LayoutId, NonFocusableKeyDispatch, Overflow,
|
||||||
ParentElement, Pixels, Point, SharedString, StatefulInteractive, StatefulInteractivity,
|
ParentElement, Pixels, Point, SharedString, StatefulInteractive, StatefulInteractivity,
|
||||||
StatelessInteractive, StatelessInteractivity, Style, StyleRefinement, Styled, ViewContext,
|
StatelessInteractive, StatelessInteractivity, Style, StyleRefinement, Styled, ViewContext,
|
||||||
|
@ -93,18 +93,6 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_element_id<R>(
|
|
||||||
&mut self,
|
|
||||||
cx: &mut ViewContext<V>,
|
|
||||||
f: impl FnOnce(&mut Self, Option<GlobalElementId>, &mut ViewContext<V>) -> R,
|
|
||||||
) -> R {
|
|
||||||
if let Some(id) = self.id() {
|
|
||||||
cx.with_element_id(id, |global_id, cx| f(self, Some(global_id), cx))
|
|
||||||
} else {
|
|
||||||
f(self, None, cx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compute_style(
|
pub fn compute_style(
|
||||||
&self,
|
&self,
|
||||||
bounds: Bounds<Pixels>,
|
bounds: Bounds<Pixels>,
|
||||||
|
@ -229,14 +217,14 @@ where
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Self::ElementState {
|
) -> Self::ElementState {
|
||||||
let mut element_state = element_state.unwrap_or_default();
|
let mut element_state = element_state.unwrap_or_default();
|
||||||
self.with_element_id(cx, |this, _global_id, cx| {
|
cx.with_element_id(self.id(), |cx| {
|
||||||
this.key_dispatch.initialize(
|
self.key_dispatch.initialize(
|
||||||
element_state.focus_handle.take(),
|
element_state.focus_handle.take(),
|
||||||
cx,
|
cx,
|
||||||
|focus_handle, cx| {
|
|focus_handle, cx| {
|
||||||
this.interactivity.initialize(cx);
|
self.interactivity.initialize(cx);
|
||||||
element_state.focus_handle = focus_handle;
|
element_state.focus_handle = focus_handle;
|
||||||
for child in &mut this.children {
|
for child in &mut self.children {
|
||||||
child.initialize(view_state, cx);
|
child.initialize(view_state, cx);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -253,8 +241,8 @@ where
|
||||||
) -> LayoutId {
|
) -> LayoutId {
|
||||||
let style = self.compute_style(Bounds::default(), element_state, cx);
|
let style = self.compute_style(Bounds::default(), element_state, cx);
|
||||||
style.apply_text_style(cx, |cx| {
|
style.apply_text_style(cx, |cx| {
|
||||||
self.with_element_id(cx, |this, _global_id, cx| {
|
cx.with_element_id(self.id(), |cx| {
|
||||||
let layout_ids = this
|
let layout_ids = self
|
||||||
.children
|
.children
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|child| child.layout(view_state, cx))
|
.map(|child| child.layout(view_state, cx))
|
||||||
|
@ -272,8 +260,8 @@ where
|
||||||
element_state: &mut Self::ElementState,
|
element_state: &mut Self::ElementState,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) {
|
) {
|
||||||
self.with_element_id(cx, |this, _global_id, cx| {
|
cx.with_element_id(self.id(), |cx| {
|
||||||
let style = this.compute_style(bounds, element_state, cx);
|
let style = self.compute_style(bounds, element_state, cx);
|
||||||
if style.visibility == Visibility::Hidden {
|
if style.visibility == Visibility::Hidden {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +273,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(group) = this.group.clone() {
|
if let Some(group) = self.group.clone() {
|
||||||
GroupBounds::push(group, bounds, cx);
|
GroupBounds::push(group, bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,8 +296,8 @@ where
|
||||||
cx.with_z_index(z_index, |cx| {
|
cx.with_z_index(z_index, |cx| {
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(0, |cx| {
|
||||||
style.paint(bounds, cx);
|
style.paint(bounds, cx);
|
||||||
this.key_dispatch.paint(bounds, cx);
|
self.key_dispatch.paint(bounds, cx);
|
||||||
this.interactivity.handle_events(
|
self.interactivity.handle_events(
|
||||||
bounds,
|
bounds,
|
||||||
content_size,
|
content_size,
|
||||||
style.overflow,
|
style.overflow,
|
||||||
|
@ -322,7 +310,7 @@ where
|
||||||
style.apply_overflow(bounds, cx, |cx| {
|
style.apply_overflow(bounds, cx, |cx| {
|
||||||
let scroll_offset = element_state.interactive.scroll_offset();
|
let scroll_offset = element_state.interactive.scroll_offset();
|
||||||
cx.with_element_offset(scroll_offset.unwrap_or_default(), |cx| {
|
cx.with_element_offset(scroll_offset.unwrap_or_default(), |cx| {
|
||||||
for child in &mut this.children {
|
for child in &mut self.children {
|
||||||
child.paint(view_state, cx);
|
child.paint(view_state, cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -331,7 +319,7 @@ where
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(group) = this.group.as_ref() {
|
if let Some(group) = self.group.as_ref() {
|
||||||
GroupBounds::pop(group, cx);
|
GroupBounds::pop(group, cx);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1008,6 +1008,8 @@ where
|
||||||
GroupBounds::push(group, bounds, cx);
|
GroupBounds::push(group, bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
todo!();
|
||||||
|
// cx.with_element_id(self.i, f);
|
||||||
cx.with_key_dispatch(
|
cx.with_key_dispatch(
|
||||||
self.key_context.clone(),
|
self.key_context.clone(),
|
||||||
self.tracked_focus_handle.clone(),
|
self.tracked_focus_handle.clone(),
|
||||||
|
|
|
@ -286,7 +286,7 @@ mod any_view {
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
pub(crate) fn initialize<V: Render>(view: &AnyView, cx: &mut WindowContext) -> Box<dyn Any> {
|
pub(crate) fn initialize<V: Render>(view: &AnyView, cx: &mut WindowContext) -> Box<dyn Any> {
|
||||||
cx.with_element_id(view.model.entity_id, |_, cx| {
|
cx.with_element_id(Some(view.model.entity_id), |cx| {
|
||||||
let view = view.clone().downcast::<V>().unwrap();
|
let view = view.clone().downcast::<V>().unwrap();
|
||||||
let element = view.update(cx, |view, cx| {
|
let element = view.update(cx, |view, cx| {
|
||||||
let mut element = AnyElement::new(view.render(cx));
|
let mut element = AnyElement::new(view.render(cx));
|
||||||
|
@ -302,7 +302,7 @@ mod any_view {
|
||||||
element: &mut Box<dyn Any>,
|
element: &mut Box<dyn Any>,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) -> LayoutId {
|
) -> LayoutId {
|
||||||
cx.with_element_id(view.model.entity_id, |_, cx| {
|
cx.with_element_id(Some(view.model.entity_id), |cx| {
|
||||||
let view = view.clone().downcast::<V>().unwrap();
|
let view = view.clone().downcast::<V>().unwrap();
|
||||||
let element = element.downcast_mut::<AnyElement<V>>().unwrap();
|
let element = element.downcast_mut::<AnyElement<V>>().unwrap();
|
||||||
view.update(cx, |view, cx| element.layout(view, cx))
|
view.update(cx, |view, cx| element.layout(view, cx))
|
||||||
|
@ -314,7 +314,7 @@ mod any_view {
|
||||||
element: &mut Box<dyn Any>,
|
element: &mut Box<dyn Any>,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
cx.with_element_id(view.model.entity_id, |_, cx| {
|
cx.with_element_id(Some(view.model.entity_id), |cx| {
|
||||||
let view = view.clone().downcast::<V>().unwrap();
|
let view = view.clone().downcast::<V>().unwrap();
|
||||||
let element = element.downcast_mut::<AnyElement<V>>().unwrap();
|
let element = element.downcast_mut::<AnyElement<V>>().unwrap();
|
||||||
view.update(cx, |view, cx| element.paint(view, cx))
|
view.update(cx, |view, cx| element.paint(view, cx))
|
||||||
|
|
|
@ -1537,16 +1537,19 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
|
||||||
/// used to associate state with identified elements across separate frames.
|
/// used to associate state with identified elements across separate frames.
|
||||||
fn with_element_id<R>(
|
fn with_element_id<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: impl Into<ElementId>,
|
id: Option<impl Into<ElementId>>,
|
||||||
f: impl FnOnce(GlobalElementId, &mut Self) -> R,
|
f: impl FnOnce(&mut Self) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
let window = self.window_mut();
|
if let Some(id) = id.map(Into::into) {
|
||||||
window.element_id_stack.push(id.into());
|
let window = self.window_mut();
|
||||||
let global_id = window.element_id_stack.clone();
|
window.element_id_stack.push(id.into());
|
||||||
let result = f(global_id, self);
|
let result = f(self);
|
||||||
let window: &mut Window = self.borrow_mut();
|
let window: &mut Window = self.borrow_mut();
|
||||||
window.element_id_stack.pop();
|
window.element_id_stack.pop();
|
||||||
result
|
result
|
||||||
|
} else {
|
||||||
|
f(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Invoke the given function with the given content mask after intersecting it
|
/// Invoke the given function with the given content mask after intersecting it
|
||||||
|
@ -1613,7 +1616,9 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
|
||||||
where
|
where
|
||||||
S: 'static,
|
S: 'static,
|
||||||
{
|
{
|
||||||
self.with_element_id(id, |global_id, cx| {
|
self.with_element_id(Some(id), |cx| {
|
||||||
|
let global_id = cx.window().element_id_stack.clone();
|
||||||
|
|
||||||
if let Some(any) = cx
|
if let Some(any) = cx
|
||||||
.window_mut()
|
.window_mut()
|
||||||
.current_frame
|
.current_frame
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue