summaryrefslogtreecommitdiffstats
path: root/widget/src/pane_grid
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-07-06 07:45:47 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-07-06 07:57:24 +0200
commitc5a623f32b3d972501bb02d87d296381b66f9481 (patch)
tree16a8dd77cebcfb37bdaa6f45a9e49304e201d4fb /widget/src/pane_grid
parentecce8bbcee45dddedef8a33bf3dc086d76c27b39 (diff)
downloadiced-c5a623f32b3d972501bb02d87d296381b66f9481.tar.gz
iced-c5a623f32b3d972501bb02d87d296381b66f9481.tar.bz2
iced-c5a623f32b3d972501bb02d87d296381b66f9481.zip
Introduce `drop` helper to `pane_grid::State`
Diffstat (limited to 'widget/src/pane_grid')
-rw-r--r--widget/src/pane_grid/state.rs58
1 files changed, 34 insertions, 24 deletions
diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs
index 332b6837..6fd15890 100644
--- a/widget/src/pane_grid/state.rs
+++ b/widget/src/pane_grid/state.rs
@@ -3,7 +3,7 @@
//! [`PaneGrid`]: crate::widget::PaneGrid
use crate::core::{Point, Size};
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;
@@ -148,6 +148,39 @@ impl<T> State<T> {
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(
&mut self,
axis: Axis,
@@ -186,29 +219,6 @@ impl<T> State<T> {
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(
&mut self,
axis: Axis,