Fix panel resize (#3707)

* [x] Reposition right dock handle
* [x] Handle mouse events correctly for drag and drop
* [x] Prevent drag events from passing through the resize handle to the
draggable items in the panels (channels, files)
* [x] Stop the editor gutter from stealing mouse move events
This commit is contained in:
Max Brunsfeld
2023-12-19 09:08:56 -08:00
committed by GitHub
5 changed files with 568 additions and 553 deletions
-2
View File
@@ -564,8 +564,6 @@ impl EditorElement {
); );
} }
} }
cx.stop_propagation();
} else { } else {
update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx); update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx);
hover_at(editor, None, cx); hover_at(editor, None, cx);
File diff suppressed because it is too large Load Diff
+45 -47
View File
@@ -200,58 +200,56 @@ impl Element for UniformList {
bounds.lower_right() - point(border.right + padding.right, border.bottom), bounds.lower_right() - point(border.right + padding.right, border.bottom),
); );
cx.with_z_index(style.z_index.unwrap_or(0), |cx| { style.paint(bounds, cx, |cx| {
style.paint(bounds, cx, |cx| { if self.item_count > 0 {
if self.item_count > 0 { let content_height =
let content_height = item_height * self.item_count + padding.top + padding.bottom;
item_height * self.item_count + padding.top + padding.bottom; let min_scroll_offset = padded_bounds.size.height - content_height;
let min_scroll_offset = padded_bounds.size.height - content_height; let is_scrolled = scroll_offset.y != px(0.);
let is_scrolled = scroll_offset.y != px(0.);
if is_scrolled && scroll_offset.y < min_scroll_offset { if is_scrolled && scroll_offset.y < min_scroll_offset {
shared_scroll_offset.borrow_mut().y = min_scroll_offset; shared_scroll_offset.borrow_mut().y = min_scroll_offset;
scroll_offset.y = min_scroll_offset; scroll_offset.y = min_scroll_offset;
} }
if let Some(scroll_handle) = self.scroll_handle.clone() { if let Some(scroll_handle) = self.scroll_handle.clone() {
scroll_handle.0.borrow_mut().replace(ScrollHandleState { scroll_handle.0.borrow_mut().replace(ScrollHandleState {
item_height, item_height,
list_height: padded_bounds.size.height, list_height: padded_bounds.size.height,
scroll_offset: shared_scroll_offset, scroll_offset: shared_scroll_offset,
});
}
let first_visible_element_ix =
(-(scroll_offset.y + padding.top) / item_height).floor() as usize;
let last_visible_element_ix =
((-scroll_offset.y + padded_bounds.size.height) / item_height)
.ceil() as usize;
let visible_range = first_visible_element_ix
..cmp::min(last_visible_element_ix, self.item_count);
let mut items = (self.render_items)(visible_range.clone(), cx);
cx.with_z_index(1, |cx| {
let content_mask = ContentMask { bounds };
cx.with_content_mask(Some(content_mask), |cx| {
for (item, ix) in items.iter_mut().zip(visible_range) {
let item_origin = padded_bounds.origin
+ point(
px(0.),
item_height * ix + scroll_offset.y + padding.top,
);
let available_space = size(
AvailableSpace::Definite(padded_bounds.size.width),
AvailableSpace::Definite(item_height),
);
item.draw(item_origin, available_space, cx);
}
});
}); });
} }
});
}) let first_visible_element_ix =
(-(scroll_offset.y + padding.top) / item_height).floor() as usize;
let last_visible_element_ix =
((-scroll_offset.y + padded_bounds.size.height) / item_height).ceil()
as usize;
let visible_range = first_visible_element_ix
..cmp::min(last_visible_element_ix, self.item_count);
let mut items = (self.render_items)(visible_range.clone(), cx);
cx.with_z_index(1, |cx| {
let content_mask = ContentMask { bounds };
cx.with_content_mask(Some(content_mask), |cx| {
for (item, ix) in items.iter_mut().zip(visible_range) {
let item_origin = padded_bounds.origin
+ point(
px(0.),
item_height * ix + scroll_offset.y + padding.top,
);
let available_space = size(
AvailableSpace::Definite(padded_bounds.size.width),
AvailableSpace::Definite(item_height),
);
item.draw(item_origin, available_space, cx);
}
});
});
}
});
}, },
); )
} }
} }
+20 -13
View File
@@ -946,16 +946,20 @@ impl<'a> WindowContext<'a> {
} }
} }
/// Returns true if the top-most opaque layer painted over this point was part of the /// Returns true if there is no opaque layer containing the given point
/// same layer as the given stacking order. /// on top of the given level. Layers whose level is an extension of the
/// level are not considered to be on top of the level.
pub fn was_top_layer(&self, point: &Point<Pixels>, level: &StackingOrder) -> bool { pub fn was_top_layer(&self, point: &Point<Pixels>, level: &StackingOrder) -> bool {
for (stack, bounds) in self.window.rendered_frame.depth_map.iter() { for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() {
if bounds.contains(point) { if level >= opaque_level {
return level.starts_with(stack) || stack.starts_with(level); break;
}
if bounds.contains(point) && !opaque_level.starts_with(level) {
return false;
} }
} }
true
false
} }
pub fn was_top_layer_under_active_drag( pub fn was_top_layer_under_active_drag(
@@ -963,16 +967,19 @@ impl<'a> WindowContext<'a> {
point: &Point<Pixels>, point: &Point<Pixels>,
level: &StackingOrder, level: &StackingOrder,
) -> bool { ) -> bool {
for (stack, bounds) in self.window.rendered_frame.depth_map.iter() { for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() {
if stack.starts_with(&[ACTIVE_DRAG_Z_INDEX]) { if level >= opaque_level {
break;
}
if opaque_level.starts_with(&[ACTIVE_DRAG_Z_INDEX]) {
continue; continue;
} }
if bounds.contains(point) {
return level.starts_with(stack) || stack.starts_with(level); if bounds.contains(point) && !opaque_level.starts_with(level) {
return false;
} }
} }
true
false
} }
/// Called during painting to get the current stacking order. /// Called during painting to get the current stacking order.
+5 -3
View File
@@ -490,11 +490,13 @@ impl Render for Dock {
let mut handle = div() let mut handle = div()
.id("resize-handle") .id("resize-handle")
.on_drag(DraggedDock(position), |dock, cx| { .on_drag(DraggedDock(position), |dock, cx| {
cx.stop_propagation();
cx.build_view(|_| dock.clone()) cx.build_view(|_| dock.clone())
}) })
.on_click(cx.listener(|v, e: &ClickEvent, cx| { .on_click(cx.listener(|v, e: &ClickEvent, cx| {
if e.down.button == MouseButton::Left && e.down.click_count == 2 { if e.down.button == MouseButton::Left && e.down.click_count == 2 {
v.resize_active_panel(None, cx) v.resize_active_panel(None, cx);
cx.stop_propagation();
} }
})) }))
.z_index(1); .z_index(1);
@@ -525,8 +527,8 @@ impl Render for Dock {
.absolute() .absolute()
.top(px(0.)) .top(px(0.))
.left(px(0.)) .left(px(0.))
.w_full() .h_full()
.h(HANDLE_SIZE) .w(HANDLE_SIZE)
.cursor_col_resize(); .cursor_col_resize();
} }
} }