use crate::tab::{MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH};
use crate::{panes::PaneId, tab::Pane};
use std::cmp::Ordering;
use std::collections::HashMap;
use zellij_utils::data::{Direction, ResizeStrategy};
use zellij_utils::errors::prelude::*;
use zellij_utils::pane_size::{Dimension, PaneGeom, Size, Viewport};
use std::cell::RefCell;
use std::rc::Rc;
const MOVE_INCREMENT_HORIZONTAL: usize = 10;
const MOVE_INCREMENT_VERTICAL: usize = 5;
const MAX_PANES: usize = 100;
// For error reporting
fn no_pane_id(pane_id: &PaneId) -> String {
format!("no floating pane with ID {:?} found", pane_id)
}
pub struct FloatingPaneGrid<'a> {
panes: Rc<RefCell<HashMap<PaneId, &'a mut Box<dyn Pane>>>>,
desired_pane_positions: Rc<RefCell<&'a mut HashMap<PaneId, PaneGeom>>>,
display_area: Size, // includes all panes (including eg. the status bar and tab bar in the default layout)
viewport: Viewport, // includes all non-UI panes
}
impl<'a> FloatingPaneGrid<'a> {
pub fn new(
panes: impl IntoIterator<Item = (&'a PaneId, &'a mut Box<dyn Pane>)>,
desired_pane_positions: &'a mut HashMap<PaneId, PaneGeom>,
display_area: Size,
viewport: Viewport,
) -> Self {
let panes: HashMap<_, _> = panes.into_iter().map(|(p_id, p)| (*p_id, p)).collect();
FloatingPaneGrid {
panes: Rc::new(RefCell::new(panes)),
desired_pane_positions: Rc::new(RefCell::new(desired_pane_positions)),
display_area,
viewport,
}
}
pub fn move_pane_by(&mut self, pane_id: PaneId, x: isize, y: isize) -> Result<()> {
let err_context = || format!("failed to move pane {pane_id:?} by ({x}, {y})");
// true => succeeded to move, false => failed to move
let