refactor(tab): separate concerns (namely move pane positioning actions out of tab) (#985)
* refactor: move resizing methods to pane resizer * refactor: move focus and close methods to pane grid * refactor(tab): move move methods positioning to pane grid * refactor(tab): separate pane resizer from pane grid * style(fmt): make rustfmt happy * style(fmt): make clippy happy
This commit is contained in:
parent
d509fea457
commit
7dad61e529
5 changed files with 1913 additions and 1702 deletions
File diff suppressed because it is too large
Load diff
1745
zellij-server/src/tab/pane_grid.rs
Normal file
1745
zellij-server/src/tab/pane_grid.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,14 +4,16 @@ use cassowary::{
|
||||||
Expression, Solver, Variable,
|
Expression, Solver, Variable,
|
||||||
WeightedRelation::EQ,
|
WeightedRelation::EQ,
|
||||||
};
|
};
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::rc::Rc;
|
||||||
use zellij_utils::{
|
use zellij_utils::{
|
||||||
input::layout::Direction,
|
input::layout::Direction,
|
||||||
pane_size::{Constraint, Dimension, PaneGeom},
|
pane_size::{Constraint, Dimension, PaneGeom},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PaneResizer<'a> {
|
pub struct PaneResizer<'a> {
|
||||||
panes: HashMap<&'a PaneId, &'a mut Box<dyn Pane>>,
|
panes: Rc<RefCell<HashMap<PaneId, &'a mut Box<dyn Pane>>>>,
|
||||||
vars: HashMap<PaneId, Variable>,
|
vars: HashMap<PaneId, Variable>,
|
||||||
solver: Solver,
|
solver: Solver,
|
||||||
}
|
}
|
||||||
|
|
@ -30,10 +32,9 @@ struct Span {
|
||||||
type Grid = Vec<Vec<Span>>;
|
type Grid = Vec<Vec<Span>>;
|
||||||
|
|
||||||
impl<'a> PaneResizer<'a> {
|
impl<'a> PaneResizer<'a> {
|
||||||
pub fn new(panes: impl IntoIterator<Item = (&'a PaneId, &'a mut Box<dyn Pane>)>) -> Self {
|
pub fn new(panes: Rc<RefCell<HashMap<PaneId, &'a mut Box<dyn Pane>>>>) -> Self {
|
||||||
let panes: HashMap<_, _> = panes.into_iter().collect();
|
|
||||||
let mut vars = HashMap::new();
|
let mut vars = HashMap::new();
|
||||||
for &&k in panes.keys() {
|
for &k in panes.borrow().keys() {
|
||||||
vars.insert(k, Variable::new());
|
vars.insert(k, Variable::new());
|
||||||
}
|
}
|
||||||
PaneResizer {
|
PaneResizer {
|
||||||
|
|
@ -122,8 +123,9 @@ impl<'a> PaneResizer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_spans(&mut self, spans: Vec<Span>) {
|
fn apply_spans(&mut self, spans: Vec<Span>) {
|
||||||
|
let mut panes = self.panes.borrow_mut();
|
||||||
for span in spans {
|
for span in spans {
|
||||||
let pane = self.panes.get_mut(&span.pid).unwrap();
|
let pane = panes.get_mut(&span.pid).unwrap();
|
||||||
let new_geom = match span.direction {
|
let new_geom = match span.direction {
|
||||||
Direction::Horizontal => PaneGeom {
|
Direction::Horizontal => PaneGeom {
|
||||||
x: span.pos,
|
x: span.pos,
|
||||||
|
|
@ -149,6 +151,7 @@ impl<'a> PaneResizer<'a> {
|
||||||
// Select the spans running *perpendicular* to the direction of resize
|
// Select the spans running *perpendicular* to the direction of resize
|
||||||
let spans: Vec<Span> = self
|
let spans: Vec<Span> = self
|
||||||
.panes
|
.panes
|
||||||
|
.borrow()
|
||||||
.values()
|
.values()
|
||||||
.map(|p| self.get_span(!direction, p.as_ref()))
|
.map(|p| self.get_span(!direction, p.as_ref()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
@ -170,6 +173,7 @@ impl<'a> PaneResizer<'a> {
|
||||||
let bwn = |v, (s, e)| s <= v && v < e;
|
let bwn = |v, (s, e)| s <= v && v < e;
|
||||||
let mut spans: Vec<_> = self
|
let mut spans: Vec<_> = self
|
||||||
.panes
|
.panes
|
||||||
|
.borrow()
|
||||||
.values()
|
.values()
|
||||||
.filter(|p| {
|
.filter(|p| {
|
||||||
let s = self.get_span(!direction, p.as_ref());
|
let s = self.get_span(!direction, p.as_ref());
|
||||||
|
|
@ -186,7 +190,8 @@ impl<'a> PaneResizer<'a> {
|
||||||
|
|
||||||
fn get_span(&self, direction: Direction, pane: &dyn Pane) -> Span {
|
fn get_span(&self, direction: Direction, pane: &dyn Pane) -> Span {
|
||||||
let pas = pane.current_geom();
|
let pas = pane.current_geom();
|
||||||
let size_var = self.vars[&pane.pid()];
|
// let size_var = self.vars[&pane.pid()];
|
||||||
|
let size_var = *self.vars.get(&pane.pid()).unwrap();
|
||||||
match direction {
|
match direction {
|
||||||
Direction::Horizontal => Span {
|
Direction::Horizontal => Span {
|
||||||
pid: pane.pid(),
|
pid: pane.pid(),
|
||||||
|
|
@ -2,4 +2,3 @@ pub mod boundaries;
|
||||||
pub mod overlay;
|
pub mod overlay;
|
||||||
pub mod pane_boundaries_frame;
|
pub mod pane_boundaries_frame;
|
||||||
pub mod pane_contents_and_ui;
|
pub mod pane_contents_and_ui;
|
||||||
pub mod pane_resizer;
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue