use std::sync::Arc;
use crate::panel::{Axis, Constraints};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ActivePanelVariant {
Monocle,
Tabbed,
Stacked,
}
#[derive(Debug, Clone)]
pub struct SlotDef {
pub kind: Arc<str>,
pub constraints: Constraints,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CardSpan {
Columns(usize),
FullWidth,
}
impl From<usize> for CardSpan {
fn from(n: usize) -> Self {
Self::Columns(n)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum GridColumnMode {
Fixed(usize),
AutoFill {
min_width: f32,
},
AutoFit {
min_width: f32,
},
}
impl GridColumnMode {
pub(crate) fn to_dashboard_strategy(
self,
gap: f32,
spans: Arc<[CardSpan]>,
auto_rows: bool,
) -> StrategyKind {
StrategyKind::Dashboard {
columns: self,
gap,
spans,
auto_rows,
}
}
}
#[derive(Debug, Clone)]
pub enum StrategyKind {
Sequence {
axis: Axis,
gap: f32,
ratio: Option<f32>,
},
MasterStack {
master_ratio: f32,
gap: f32,
},
Deck {
master_ratio: f32,
gap: f32,
},
CenteredMaster {
master_ratio: f32,
gap: f32,
},
BinarySplit {
spiral: bool,
ratio: f32,
gap: f32,
},
Dashboard {
columns: GridColumnMode,
gap: f32,
spans: Arc<[CardSpan]>,
auto_rows: bool,
},
ActivePanel {
variant: ActivePanelVariant,
bar_height: f32,
},
Window {
panel_count: usize,
gap: f32,
},
Slotted {
slots: Arc<[SlotDef]>,
gap: f32,
axis: Axis,
},
}
impl StrategyKind {
pub fn gap(&self) -> f32 {
match self {
Self::Sequence { gap, .. }
| Self::MasterStack { gap, .. }
| Self::Deck { gap, .. }
| Self::CenteredMaster { gap, .. }
| Self::BinarySplit { gap, .. }
| Self::Dashboard { gap, .. }
| Self::Window { gap, .. }
| Self::Slotted { gap, .. } => *gap,
Self::ActivePanel { .. } => 0.0,
}
}
pub fn supports_move(&self) -> bool {
!matches!(self, Self::Slotted { .. })
}
pub fn supports_spatial_nav(&self) -> bool {
!matches!(self, Self::ActivePanel { .. } | Self::Window { .. })
}
}