Skip to content

Commit

Permalink
Add relabel helper to pane_grid::State
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Oct 24, 2024
1 parent 55504ff commit d08bc6e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions widget/src/pane_grid/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,8 @@ impl<T> State<T> {
) {
if let Some((state, _)) = self.close(pane) {
if let Some((new_pane, _)) = self.split(axis, target, state) {
// Ensure new node corresponds to original `Pane` for state continuity
self.swap(pane, new_pane);
let _ = self
.panes
.remove(&new_pane)
.and_then(|state| self.panes.insert(pane, state));
// Ensure new node corresponds to original closed `Pane` for state continuity
self.relabel(new_pane, pane);

if swap {
self.swap(target, pane);
Expand Down Expand Up @@ -258,22 +254,27 @@ impl<T> State<T> {
&mut self,
axis: Axis,
pane: Pane,
swap: bool,
inverse: bool,
) {
if let Some((state, _)) = self.close(pane) {
if let Some((new_pane, _)) =
self.split_node(axis, None, state, swap)
self.split_node(axis, None, state, inverse)
{
// Ensure new node corresponds to original `Pane` for state continuity
self.swap(pane, new_pane);
let _ = self
.panes
.remove(&new_pane)
.and_then(|state| self.panes.insert(pane, state));
// Ensure new node corresponds to original closed `Pane` for state continuity
self.relabel(new_pane, pane);
}
}
}

fn relabel(&mut self, target: Pane, label: Pane) {
self.swap(target, label);

let _ = self
.panes
.remove(&target)
.and_then(|state| self.panes.insert(label, state));
}

/// Swaps the position of the provided panes in the [`State`].
///
/// If you want to swap panes on drag and drop in your [`PaneGrid`], you
Expand Down

0 comments on commit d08bc6e

Please sign in to comment.