use std::sync::Arc;
use super::builder::BoundStrategy;
use crate::panel::Axis;
use super::{SlotDef, StrategyKind};
#[derive(Debug, Clone)]
pub struct SidebarStrategy {
gap: f32,
sidebar_width: f32,
}
impl SidebarStrategy {
pub(crate) fn new(gap: f32, sidebar_width: f32) -> Self {
Self { gap, sidebar_width }
}
crate::macros::builder_setters!(
sidebar_width(width: f32);
gap(gap: f32)
);
pub fn with_panels(
self,
sidebar: impl Into<Arc<str>>,
content: impl Into<Arc<str>>,
) -> BoundStrategy {
let sidebar: Arc<str> = sidebar.into();
let content: Arc<str> = content.into();
let slots: Arc<[SlotDef]> = vec![
SlotDef {
kind: Arc::clone(&sidebar),
constraints: crate::panel::fixed(self.sidebar_width),
},
SlotDef {
kind: Arc::clone(&content),
constraints: crate::panel::grow(1.0),
},
]
.into();
let kind = StrategyKind::Slotted {
slots,
gap: self.gap,
axis: Axis::Row,
};
BoundStrategy::new(kind, Box::from([sidebar, content]), None)
}
}