Introduce drop helper to pane_grid::State
This commit is contained in:
parent
ecce8bbcee
commit
c5a623f32b
2 changed files with 37 additions and 32 deletions
|
|
@ -108,14 +108,9 @@ impl Application for Example {
|
||||||
Message::Dragged(pane_grid::DragEvent::Dropped {
|
Message::Dragged(pane_grid::DragEvent::Dropped {
|
||||||
pane,
|
pane,
|
||||||
target,
|
target,
|
||||||
}) => match target {
|
}) => {
|
||||||
pane_grid::Target::Edge(edge) => {
|
self.panes.drop(&pane, target);
|
||||||
self.panes.move_to_edge(&pane, edge)
|
}
|
||||||
}
|
|
||||||
pane_grid::Target::Pane(target, region) => {
|
|
||||||
self.panes.split_with(&target, &pane, region)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Message::Dragged(_) => {}
|
Message::Dragged(_) => {}
|
||||||
Message::TogglePin(pane) => {
|
Message::TogglePin(pane) => {
|
||||||
if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane)
|
if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//! [`PaneGrid`]: crate::widget::PaneGrid
|
//! [`PaneGrid`]: crate::widget::PaneGrid
|
||||||
use crate::core::{Point, Size};
|
use crate::core::{Point, Size};
|
||||||
use crate::pane_grid::{
|
use crate::pane_grid::{
|
||||||
Axis, Configuration, Direction, Edge, Node, Pane, Region, Split,
|
Axis, Configuration, Direction, Edge, Node, Pane, Region, Split, Target,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
@ -148,6 +148,39 @@ impl<T> State<T> {
|
||||||
self.split_node(axis, Some(pane), state, false)
|
self.split_node(axis, Some(pane), state, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
|
||||||
|
///
|
||||||
|
/// Panes will be swapped by default for [`Region::Center`].
|
||||||
|
pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) {
|
||||||
|
match region {
|
||||||
|
Region::Center => self.swap(pane, target),
|
||||||
|
Region::Edge(edge) => match edge {
|
||||||
|
Edge::Top => {
|
||||||
|
self.split_and_swap(Axis::Horizontal, target, pane, true)
|
||||||
|
}
|
||||||
|
Edge::Bottom => {
|
||||||
|
self.split_and_swap(Axis::Horizontal, target, pane, false)
|
||||||
|
}
|
||||||
|
Edge::Left => {
|
||||||
|
self.split_and_swap(Axis::Vertical, target, pane, true)
|
||||||
|
}
|
||||||
|
Edge::Right => {
|
||||||
|
self.split_and_swap(Axis::Vertical, target, pane, false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drops the given [`Pane`] into the provided [`Target`].
|
||||||
|
pub fn drop(&mut self, pane: &Pane, target: Target) {
|
||||||
|
match target {
|
||||||
|
Target::Edge(edge) => self.move_to_edge(pane, edge),
|
||||||
|
Target::Pane(target, region) => {
|
||||||
|
self.split_with(&target, pane, region)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn split_node(
|
fn split_node(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
|
|
@ -186,29 +219,6 @@ impl<T> State<T> {
|
||||||
Some((new_pane, new_split))
|
Some((new_pane, new_split))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`].
|
|
||||||
///
|
|
||||||
/// Panes will be swapped by default for [`Region::Center`].
|
|
||||||
pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) {
|
|
||||||
match region {
|
|
||||||
Region::Center => self.swap(pane, target),
|
|
||||||
Region::Edge(edge) => match edge {
|
|
||||||
Edge::Top => {
|
|
||||||
self.split_and_swap(Axis::Horizontal, target, pane, true)
|
|
||||||
}
|
|
||||||
Edge::Bottom => {
|
|
||||||
self.split_and_swap(Axis::Horizontal, target, pane, false)
|
|
||||||
}
|
|
||||||
Edge::Left => {
|
|
||||||
self.split_and_swap(Axis::Vertical, target, pane, true)
|
|
||||||
}
|
|
||||||
Edge::Right => {
|
|
||||||
self.split_and_swap(Axis::Vertical, target, pane, false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn split_and_swap(
|
fn split_and_swap(
|
||||||
&mut self,
|
&mut self,
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue