Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-27 17:25:04 -06:00
parent 96f9c67e77
commit b364d404a9
3 changed files with 72 additions and 78 deletions

View file

@ -289,30 +289,23 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> {
} }
} }
fn immutable(app: &'a AppContext, entity_id: EntityId) -> Self { // todo!
Self { // fn update<R>(&mut self, update: impl FnOnce(&mut T, &mut Self) -> R) -> R {
app: Reference::Immutable(app), // let mut entity = self
entity_type: PhantomData, // .app
entity_id, // .entities
} // .get_mut(self.entity_id)
} // .unwrap()
// .take()
fn update<R>(&mut self, update: impl FnOnce(&mut T, &mut Self) -> R) -> R { // .unwrap();
let mut entity = self // let result = update(entity.downcast_mut::<T>().unwrap(), self);
.app // self.app
.entities // .entities
.get_mut(self.entity_id) // .get_mut(self.entity_id)
.unwrap() // .unwrap()
.take() // .replace(entity);
.unwrap(); // result
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> { pub fn handle(&self) -> WeakHandle<T> {
WeakHandle { WeakHandle {
@ -420,7 +413,7 @@ pub struct WeakHandle<T> {
} }
impl<T: Send + Sync + 'static> 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") // todo!("Actually upgrade")
Some(Handle { Some(Handle {
id: self.id, id: self.id,

View file

@ -149,7 +149,7 @@ impl<V: 'static> Div<V> {
fn handle_scroll( fn handle_scroll(
&mut self, &mut self,
order: u32, _order: u32,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
overflow: Point<Overflow>, overflow: Point<Overflow>,
child_layout_ids: &[LayoutId], child_layout_ids: &[LayoutId],
@ -164,6 +164,7 @@ impl<V: 'static> Div<V> {
} }
scroll_max -= bounds.size; scroll_max -= bounds.size;
// todo!("handle scroll")
// let scroll_state = self.scroll_state.as_ref().unwrap().clone(); // let scroll_state = self.scroll_state.as_ref().unwrap().clone();
// cx.on_event(order, move |_, event: &ScrollWheelEvent, cx| { // cx.on_event(order, move |_, event: &ScrollWheelEvent, cx| {
// if bounds.contains_point(event.position) { // if bounds.contains_point(event.position) {
@ -193,56 +194,56 @@ impl<V: 'static> Div<V> {
} }
} }
fn paint_inspector( // fn paint_inspector(
&self, // &self,
parent_origin: Point<Pixels>, // parent_origin: Point<Pixels>,
layout: &Layout, // layout: &Layout,
cx: &mut ViewContext<V>, // cx: &mut ViewContext<V>,
) { // ) {
let style = self.styles.merged(); // let style = self.styles.merged();
let bounds = layout.bounds; // let bounds = layout.bounds;
let hovered = bounds.contains_point(cx.mouse_position()); // let hovered = bounds.contains_point(cx.mouse_position());
if hovered { // if hovered {
let rem_size = cx.rem_size(); // let rem_size = cx.rem_size();
// cx.scene().push_quad(scene::Quad { // // cx.scene().push_quad(scene::Quad {
// bounds, // // bounds,
// background: Some(hsla(0., 0., 1., 0.05).into()), // // background: Some(hsla(0., 0., 1., 0.05).into()),
// border: gpui::Border { // // border: gpui::Border {
// color: hsla(0., 0., 1., 0.2).into(), // // color: hsla(0., 0., 1., 0.2).into(),
// top: 1., // // top: 1.,
// right: 1., // // right: 1.,
// bottom: 1., // // bottom: 1.,
// left: 1., // // left: 1.,
// }, // // },
// corner_radii: CornerRadii::default() // // corner_radii: CornerRadii::default()
// .refined(&style.corner_radii) // // .refined(&style.corner_radii)
// .to_gpui(bounds.size(), rem_size), // // .to_gpui(bounds.size(), rem_size),
// }) // // })
} // }
// let pressed = Cell::new(hovered && cx.is_mouse_down(MouseButton::Left)); // // let pressed = Cell::new(hovered && cx.is_mouse_down(MouseButton::Left));
// cx.on_event(layout.order, move |_, event: &MouseButtonEvent, _| { // // cx.on_event(layout.order, move |_, event: &MouseButtonEvent, _| {
// if bounds.contains_point(event.position) { // // if bounds.contains_point(event.position) {
// if event.is_down { // // if event.is_down {
// pressed.set(true); // // pressed.set(true);
// } else if pressed.get() { // // } else if pressed.get() {
// pressed.set(false); // // pressed.set(false);
// eprintln!("clicked div {:?} {:#?}", bounds, style); // // eprintln!("clicked div {:?} {:#?}", bounds, style);
// } // // }
// } // // }
// }); // // });
// let hovered = Cell::new(hovered); // // let hovered = Cell::new(hovered);
// cx.on_event(layout.order, move |_, event: &MouseMovedEvent, cx| { // // cx.on_event(layout.order, move |_, event: &MouseMovedEvent, cx| {
// cx.bubble_event(); // // cx.bubble_event();
// let hovered_now = bounds.contains_point(event.position); // // let hovered_now = bounds.contains_point(event.position);
// if hovered.get() != hovered_now { // // if hovered.get() != hovered_now {
// hovered.set(hovered_now); // // hovered.set(hovered_now);
// cx.repaint(); // // cx.repaint();
// // }
// // });
// } // }
// });
}
} }
impl<V> Styled for Div<V> { impl<V> Styled for Div<V> {

View file

@ -24,7 +24,7 @@ pub struct Window {
content_size: Size<Pixels>, content_size: Size<Pixels>,
layout_engine: TaffyLayoutEngine, layout_engine: TaffyLayoutEngine,
text_style_stack: Vec<TextStyleRefinement>, 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<()>>, pub(crate) root_view: Option<AnyView<()>>,
mouse_position: Point<Pixels>, mouse_position: Point<Pixels>,
pub(crate) scene: Scene, pub(crate) scene: Scene,
@ -64,7 +64,7 @@ impl Window {
content_size, content_size,
layout_engine: TaffyLayoutEngine::new(), layout_engine: TaffyLayoutEngine::new(),
text_style_stack: Vec::new(), text_style_stack: Vec::new(),
cascading_states: HashMap::default(), state_stacks_by_type: HashMap::default(),
root_view: None, root_view: None,
mouse_position, mouse_position,
scene: Scene::new(scale_factor), 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) { pub fn push_cascading_state<T: Send + Sync + 'static>(&mut self, theme: T) {
self.window self.window
.cascading_states .state_stacks_by_type
.entry(TypeId::of::<T>()) .entry(TypeId::of::<T>())
.or_default() .or_default()
.push(Box::new(theme)); .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) { pub fn pop_cascading_state<T: Send + Sync + 'static>(&mut self) {
self.window self.window
.cascading_states .state_stacks_by_type
.get_mut(&TypeId::of::<T>()) .get_mut(&TypeId::of::<T>())
.and_then(|stack| stack.pop()) .and_then(|stack| stack.pop())
.expect("cascading state not found"); .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 { pub fn cascading_state<T: Send + Sync + 'static>(&self) -> &T {
let type_id = TypeId::of::<T>(); let type_id = TypeId::of::<T>();
self.window self.window
.cascading_states .state_stacks_by_type
.get(&type_id) .get(&type_id)
.and_then(|stack| stack.last()) .and_then(|stack| stack.last())
.expect("no cascading state of the specified type has been pushed") .expect("no cascading state of the specified type has been pushed")