Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nathansobo committed Dec 14, 2023
1 parent c863227 commit 6f17cf7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
16 changes: 8 additions & 8 deletions crates/gpui2/src/elements/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,28 +778,28 @@ impl Interactivity {
});
}

for listener in self.mouse_down_listeners.drain(..) {
for listener in self.mouse_down_listeners {
let interactive_bounds = interactive_bounds.clone();
cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
listener(event, &*interactive_bounds, phase, cx);
})
}

for listener in self.mouse_up_listeners.drain(..) {
for listener in self.mouse_up_listeners {
let interactive_bounds = interactive_bounds.clone();
cx.on_mouse_event(move |event: &MouseUpEvent, phase, cx| {
listener(event, &*interactive_bounds, phase, cx);
})
}

for listener in self.mouse_move_listeners.drain(..) {
for listener in self.mouse_move_listeners {
let interactive_bounds = interactive_bounds.clone();
cx.on_mouse_event(move |event: &MouseMoveEvent, phase, cx| {
listener(event, &*interactive_bounds, phase, cx);
})
}

for listener in self.scroll_wheel_listeners.drain(..) {
for listener in self.scroll_wheel_listeners {
let interactive_bounds = interactive_bounds.clone();
cx.on_mouse_event(move |event: &ScrollWheelEvent, phase, cx| {
listener(event, &*interactive_bounds, phase, cx);
Expand Down Expand Up @@ -868,8 +868,8 @@ impl Interactivity {
}
}

let click_listeners = mem::take(&mut self.click_listeners);
let drag_listener = mem::take(&mut self.drag_listener);
let click_listeners = self.click_listeners;
let drag_listener = self.drag_listener;

if !click_listeners.is_empty() || drag_listener.is_some() {
let pending_mouse_down = element_state.pending_mouse_down.clone();
Expand Down Expand Up @@ -1086,13 +1086,13 @@ impl Interactivity {
self.key_context.clone(),
element_state.focus_handle.clone(),
|_, cx| {
for listener in self.key_down_listeners.drain(..) {
for listener in self.key_down_listeners {
cx.on_key_event(move |event: &KeyDownEvent, phase, cx| {
listener(event, phase, cx);
})
}

for listener in self.key_up_listeners.drain(..) {
for listener in self.key_up_listeners {
cx.on_key_event(move |event: &KeyUpEvent, phase, cx| {
listener(event, phase, cx);
})
Expand Down
5 changes: 5 additions & 0 deletions crates/gpui2/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ impl AnyView {
cx: &mut WindowContext,
) {
cx.with_absolute_element_offset(origin, |cx| {
let start_time = std::time::Instant::now();
let (layout_id, rendered_element) = (self.layout)(self, cx);
let duration = start_time.elapsed();
println!("request layout: {:?}", duration);

let start_time = std::time::Instant::now();
cx.compute_layout(layout_id, available_space);
let duration = start_time.elapsed();
println!("compute layout: {:?}", duration);

let start_time = std::time::Instant::now();
(self.paint)(self, rendered_element, cx);
let duration = start_time.elapsed();
Expand Down
34 changes: 26 additions & 8 deletions crates/gpui2/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,26 @@ const ACTIVE_DRAG_Z_INDEX: u32 = 1;

/// A global stacking order, which is created by stacking successive z-index values.
/// Each z-index will always be interpreted in the context of its parent z-index.
#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Default, Debug)]
pub struct StackingOrder(pub(crate) SmallVec<[u32; 16]>);
#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Debug)]
pub struct StackingOrder(pub(crate) Arc<Vec<u32>>);

impl Default for StackingOrder {
fn default() -> Self {
StackingOrder(Arc::new(Vec::new()))
}
}

impl StackingOrder {
/// Pushes a new z-index onto the stacking order.
pub fn push(&mut self, z_index: u32) {
Arc::make_mut(&mut self.0).push(z_index);
}

/// Pops the last z-index off the stacking order.
pub fn pop(&mut self) {
Arc::make_mut(&mut self.0).pop();
}
}

/// Represents the two different phases when dispatching events.
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -2892,12 +2910,12 @@ impl AnyWindowHandle {
}
}

#[cfg(any(test, feature = "test-support"))]
impl From<SmallVec<[u32; 16]>> for StackingOrder {
fn from(small_vec: SmallVec<[u32; 16]>) -> Self {
StackingOrder(small_vec)
}
}
// #[cfg(any(test, feature = "test-support"))]
// impl From<SmallVec<[u32; 16]>> for StackingOrder {
// fn from(small_vec: SmallVec<[u32; 16]>) -> Self {
// StackingOrder(small_vec)
// }
// }

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum ElementId {
Expand Down
8 changes: 8 additions & 0 deletions debug.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>

0 comments on commit 6f17cf7

Please sign in to comment.