diff --git a/crates/gpui3/src/elements/hoverable.rs b/crates/gpui3/src/elements/hoverable.rs index 09ee6f77d1..60fbb53795 100644 --- a/crates/gpui3/src/elements/hoverable.rs +++ b/crates/gpui3/src/elements/hoverable.rs @@ -9,10 +9,7 @@ use std::sync::{ Arc, }; -pub struct Hoverable -// where -// ::Refinement: 'static + Send + Sync, -{ +pub struct Hoverable { hovered: Arc, cascade_slot: CascadeSlot, hovered_style: ::Refinement, diff --git a/crates/gpui3/src/elements/pressable.rs b/crates/gpui3/src/elements/pressable.rs index 67e1fe9ea5..ab586a125c 100644 --- a/crates/gpui3/src/elements/pressable.rs +++ b/crates/gpui3/src/elements/pressable.rs @@ -60,6 +60,10 @@ where type ViewState = E::ViewState; type ElementState = PressableState; + fn element_id(&self) -> Option { + Some(StatefulElement::element_id(&self.child)) + } + fn layout( &mut self, state: &mut Self::ViewState, @@ -103,7 +107,6 @@ where cx.on_mouse_event(move |_, event: &MouseDownEvent, phase, cx| { if phase == DispatchPhase::Capture { if bounds.contains_point(event.position) { - dbg!("pressed"); pressed.store(true, SeqCst); cx.notify(); } @@ -113,7 +116,6 @@ where cx.on_mouse_event(move |_, _: &MouseUpEvent, phase, cx| { if phase == DispatchPhase::Capture { if pressed.load(SeqCst) { - dbg!("released"); pressed.store(false, SeqCst); cx.notify(); } @@ -133,109 +135,10 @@ impl ParentElement for Pressable { } } -// use crate::{ -// element::{AnyElement, Element, IntoElement, Layout, ParentElement}, -// interactive::{InteractionHandlers, Interactive}, -// style::{Style, StyleHelpers, Styleable}, -// ViewContext, -// }; -// use anyhow::Result; -// use gpui::{geometry::vector::Vector2F, platform::MouseButtonEvent, LayoutId}; -// use refineable::{CascadeSlot, Refineable, RefinementCascade}; -// use smallvec::SmallVec; -// use std::{cell::Cell, rc::Rc}; - -// pub struct Pressable { -// pressed: Rc>, -// pressed_style: ::Refinement, -// cascade_slot: CascadeSlot, -// child: E, -// } - -// pub fn pressable(mut child: E) -> Pressable { -// Pressable { -// pressed: Rc::new(Cell::new(false)), -// pressed_style: Default::default(), -// cascade_slot: child.style_cascade().reserve(), -// child, -// } -// } - -// impl Styleable for Pressable { -// type Style = E::Style; - -// fn declared_style(&mut self) -> &mut ::Refinement { -// &mut self.pressed_style -// } - -// fn style_cascade(&mut self) -> &mut RefinementCascade { -// self.child.style_cascade() -// } -// } - -// impl + Styleable> Element for Pressable { -// type PaintState = E::PaintState; - -// fn layout( -// &mut self, -// view: &mut V, -// cx: &mut ViewContext, -// ) -> Result<(LayoutId, Self::PaintState)> -// where -// Self: Sized, -// { -// self.child.layout(view, cx) -// } - -// fn paint( -// &mut self, -// view: &mut V, -// parent_origin: Vector2F, -// layout: &Layout, -// paint_state: &mut Self::PaintState, -// cx: &mut ViewContext, -// ) where -// Self: Sized, -// { -// let slot = self.cascade_slot; -// let style = self.pressed.get().then_some(self.pressed_style.clone()); -// self.style_cascade().set(slot, style); - -// let pressed = self.pressed.clone(); -// let bounds = layout.bounds + parent_origin; -// cx.on_event(layout.order, move |_view, event: &MouseButtonEvent, cx| { -// if event.is_down { -// if bounds.contains_point(event.position) { -// pressed.set(true); -// cx.repaint(); -// } -// } else if pressed.get() { -// pressed.set(false); -// cx.repaint(); -// } -// }); - -// self.child -// .paint(view, parent_origin, layout, paint_state, cx); -// } -// } - -// impl + Styleable> Interactive for Pressable { -// fn interaction_handlers(&mut self) -> &mut InteractionHandlers { -// self.child.interaction_handlers() -// } -// } - -// impl + Styleable> ParentElement for Pressable { -// fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { -// self.child.children_mut() -// } -// } - -// impl + Styleable> IntoElement for Pressable { -// type Element = Self; - -// fn into_element(self) -> Self::Element { -// self -// } -// } +impl StatefulElement for Pressable +where + E: StatefulElement + Styled, + ::Style: 'static + Refineable + Send + Sync + Default, + <::Style as Refineable>::Refinement: 'static + Refineable + Send + Sync + Default, +{ +} diff --git a/crates/gpui3/src/text_system.rs b/crates/gpui3/src/text_system.rs index f42a884fe0..4ac98556b4 100644 --- a/crates/gpui3/src/text_system.rs +++ b/crates/gpui3/src/text_system.rs @@ -173,8 +173,8 @@ impl TextSystem { Ok(Line::new(layout.clone(), runs)) } - pub fn finish_frame(&self) { - self.text_layout_cache.finish_frame() + pub fn end_frame(&self) { + self.text_layout_cache.end_frame() } pub fn line_wrapper( diff --git a/crates/gpui3/src/text_system/text_layout_cache.rs b/crates/gpui3/src/text_system/text_layout_cache.rs index e02122478b..e9768aaf21 100644 --- a/crates/gpui3/src/text_system/text_layout_cache.rs +++ b/crates/gpui3/src/text_system/text_layout_cache.rs @@ -23,7 +23,7 @@ impl TextLayoutCache { } } - pub fn finish_frame(&self) { + pub fn end_frame(&self) { let mut prev_frame = self.prev_frame.lock(); let mut curr_frame = self.curr_frame.write(); std::mem::swap(&mut *prev_frame, &mut *curr_frame); diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index bf68cd679f..99ba8dc038 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -606,8 +606,9 @@ impl<'a, 'w> WindowContext<'a, 'w> { }; cx.window.root_view = Some(root_view); - let scene = cx.window.scene_builder.build(); + cx.end_frame(); + cx.run_on_main(view, |_, cx| { cx.window .platform_window @@ -650,6 +651,10 @@ impl<'a, 'w> WindowContext<'a, 'w> { .for_each(Vec::clear); } + fn end_frame(&mut self) { + self.text_system().end_frame(); + } + fn dispatch_event(&mut self, event: Event) -> bool { if let Some(any_mouse_event) = event.mouse_event() { if let Some(MouseMoveEvent { position, .. }) = any_mouse_event.downcast_ref() { @@ -791,7 +796,7 @@ pub trait BorrowWindow: BorrowAppContext { self.window_mut().element_id_stack.push(id); let global_id = self.window_mut().element_id_stack.clone(); - if let Some(any) = self + let result = if let Some(any) = self .window_mut() .element_states .remove(&global_id) @@ -816,7 +821,11 @@ pub trait BorrowWindow: BorrowAppContext { .element_states .insert(global_id, Box::new(Some(state))); result - } + }; + + self.window_mut().element_id_stack.pop(); + + result } fn content_mask(&self) -> ContentMask {