diff options
author | 2020-03-14 04:06:32 +0100 | |
---|---|---|
committer | 2020-03-14 04:06:32 +0100 | |
commit | 6e8585e88c89c9e3e18e49765d4d954000bd4674 (patch) | |
tree | d72ce482c009fc29342d5aa2508e3478f42db4f7 /native/src | |
parent | 858c086eeee4284a5a7b3e49cb3c112d204e53c3 (diff) | |
download | iced-6e8585e88c89c9e3e18e49765d4d954000bd4674.tar.gz iced-6e8585e88c89c9e3e18e49765d4d954000bd4674.tar.bz2 iced-6e8585e88c89c9e3e18e49765d4d954000bd4674.zip |
Expose `adjacent_pane` instead of `focus_adjacent`
Diffstat (limited to 'native/src')
-rw-r--r-- | native/src/widget/pane_grid.rs | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 1ba1b417..ddbc7bfd 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -321,8 +321,8 @@ enum FocusedPane { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Direction { - Top, - Bottom, + Up, + Down, Left, Right, } @@ -378,42 +378,46 @@ impl<T> State<T> { } } - pub fn focus(&mut self, pane: &Pane) { - self.internal.focused_pane = FocusedPane::Some { - pane: *pane, - focus: Focus::Idle, - }; - } - - pub fn focus_adjacent(&mut self, pane: &Pane, direction: Direction) { + pub fn adjacent_pane( + &self, + pane: &Pane, + direction: Direction, + ) -> Option<Pane> { let regions = self.internal.layout.regions(0.0, Size::new(4096.0, 4096.0)); - if let Some(current_region) = regions.get(pane) { - let target = match direction { - Direction::Left => { - Point::new(current_region.x - 1.0, current_region.y + 1.0) - } - Direction::Right => Point::new( - current_region.x + current_region.width + 1.0, - current_region.y + 1.0, - ), - Direction::Top => { - Point::new(current_region.x + 1.0, current_region.y - 1.0) - } - Direction::Bottom => Point::new( - current_region.x + 1.0, - current_region.y + current_region.height + 1.0, - ), - }; - - let mut colliding_regions = - regions.iter().filter(|(_, region)| region.contains(target)); + let current_region = regions.get(pane)?; - if let Some((pane, _)) = colliding_regions.next() { - self.focus(&pane); + let target = match direction { + Direction::Left => { + Point::new(current_region.x - 1.0, current_region.y + 1.0) } - } + Direction::Right => Point::new( + current_region.x + current_region.width + 1.0, + current_region.y + 1.0, + ), + Direction::Up => { + Point::new(current_region.x + 1.0, current_region.y - 1.0) + } + Direction::Down => Point::new( + current_region.x + 1.0, + current_region.y + current_region.height + 1.0, + ), + }; + + let mut colliding_regions = + regions.iter().filter(|(_, region)| region.contains(target)); + + let (pane, _) = colliding_regions.next()?; + + Some(*pane) + } + + pub fn focus(&mut self, pane: &Pane) { + self.internal.focused_pane = FocusedPane::Some { + pane: *pane, + focus: Focus::Idle, + }; } pub fn split_vertically(&mut self, pane: &Pane, state: T) -> Option<Pane> { |