use std::time::Duration;
use gpui::{ElementId, Entity, IntoElement, Pixels, Size};
mod geometry;
mod render;
mod state;
mod types;
pub use geometry::{PaneExpansionAnchor, PaneLayoutDirective, PaneOverlayAlignment};
pub use state::{
AdaptivePaneState, PaneAdaptStrategy, PaneBackBehavior, PaneDestination, PaneLayoutValue,
PanePlacement, PaneRole,
};
pub use types::{AdaptivePane, PaneSeparator};
use types::pair_index;
#[derive(IntoElement)]
pub struct AdaptivePaneLayout {
pub(super) id: ElementId,
pub(super) viewport: Size<Pixels>,
pub(super) state: Entity<AdaptivePaneState>,
pub(super) directive: Option<PaneLayoutDirective>,
pub(super) panes: [Option<AdaptivePane>; 3],
pub(super) order: [PaneRole; 3],
pub(super) separators: [Option<PaneSeparator>; 9],
pub(super) duration: Duration,
}
impl AdaptivePaneLayout {
pub fn new(
id: impl Into<ElementId>,
viewport: Size<Pixels>,
state: &Entity<AdaptivePaneState>,
) -> Self {
Self {
id: id.into(),
viewport,
state: state.clone(),
directive: None,
panes: Default::default(),
order: PaneRole::ALL,
separators: Default::default(),
duration: Duration::from_millis(240),
}
}
pub fn pane(mut self, role: PaneRole, pane: AdaptivePane) -> Self {
self.panes[role.index()] = Some(pane);
self
}
pub fn directive(mut self, directive: PaneLayoutDirective) -> Self {
self.directive = Some(directive);
self
}
pub fn order(mut self, order: [PaneRole; 3]) -> Self {
if PaneRole::ALL.into_iter().all(|role| order.contains(&role)) {
self.order = order;
}
self
}
pub fn separator(mut self, start: PaneRole, end: PaneRole, separator: PaneSeparator) -> Self {
self.separators[pair_index(start, end)] = Some(separator);
self
}
pub fn transition_duration(mut self, duration: Duration) -> Self {
self.duration = duration;
self
}
}