summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes/floating_panes/floating_pane_grid.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-17 12:05:50 +0100
committerGitHub <noreply@github.com>2023-02-17 12:05:50 +0100
commitf1ff272b0b65f6d328fef24531ada67ea585ce85 (patch)
tree0e33aa4a1af21c0785fa30118ee42a21972497cf /zellij-server/src/panes/floating_panes/floating_pane_grid.rs
parent1517036c2489b2a7dc43230e2ba8a05841a69dbe (diff)
feat(ui): swap layouts and stacked panes (#2167)
* relayout working with hard coded layout * work * refactor(layout): PaneLayout => TiledPaneLayout * tests passing * tests passing * tests passing * stacked panes and passing tests * tests for stacked panes * refactor(panes): stacked panes * fix: focusing into stacked panes from the left/right * fix(layouts): handle stacked layouts in the middle of the screen * fix(pane-stack): focus correctly when coming to stack from above/below * fix(stacked-panes): resize stack * fix(stacked-panes): focus with mouse * fix(stacked-panes): focus next pane * fix(layout-applier): sane focus order * fix(stacked-panes): better titles for one-liners * fix(stacked-panes): handle moving pane location in stack * fix(relayout): properly calculate display area * fix(relayout): properly calculate rounding errors * fix(stacked-panes): properly handle closing a pane near a stack * fix(swap-layouts): adjust swap layout sort order * feat(swap-layouts): ui + ux * fix(swap-layouts): include base layout * refactor(layout): remove unused method * fix(swap-layouts): respect pane contents and focus * work * fix(swap-layouts): load swap layouts from external file * fix(swap-layouts): properly truncate layout children * fix(stacked-panes): allow stacked panes to become fullscreen * fix(swap-layouts): work with multiple tabs * fix(swap-layouts): embed/eject panes properly with auto-layout * fix(stacked-panes): close last pane in stack * fix(stacked-panes): move focus for all clients in stack * fix(floating-panes): set layout damaged when moving panes * fix(relayout): move out of unfitting layout when resizing whole tab * fix(ui): background color for swap layout indicator * fix(keybinds): add switch next layout in tmux * fix(ui): swap layout indication in compact layout * fix(compact): correct swap constraint * fix(tests): tmux swap config shortcut * fix(resizes): cache resizes so as not to confuse panes (eg. vim) with multiple resizes that it debounces weirdly * feat(cli): dump swap layouts * fix(ui): stacked panes without pane frames * fix(ux): move pane forward/backwards also with floating panes * refactor(lint): remove unused stuff * refactor(tab): move swap layouts to separate file * style(fmt): rustfmt * style(fmt): rustfmt * refactor(panes): various cleanups * chore(deps): upgrade termwiz to get alt left-bracket * fix(assets): merge conflicts of binary files * style(fmt): rustfmt * style(clippy): no thank you! * chore(repo): remove garbage file
Diffstat (limited to 'zellij-server/src/panes/floating_panes/floating_pane_grid.rs')
-rw-r--r--zellij-server/src/panes/floating_panes/floating_pane_grid.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs
index 2245ee16a..afeecc8d2 100644
--- a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs
+++ b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs
@@ -703,6 +703,56 @@ impl<'a> FloatingPaneGrid<'a> {
.copied();
next_index
}
+ pub fn next_selectable_pane_id(&self, current_pane_id: &PaneId) -> Option<PaneId> {
+ let panes = self.panes.borrow();
+ let mut panes: Vec<(PaneId, &&mut Box<dyn Pane>)> = panes
+ .iter()
+ .filter(|(_, p)| p.selectable())
+ .map(|(p_id, p)| (*p_id, p))
+ .collect();
+ panes.sort_by(|(_a_id, a_pane), (_b_id, b_pane)| {
+ if a_pane.y() == b_pane.y() {
+ a_pane.x().cmp(&b_pane.x())
+ } else {
+ a_pane.y().cmp(&b_pane.y())
+ }
+ });
+ let active_pane_position = panes
+ .iter()
+ .position(|(id, _)| id == current_pane_id)
+ .unwrap();
+
+ let next_active_pane_id = panes
+ .get(active_pane_position + 1)
+ .or_else(|| panes.get(0))
+ .map(|p| p.0)
+ .unwrap();
+ Some(next_active_pane_id)
+ }
+ pub fn previous_selectable_pane_id(&self, current_pane_id: &PaneId) -> Option<PaneId> {
+ let panes = self.panes.borrow();
+ let mut panes: Vec<(PaneId, &&mut Box<dyn Pane>)> = panes
+ .iter()
+ .filter(|(_, p)| p.selectable())
+ .map(|(p_id, p)| (*p_id, p))
+ .collect();
+ panes.sort_by(|(_a_id, a_pane), (_b_id, b_pane)| {
+ if a_pane.y() == b_pane.y() {
+ a_pane.x().cmp(&b_pane.x())
+ } else {
+ a_pane.y().cmp(&b_pane.y())
+ }
+ });
+ let active_pane_position = panes.iter().position(|(id, _)| id == current_pane_id)?;
+
+ let last_pane = panes.last()?;
+ let previous_active_pane_id = if active_pane_position == 0 {
+ last_pane.0
+ } else {
+ panes.get(active_pane_position - 1)?.0
+ };
+ Some(previous_active_pane_id)
+ }
pub fn find_room_for_new_pane(&self) -> Option<PaneGeom> {
let panes = self.panes.borrow();
let pane_geoms: Vec<PaneGeom> = panes.values().map(|p| p.position_and_size()).collect();
@@ -766,6 +816,7 @@ fn half_size_middle_geom(space: &Viewport, offset: usize) -> PaneGeom {
y: space.y + (space.rows as f64 / 4.0).round() as usize + offset,
cols: Dimension::fixed(space.cols / 2),
rows: Dimension::fixed(space.rows / 2),
+ is_stacked: false,
};
geom.cols.set_inner(space.cols / 2);
geom.rows.set_inner(space.rows / 2);
@@ -778,6 +829,7 @@ fn half_size_top_left_geom(space: &Viewport, offset: usize) -> PaneGeom {
y: space.y + 2 + offset,
cols: Dimension::fixed(space.cols / 3),
rows: Dimension::fixed(space.rows / 3),
+ is_stacked: false,
};
geom.cols.set_inner(space.cols / 3);
geom.rows.set_inner(space.rows / 3);
@@ -790,6 +842,7 @@ fn half_size_top_right_geom(space: &Viewport, offset: usize) -> PaneGeom {
y: space.y + 2 + offset,
cols: Dimension::fixed(space.cols / 3),
rows: Dimension::fixed(space.rows / 3),
+ is_stacked: false,
};
geom.cols.set_inner(space.cols / 3);
geom.rows.set_inner(space.rows / 3);
@@ -802,6 +855,7 @@ fn half_size_bottom_left_geom(space: &Viewport, offset: usize) -> PaneGeom {
y: ((space.y + space.rows) - (space.rows / 3) - 2).saturating_sub(offset),
cols: Dimension::fixed(space.cols / 3),
rows: Dimension::fixed(space.rows / 3),
+ is_stacked: false,
};
geom.cols.set_inner(space.cols / 3);
geom.rows.set_inner(space.rows / 3);
@@ -814,6 +868,7 @@ fn half_size_bottom_right_geom(space: &Viewport, offset: usize) -> PaneGeom {
y: ((space.y + space.rows) - (space.rows / 3) - 2).saturating_sub(offset),
cols: Dimension::fixed(space.cols / 3),
rows: Dimension::fixed(space.rows / 3),
+ is_stacked: false,
};
geom.cols.set_inner(space.cols / 3);
geom.rows.set_inner(space.rows / 3);