mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-16 15:11:25 +00:00
Checkpoint
This commit is contained in:
parent
47b64a5074
commit
93c233b1cf
4 changed files with 49 additions and 28 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
AnyElement, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId,
|
||||
AnyElement, BorrowWindow, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId,
|
||||
MouseEventListeners, Overflow, ParentElement, Pixels, Point, Refineable, RefinementCascade,
|
||||
Style, Styled, ViewContext,
|
||||
};
|
||||
|
@ -44,7 +44,9 @@ impl<S: 'static + Send + Sync, Marker: 'static + Send + Sync> Element for Div<S,
|
|||
cx: &mut ViewContext<S>,
|
||||
) -> (LayoutId, Self::ElementState) {
|
||||
let style = self.computed_style();
|
||||
let child_layout_ids = style.apply_text_style(cx, |cx| self.layout_children(view, cx));
|
||||
let child_layout_ids = style.apply_text_style(cx, |cx| {
|
||||
self.with_element_id(cx, |this, cx| this.layout_children(view, cx))
|
||||
});
|
||||
let layout_id = cx.request_layout(style.into(), child_layout_ids.clone());
|
||||
(layout_id, ())
|
||||
}
|
||||
|
@ -60,11 +62,14 @@ impl<S: 'static + Send + Sync, Marker: 'static + Send + Sync> Element for Div<S,
|
|||
cx.stack(0, |cx| style.paint(bounds, cx));
|
||||
|
||||
let overflow = &style.overflow;
|
||||
|
||||
style.apply_text_style(cx, |cx| {
|
||||
cx.stack(1, |cx| {
|
||||
style.apply_overflow(bounds, cx, |cx| {
|
||||
self.listeners.paint(bounds, cx);
|
||||
self.paint_children(overflow, state, cx)
|
||||
self.with_element_id(cx, |this, cx| {
|
||||
this.listeners.paint(bounds, cx);
|
||||
this.paint_children(overflow, state, cx)
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
|
@ -157,6 +162,18 @@ where
|
|||
child.paint(state, Some(scroll_offset), cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn with_element_id<R>(
|
||||
&mut self,
|
||||
cx: &mut ViewContext<S>,
|
||||
f: impl FnOnce(&mut Self, &mut ViewContext<S>) -> R,
|
||||
) -> R {
|
||||
if let Some(element_id) = self.element_id() {
|
||||
cx.with_element_id(element_id, |cx| f(self, cx))
|
||||
} else {
|
||||
f(self, cx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: 'static + Send + Sync, Marker: 'static + Send + Sync> Styled for Div<V, Marker> {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{
|
||||
AnyBox, AnyElement, Bounds, Element, Handle, IntoAnyElement, LayoutId, Pixels, ViewContext,
|
||||
WindowContext,
|
||||
AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, Handle, IdentifiedElement,
|
||||
IntoAnyElement, LayoutId, Pixels, ViewContext, WindowContext,
|
||||
};
|
||||
use std::{any::Any, marker::PhantomData, sync::Arc};
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub struct View<S: Send + Sync, P> {
|
|||
parent_state_type: PhantomData<P>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync, P: 'static + Send> View<S, P> {
|
||||
impl<S: 'static + Send + Sync, P: 'static + Send + Sync> View<S, P> {
|
||||
pub fn into_any(self) -> AnyView<P> {
|
||||
AnyView {
|
||||
view: Arc::new(Mutex::new(self)),
|
||||
|
@ -54,7 +54,7 @@ impl<S: 'static + Send + Sync, P: 'static + Send + Sync> Element for View<S, P>
|
|||
type ElementState = AnyElement<S>;
|
||||
|
||||
fn element_id(&self) -> Option<crate::ElementId> {
|
||||
None
|
||||
Some(ElementId::View(self.state.id))
|
||||
}
|
||||
|
||||
fn layout(
|
||||
|
@ -87,21 +87,27 @@ trait ViewObject: Send + 'static {
|
|||
fn paint(&mut self, bounds: Bounds<Pixels>, element: &mut dyn Any, cx: &mut WindowContext);
|
||||
}
|
||||
|
||||
impl<S: Send + Sync + 'static, P: Send + 'static> ViewObject for View<S, P> {
|
||||
impl<S: Send + Sync + 'static, P: Send + Sync + 'static> IdentifiedElement for View<S, P> {}
|
||||
|
||||
impl<S: Send + Sync + 'static, P: Send + Sync + 'static> ViewObject for View<S, P> {
|
||||
fn layout(&mut self, cx: &mut WindowContext) -> (LayoutId, AnyBox) {
|
||||
cx.with_element_id(IdentifiedElement::element_id(self), |cx| {
|
||||
self.state.update(cx, |state, cx| {
|
||||
let mut element = (self.render)(state, cx);
|
||||
let layout_id = element.layout(state, cx);
|
||||
let element = Box::new(element) as AnyBox;
|
||||
(layout_id, element)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn paint(&mut self, _: Bounds<Pixels>, element: &mut dyn Any, 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();
|
||||
element.paint(state, None, cx);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::{
|
|||
mem,
|
||||
sync::Arc,
|
||||
};
|
||||
use util::{arc_cow::ArcCow, ResultExt};
|
||||
use util::ResultExt;
|
||||
|
||||
#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Default)]
|
||||
pub struct StackingOrder(pub(crate) SmallVec<[u32; 16]>);
|
||||
|
@ -1110,22 +1110,19 @@ impl From<SmallVec<[u32; 16]>> for StackingOrder {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct ElementId(ArcCow<'static, [u8]>);
|
||||
pub enum ElementId {
|
||||
View(EntityId),
|
||||
Number(usize),
|
||||
}
|
||||
|
||||
impl From<usize> for ElementId {
|
||||
fn from(id: usize) -> Self {
|
||||
Self(id.to_ne_bytes().to_vec().into())
|
||||
ElementId::Number(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for ElementId {
|
||||
fn from(id: i32) -> Self {
|
||||
Self(id.to_ne_bytes().to_vec().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ElementId {
|
||||
fn from(id: &'static str) -> Self {
|
||||
Self(id.into())
|
||||
Self::Number(id as usize)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ impl Workspace {
|
|||
.flex_row()
|
||||
.overflow_hidden()
|
||||
.child(self.left_panel.clone())
|
||||
.child(div().h_full().flex_1()), // .child(self.right_panel.clone()),
|
||||
.child(div().h_full().flex_1())
|
||||
.child(self.right_panel.clone()),
|
||||
)
|
||||
.child(statusbar::statusbar(cx))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue