Add a double click to reset resized splits (#2762)
fixes https://github.com/zed-industries/community/issues/1791 Release Notes: - Double clicking on split resize handles now resets the split's dimensions
This commit is contained in:
commit
0e9cad4935
1 changed files with 64 additions and 48 deletions
|
@ -826,63 +826,79 @@ mod element {
|
||||||
let child_size = child.size();
|
let child_size = child.size();
|
||||||
let next_child_size = next_child.size();
|
let next_child_size = next_child.size();
|
||||||
let drag_bounds = visible_bounds.clone();
|
let drag_bounds = visible_bounds.clone();
|
||||||
let flexes = self.flexes.clone();
|
let flexes = self.flexes.borrow();
|
||||||
let current_flex = flexes.borrow()[ix];
|
let current_flex = flexes[ix];
|
||||||
let next_ix = *next_ix;
|
let next_ix = *next_ix;
|
||||||
let next_flex = flexes.borrow()[next_ix];
|
let next_flex = flexes[next_ix];
|
||||||
|
drop(flexes);
|
||||||
enum ResizeHandle {}
|
enum ResizeHandle {}
|
||||||
let mut mouse_region = MouseRegion::new::<ResizeHandle>(
|
let mut mouse_region = MouseRegion::new::<ResizeHandle>(
|
||||||
cx.view_id(),
|
cx.view_id(),
|
||||||
self.basis + ix,
|
self.basis + ix,
|
||||||
handle_bounds,
|
handle_bounds,
|
||||||
);
|
);
|
||||||
mouse_region = mouse_region.on_drag(
|
mouse_region = mouse_region
|
||||||
MouseButton::Left,
|
.on_drag(MouseButton::Left, {
|
||||||
move |drag, workspace: &mut Workspace, cx| {
|
let flexes = self.flexes.clone();
|
||||||
let min_size = match axis {
|
move |drag, workspace: &mut Workspace, cx| {
|
||||||
Axis::Horizontal => HORIZONTAL_MIN_SIZE,
|
let min_size = match axis {
|
||||||
Axis::Vertical => VERTICAL_MIN_SIZE,
|
Axis::Horizontal => HORIZONTAL_MIN_SIZE,
|
||||||
};
|
Axis::Vertical => VERTICAL_MIN_SIZE,
|
||||||
// Don't allow resizing to less than the minimum size, if elements are already too small
|
};
|
||||||
if min_size - 1. > child_size.along(axis)
|
// Don't allow resizing to less than the minimum size, if elements are already too small
|
||||||
|| min_size - 1. > next_child_size.along(axis)
|
if min_size - 1. > child_size.along(axis)
|
||||||
{
|
|| min_size - 1. > next_child_size.along(axis)
|
||||||
return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut current_target_size =
|
||||||
|
(drag.position - child_start).along(axis);
|
||||||
|
|
||||||
|
let proposed_current_pixel_change =
|
||||||
|
current_target_size - child_size.along(axis);
|
||||||
|
|
||||||
|
if proposed_current_pixel_change < 0. {
|
||||||
|
current_target_size = f32::max(current_target_size, min_size);
|
||||||
|
} else if proposed_current_pixel_change > 0. {
|
||||||
|
// TODO: cascade this change to other children if current item is at min size
|
||||||
|
let next_target_size = f32::max(
|
||||||
|
next_child_size.along(axis) - proposed_current_pixel_change,
|
||||||
|
min_size,
|
||||||
|
);
|
||||||
|
current_target_size = f32::min(
|
||||||
|
current_target_size,
|
||||||
|
child_size.along(axis) + next_child_size.along(axis)
|
||||||
|
- next_target_size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_pixel_change =
|
||||||
|
current_target_size - child_size.along(axis);
|
||||||
|
let flex_change =
|
||||||
|
current_pixel_change / drag_bounds.length_along(axis);
|
||||||
|
let current_target_flex = current_flex + flex_change;
|
||||||
|
let next_target_flex = next_flex - flex_change;
|
||||||
|
|
||||||
|
let mut borrow = flexes.borrow_mut();
|
||||||
|
*borrow.get_mut(ix).unwrap() = current_target_flex;
|
||||||
|
*borrow.get_mut(next_ix).unwrap() = next_target_flex;
|
||||||
|
|
||||||
|
workspace.schedule_serialize(cx);
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
let mut current_target_size = (drag.position - child_start).along(axis);
|
.on_click(MouseButton::Left, {
|
||||||
|
let flexes = self.flexes.clone();
|
||||||
let proposed_current_pixel_change =
|
move |e, v: &mut Workspace, cx| {
|
||||||
current_target_size - child_size.along(axis);
|
if e.click_count >= 2 {
|
||||||
|
let mut borrow = flexes.borrow_mut();
|
||||||
if proposed_current_pixel_change < 0. {
|
*borrow = vec![1.; borrow.len()];
|
||||||
current_target_size = f32::max(current_target_size, min_size);
|
v.schedule_serialize(cx);
|
||||||
} else if proposed_current_pixel_change > 0. {
|
cx.notify();
|
||||||
// TODO: cascade this change to other children if current item is at min size
|
}
|
||||||
let next_target_size = f32::max(
|
|
||||||
next_child_size.along(axis) - proposed_current_pixel_change,
|
|
||||||
min_size,
|
|
||||||
);
|
|
||||||
current_target_size = f32::min(
|
|
||||||
current_target_size,
|
|
||||||
child_size.along(axis) + next_child_size.along(axis)
|
|
||||||
- next_target_size,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
let current_pixel_change = current_target_size - child_size.along(axis);
|
|
||||||
let flex_change = current_pixel_change / drag_bounds.length_along(axis);
|
|
||||||
let current_target_flex = current_flex + flex_change;
|
|
||||||
let next_target_flex = next_flex - flex_change;
|
|
||||||
|
|
||||||
let mut borrow = flexes.borrow_mut();
|
|
||||||
*borrow.get_mut(ix).unwrap() = current_target_flex;
|
|
||||||
*borrow.get_mut(next_ix).unwrap() = next_target_flex;
|
|
||||||
|
|
||||||
workspace.schedule_serialize(cx);
|
|
||||||
cx.notify();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
scene.push_mouse_region(mouse_region);
|
scene.push_mouse_region(mouse_region);
|
||||||
|
|
||||||
scene.pop_stacking_context();
|
scene.pop_stacking_context();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue