use ratatui::layout::Rect;
use std::collections::{HashMap, HashSet};
use crate::themes::Theme;
pub struct LayoutContext<'a> {
pub frame_area: Rect,
pub show_throbber: bool,
pub input_visual_lines: usize,
pub theme: &'a Theme,
pub active_widgets: HashSet<&'static str>,
}
pub struct WidgetSizes {
pub heights: HashMap<&'static str, u16>,
pub is_active: HashMap<&'static str, bool>,
}
impl WidgetSizes {
pub fn height(&self, id: &str) -> u16 {
self.heights.get(id).copied().unwrap_or(0)
}
pub fn is_active(&self, id: &str) -> bool {
self.is_active.get(id).copied().unwrap_or(false)
}
}
#[derive(Default)]
pub struct LayoutResult {
pub widget_areas: HashMap<&'static str, Rect>,
pub render_order: Vec<&'static str>,
pub input_area: Option<Rect>,
}
pub trait LayoutProvider: Send + Sync + 'static {
fn compute(&self, ctx: &LayoutContext, sizes: &WidgetSizes) -> LayoutResult;
}
pub type LayoutFn = Box<dyn Fn(Rect, &LayoutContext, &WidgetSizes) -> LayoutResult + Send + Sync>;