mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 14:17:02 +00:00
Checkpoint
This commit is contained in:
parent
4a3a1ad0c3
commit
1668330764
1 changed files with 43 additions and 46 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
point, px, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, BorrowAppContext,
|
point, px, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, BorrowAppContext,
|
||||||
BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, FocusHandle, KeyContext,
|
BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId, FocusHandle, KeyContext,
|
||||||
KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
||||||
Pixels, Point, Render, ScrollWheelEvent, SharedString, Size, Style, StyleRefinement, Styled,
|
Pixels, Point, Render, ScrollWheelEvent, SharedString, Size, Style, StyleRefinement, Styled,
|
||||||
Task, View, ViewContext, Visibility,
|
Task, View, ViewContext, Visibility,
|
||||||
|
@ -550,8 +550,8 @@ impl<V: 'static> InteractiveComponent<V> for Node<V> {
|
||||||
impl<V: 'static> Element<V> for Node<V> {
|
impl<V: 'static> Element<V> for Node<V> {
|
||||||
type ElementState = NodeState;
|
type ElementState = NodeState;
|
||||||
|
|
||||||
fn id(&self) -> Option<crate::ElementId> {
|
fn id(&self) -> Option<ElementId> {
|
||||||
None
|
self.interactivity.element_id.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize(
|
fn initialize(
|
||||||
|
@ -560,13 +560,12 @@ impl<V: 'static> Element<V> for Node<V> {
|
||||||
element_state: Option<Self::ElementState>,
|
element_state: Option<Self::ElementState>,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> Self::ElementState {
|
) -> Self::ElementState {
|
||||||
let interactive_state =
|
let interactive_state = self
|
||||||
self.interactivity
|
.interactivity
|
||||||
.initialize(element_state.map(|s| s.interactive_state), cx, |cx| {
|
.initialize(element_state.map(|s| s.interactive_state), cx);
|
||||||
for child in &mut self.children {
|
for child in &mut self.children {
|
||||||
child.initialize(view_state, cx);
|
child.initialize(view_state, cx);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
NodeState {
|
NodeState {
|
||||||
interactive_state,
|
interactive_state,
|
||||||
|
@ -656,13 +655,8 @@ pub struct NodeState {
|
||||||
interactive_state: InteractiveElementState,
|
interactive_state: InteractiveElementState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsMut<InteractiveElementState> for InteractiveElementState {
|
|
||||||
fn as_mut(&mut self) -> &mut InteractiveElementState {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Interactivity<V> {
|
pub struct Interactivity<V> {
|
||||||
|
element_id: Option<ElementId>,
|
||||||
key_context: KeyContext,
|
key_context: KeyContext,
|
||||||
tracked_focus_handle: Option<FocusHandle>,
|
tracked_focus_handle: Option<FocusHandle>,
|
||||||
focusable: bool,
|
focusable: bool,
|
||||||
|
@ -700,9 +694,9 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
element_state: Option<InteractiveElementState>,
|
element_state: Option<InteractiveElementState>,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
f: impl FnOnce(&mut ViewContext<V>),
|
|
||||||
) -> InteractiveElementState {
|
) -> InteractiveElementState {
|
||||||
let mut element_state = element_state.unwrap_or_default();
|
let mut element_state = element_state.unwrap_or_default();
|
||||||
|
|
||||||
// Ensure we store a focus handle in our element state if we're focusable.
|
// Ensure we store a focus handle in our element state if we're focusable.
|
||||||
// If there's an explicit focus handle we're tracking, use that. Otherwise
|
// If there's an explicit focus handle we're tracking, use that. Otherwise
|
||||||
// create a new handle and store it in the element state, which lives for as
|
// create a new handle and store it in the element state, which lives for as
|
||||||
|
@ -724,11 +718,13 @@ where
|
||||||
f: impl FnOnce(Style, &mut ViewContext<V>) -> LayoutId,
|
f: impl FnOnce(Style, &mut ViewContext<V>) -> LayoutId,
|
||||||
) -> LayoutId {
|
) -> LayoutId {
|
||||||
let style = self.compute_style(None, element_state, cx);
|
let style = self.compute_style(None, element_state, cx);
|
||||||
cx.with_key_dispatch(
|
cx.with_element_id(self.element_id.clone(), |cx| {
|
||||||
self.key_context.clone(),
|
cx.with_key_dispatch(
|
||||||
self.tracked_focus_handle.clone(),
|
self.key_context.clone(),
|
||||||
|_, cx| f(style, cx),
|
self.tracked_focus_handle.clone(),
|
||||||
)
|
|_, cx| f(style, cx),
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint(
|
fn paint(
|
||||||
|
@ -1008,31 +1004,31 @@ where
|
||||||
GroupBounds::push(group, bounds, cx);
|
GroupBounds::push(group, bounds, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!();
|
cx.with_element_id(self.element_id.clone(), |cx| {
|
||||||
// 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(),
|
|_, cx| {
|
||||||
|_, cx| {
|
for listener in self.key_down_listeners.drain(..) {
|
||||||
for listener in self.key_down_listeners.drain(..) {
|
cx.on_key_event(move |state, event: &KeyDownEvent, phase, cx| {
|
||||||
cx.on_key_event(move |state, event: &KeyDownEvent, phase, cx| {
|
listener(state, event, phase, cx);
|
||||||
listener(state, event, phase, cx);
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for listener in self.key_up_listeners.drain(..) {
|
for listener in self.key_up_listeners.drain(..) {
|
||||||
cx.on_key_event(move |state, event: &KeyUpEvent, phase, cx| {
|
cx.on_key_event(move |state, event: &KeyUpEvent, phase, cx| {
|
||||||
listener(state, event, phase, cx);
|
listener(state, event, phase, cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for (action_type, listener) in self.action_listeners.drain(..) {
|
for (action_type, listener) in self.action_listeners.drain(..) {
|
||||||
cx.on_action(action_type, listener)
|
cx.on_action(action_type, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
f(style, self.scroll_offset, cx)
|
f(style, self.scroll_offset, cx)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(group) = self.group.as_ref() {
|
if let Some(group) = self.group.as_ref() {
|
||||||
GroupBounds::pop(group, cx);
|
GroupBounds::pop(group, cx);
|
||||||
|
@ -1116,6 +1112,7 @@ where
|
||||||
impl<V: 'static> Default for Interactivity<V> {
|
impl<V: 'static> Default for Interactivity<V> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
element_id: None,
|
||||||
key_context: KeyContext::default(),
|
key_context: KeyContext::default(),
|
||||||
tracked_focus_handle: None,
|
tracked_focus_handle: None,
|
||||||
scroll_offset: Point::default(),
|
scroll_offset: Point::default(),
|
||||||
|
@ -1243,7 +1240,7 @@ where
|
||||||
{
|
{
|
||||||
type ElementState = E::ElementState;
|
type ElementState = E::ElementState;
|
||||||
|
|
||||||
fn id(&self) -> Option<crate::ElementId> {
|
fn id(&self) -> Option<ElementId> {
|
||||||
self.element.id()
|
self.element.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1313,7 +1310,7 @@ where
|
||||||
{
|
{
|
||||||
type ElementState = E::ElementState;
|
type ElementState = E::ElementState;
|
||||||
|
|
||||||
fn id(&self) -> Option<crate::ElementId> {
|
fn id(&self) -> Option<ElementId> {
|
||||||
self.element.id()
|
self.element.id()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue