use crate::direct::DirectTerminalCanvas;
use crate::ptop::app::App;
use crate::ptop::config::PanelType;
use crate::widgets::DisplayAction;
use crate::Rect;
pub type PanelDrawFn = fn(&App, &mut DirectTerminalCanvas<'_>, Rect);
#[inline]
pub fn evaluate_panel_draw(
app: &App,
panel_enabled: bool,
panel_type: PanelType,
normal_draw_fn: PanelDrawFn,
compact_draw_fn: Option<PanelDrawFn>,
) -> Option<PanelDrawFn> {
if !panel_enabled {
return None;
}
match app.evaluate_panel_display(panel_type) {
DisplayAction::Show | DisplayAction::Expand => Some(normal_draw_fn),
DisplayAction::Hide => None,
DisplayAction::Compact => Some(compact_draw_fn.unwrap_or(normal_draw_fn)),
DisplayAction::ShowPlaceholder(_) => Some(normal_draw_fn),
}
}
#[inline]
pub fn push_if_visible(
panels: &mut Vec<PanelDrawFn>,
app: &App,
panel_enabled: bool,
panel_type: PanelType,
normal_draw_fn: PanelDrawFn,
compact_draw_fn: Option<PanelDrawFn>,
) {
if let Some(draw_fn) = evaluate_panel_draw(
app,
panel_enabled,
panel_type,
normal_draw_fn,
compact_draw_fn,
) {
panels.push(draw_fn);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_evaluate_panel_draw_disabled() {
}
#[test]
fn test_push_if_visible_signature() {
let _ = push_if_visible
as fn(&mut Vec<PanelDrawFn>, &App, bool, PanelType, PanelDrawFn, Option<PanelDrawFn>);
}
}