summaryrefslogtreecommitdiffstats
path: root/native/src/widget/pane_grid/state.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-14 06:26:09 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-14 06:26:09 +0100
commit00c2b55b569ea2ff2fc9de9bbf02475c6ede7e42 (patch)
treeb1c7c222e561d11272879c94731c36aa145391bd /native/src/widget/pane_grid/state.rs
parent5c8ec4504b6541cdc588b91a6b2c7100b4a7cc77 (diff)
downloadiced-00c2b55b569ea2ff2fc9de9bbf02475c6ede7e42.tar.gz
iced-00c2b55b569ea2ff2fc9de9bbf02475c6ede7e42.tar.bz2
iced-00c2b55b569ea2ff2fc9de9bbf02475c6ede7e42.zip
Replace `FocusedPane` with `Action` in `pane_grid`
Diffstat (limited to 'native/src/widget/pane_grid/state.rs')
-rw-r--r--native/src/widget/pane_grid/state.rs80
1 files changed, 38 insertions, 42 deletions
diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs
index 130c7e34..61576a29 100644
--- a/native/src/widget/pane_grid/state.rs
+++ b/native/src/widget/pane_grid/state.rs
@@ -31,8 +31,8 @@ impl<T> State<T> {
panes,
internal: Internal {
layout: Node::Pane(first_pane),
- last_pane: 0,
- focused_pane: FocusedPane::None,
+ last_id: 0,
+ action: Action::Idle { focus: None },
},
modifiers: keyboard::ModifiersState::default(),
},
@@ -56,25 +56,14 @@ impl<T> State<T> {
self.panes.iter_mut()
}
- pub fn focused_pane(&self) -> Option<Pane> {
- match self.internal.focused_pane {
- FocusedPane::Some {
- pane,
- focus: Focus::Idle,
- } => Some(pane),
- FocusedPane::Some {
- focus: Focus::Dragging,
- ..
- } => None,
- FocusedPane::None => None,
+ pub fn active(&self) -> Option<Pane> {
+ match self.internal.action {
+ Action::Idle { focus } => focus,
+ _ => None,
}
}
- pub fn adjacent_pane(
- &self,
- pane: &Pane,
- direction: Direction,
- ) -> Option<Pane> {
+ pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane> {
let regions =
self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0));
@@ -130,12 +119,18 @@ impl<T> State<T> {
let node = self.internal.layout.find(pane)?;
let new_pane = {
- self.internal.last_pane = self.internal.last_pane.checked_add(1)?;
+ self.internal.last_id = self.internal.last_id.checked_add(1)?;
+
+ Pane(self.internal.last_id)
+ };
+
+ let split_id = {
+ self.internal.last_id = self.internal.last_id.checked_add(1)?;
- Pane(self.internal.last_pane)
+ self.internal.last_id
};
- node.split(kind, new_pane);
+ node.split(split_id, kind, new_pane);
let _ = self.panes.insert(new_pane, state);
self.focus(&new_pane);
@@ -169,26 +164,33 @@ impl<T> State<T> {
#[derive(Debug)]
pub struct Internal {
layout: Node,
- last_pane: usize,
- focused_pane: FocusedPane,
+ last_id: usize,
+ action: Action,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub enum FocusedPane {
- None,
- Some { pane: Pane, focus: Focus },
+pub enum Action {
+ Idle { focus: Option<Pane> },
+ Dragging { pane: Pane },
+}
+
+impl Action {
+ pub fn focus(&self) -> Option<(Pane, Focus)> {
+ match self {
+ Action::Idle { focus } => focus.map(|pane| (pane, Focus::Idle)),
+ Action::Dragging { pane } => Some((*pane, Focus::Dragging)),
+ }
+ }
}
impl Internal {
- pub fn focused(&self) -> FocusedPane {
- self.focused_pane
+ pub fn action(&self) -> Action {
+ self.action
}
+
pub fn dragged(&self) -> Option<Pane> {
- match self.focused_pane {
- FocusedPane::Some {
- pane,
- focus: Focus::Dragging,
- } => Some(pane),
+ match self.action {
+ Action::Dragging { pane } => Some(pane),
_ => None,
}
}
@@ -202,21 +204,15 @@ impl Internal {
}
pub fn focus(&mut self, pane: &Pane) {
- self.focused_pane = FocusedPane::Some {
- pane: *pane,
- focus: Focus::Idle,
- };
+ self.action = Action::Idle { focus: Some(*pane) };
}
pub fn drag(&mut self, pane: &Pane) {
- self.focused_pane = FocusedPane::Some {
- pane: *pane,
- focus: Focus::Dragging,
- };
+ self.action = Action::Dragging { pane: *pane };
}
pub fn unfocus(&mut self) {
- self.focused_pane = FocusedPane::None;
+ self.action = Action::Idle { focus: None };
}
pub fn hash_layout(&self, hasher: &mut Hasher) {