@@ -289,30 +289,23 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> {
}
}
- fn immutable(app: &'a AppContext, entity_id: EntityId) -> Self {
- Self {
- app: Reference::Immutable(app),
- entity_type: PhantomData,
- entity_id,
- }
- }
-
- fn update<R>(&mut self, update: impl FnOnce(&mut T, &mut Self) -> R) -> R {
- let mut entity = self
- .app
- .entities
- .get_mut(self.entity_id)
- .unwrap()
- .take()
- .unwrap();
- let result = update(entity.downcast_mut::<T>().unwrap(), self);
- self.app
- .entities
- .get_mut(self.entity_id)
- .unwrap()
- .replace(entity);
- result
- }
+ // todo!
+ // fn update<R>(&mut self, update: impl FnOnce(&mut T, &mut Self) -> R) -> R {
+ // let mut entity = self
+ // .app
+ // .entities
+ // .get_mut(self.entity_id)
+ // .unwrap()
+ // .take()
+ // .unwrap();
+ // let result = update(entity.downcast_mut::<T>().unwrap(), self);
+ // self.app
+ // .entities
+ // .get_mut(self.entity_id)
+ // .unwrap()
+ // .replace(entity);
+ // result
+ // }
pub fn handle(&self) -> WeakHandle<T> {
WeakHandle {
@@ -420,7 +413,7 @@ pub struct WeakHandle<T> {
}
impl<T: Send + Sync + 'static> WeakHandle<T> {
- pub fn upgrade(&self, cx: &impl Context) -> Option<Handle<T>> {
+ pub fn upgrade(&self, _: &impl Context) -> Option<Handle<T>> {
// todo!("Actually upgrade")
Some(Handle {
id: self.id,
@@ -149,7 +149,7 @@ impl<V: 'static> Div<V> {
fn handle_scroll(
&mut self,
- order: u32,
+ _order: u32,
bounds: Bounds<Pixels>,
overflow: Point<Overflow>,
child_layout_ids: &[LayoutId],
@@ -164,6 +164,7 @@ impl<V: 'static> Div<V> {
}
scroll_max -= bounds.size;
+ // todo!("handle scroll")
// let scroll_state = self.scroll_state.as_ref().unwrap().clone();
// cx.on_event(order, move |_, event: &ScrollWheelEvent, cx| {
// if bounds.contains_point(event.position) {
@@ -193,56 +194,56 @@ impl<V: 'static> Div<V> {
}
}
- fn paint_inspector(
- &self,
- parent_origin: Point<Pixels>,
- layout: &Layout,
- cx: &mut ViewContext<V>,
- ) {
- let style = self.styles.merged();
- let bounds = layout.bounds;
-
- let hovered = bounds.contains_point(cx.mouse_position());
- if hovered {
- let rem_size = cx.rem_size();
- // cx.scene().push_quad(scene::Quad {
- // bounds,
- // background: Some(hsla(0., 0., 1., 0.05).into()),
- // border: gpui::Border {
- // color: hsla(0., 0., 1., 0.2).into(),
- // top: 1.,
- // right: 1.,
- // bottom: 1.,
- // left: 1.,
- // },
- // corner_radii: CornerRadii::default()
- // .refined(&style.corner_radii)
- // .to_gpui(bounds.size(), rem_size),
- // })
- }
-
- // let pressed = Cell::new(hovered && cx.is_mouse_down(MouseButton::Left));
- // cx.on_event(layout.order, move |_, event: &MouseButtonEvent, _| {
- // if bounds.contains_point(event.position) {
- // if event.is_down {
- // pressed.set(true);
- // } else if pressed.get() {
- // pressed.set(false);
- // eprintln!("clicked div {:?} {:#?}", bounds, style);
- // }
- // }
- // });
-
- // let hovered = Cell::new(hovered);
- // cx.on_event(layout.order, move |_, event: &MouseMovedEvent, cx| {
- // cx.bubble_event();
- // let hovered_now = bounds.contains_point(event.position);
- // if hovered.get() != hovered_now {
- // hovered.set(hovered_now);
- // cx.repaint();
- // }
- // });
- }
+ // fn paint_inspector(
+ // &self,
+ // parent_origin: Point<Pixels>,
+ // layout: &Layout,
+ // cx: &mut ViewContext<V>,
+ // ) {
+ // let style = self.styles.merged();
+ // let bounds = layout.bounds;
+
+ // let hovered = bounds.contains_point(cx.mouse_position());
+ // if hovered {
+ // let rem_size = cx.rem_size();
+ // // cx.scene().push_quad(scene::Quad {
+ // // bounds,
+ // // background: Some(hsla(0., 0., 1., 0.05).into()),
+ // // border: gpui::Border {
+ // // color: hsla(0., 0., 1., 0.2).into(),
+ // // top: 1.,
+ // // right: 1.,
+ // // bottom: 1.,
+ // // left: 1.,
+ // // },
+ // // corner_radii: CornerRadii::default()
+ // // .refined(&style.corner_radii)
+ // // .to_gpui(bounds.size(), rem_size),
+ // // })
+ // }
+
+ // // let pressed = Cell::new(hovered && cx.is_mouse_down(MouseButton::Left));
+ // // cx.on_event(layout.order, move |_, event: &MouseButtonEvent, _| {
+ // // if bounds.contains_point(event.position) {
+ // // if event.is_down {
+ // // pressed.set(true);
+ // // } else if pressed.get() {
+ // // pressed.set(false);
+ // // eprintln!("clicked div {:?} {:#?}", bounds, style);
+ // // }
+ // // }
+ // // });
+
+ // // let hovered = Cell::new(hovered);
+ // // cx.on_event(layout.order, move |_, event: &MouseMovedEvent, cx| {
+ // // cx.bubble_event();
+ // // let hovered_now = bounds.contains_point(event.position);
+ // // if hovered.get() != hovered_now {
+ // // hovered.set(hovered_now);
+ // // cx.repaint();
+ // // }
+ // // });
+ // }
}
impl<V> Styled for Div<V> {
@@ -24,7 +24,7 @@ pub struct Window {
content_size: Size<Pixels>,
layout_engine: TaffyLayoutEngine,
text_style_stack: Vec<TextStyleRefinement>,
- cascading_states: HashMap<TypeId, Vec<Box<dyn Any + Send + Sync>>>,
+ state_stacks_by_type: HashMap<TypeId, Vec<Box<dyn Any + Send + Sync>>>,
pub(crate) root_view: Option<AnyView<()>>,
mouse_position: Point<Pixels>,
pub(crate) scene: Scene,
@@ -64,7 +64,7 @@ impl Window {
content_size,
layout_engine: TaffyLayoutEngine::new(),
text_style_stack: Vec::new(),
- cascading_states: HashMap::default(),
+ state_stacks_by_type: HashMap::default(),
root_view: None,
mouse_position,
scene: Scene::new(scale_factor),
@@ -168,7 +168,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
pub fn push_cascading_state<T: Send + Sync + 'static>(&mut self, theme: T) {
self.window
- .cascading_states
+ .state_stacks_by_type
.entry(TypeId::of::<T>())
.or_default()
.push(Box::new(theme));
@@ -176,7 +176,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
pub fn pop_cascading_state<T: Send + Sync + 'static>(&mut self) {
self.window
- .cascading_states
+ .state_stacks_by_type
.get_mut(&TypeId::of::<T>())
.and_then(|stack| stack.pop())
.expect("cascading state not found");
@@ -185,7 +185,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
pub fn cascading_state<T: Send + Sync + 'static>(&self) -> &T {
let type_id = TypeId::of::<T>();
self.window
- .cascading_states
+ .state_stacks_by_type
.get(&type_id)
.and_then(|stack| stack.last())
.expect("no cascading state of the specified type has been pushed")