summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-10-24 14:17:38 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-10-24 14:17:38 +0200
commitd08bc6e45d12c7a5e4037c20673ff832eb7802ec (patch)
treee151b781cb424b50caed6f4eceb6d28131a96cc6 /widget
parent55504ffcd41a5f1c8c35889501337a729b6aac28 (diff)
downloadiced-d08bc6e45d12c7a5e4037c20673ff832eb7802ec.tar.gz
iced-d08bc6e45d12c7a5e4037c20673ff832eb7802ec.tar.bz2
iced-d08bc6e45d12c7a5e4037c20673ff832eb7802ec.zip
Add `relabel` helper to `pane_grid::State`
Diffstat (limited to 'widget')
-rw-r--r--widget/src/pane_grid/state.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs
index 67cd3bf2..2f8a64ea 100644
--- a/widget/src/pane_grid/state.rs
+++ b/widget/src/pane_grid/state.rs
@@ -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);
@@ -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