use std::marker::PhantomData;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::widgets::StatefulWidget;
use crate::widgets::CommanderWidget;
use crate::widgets::CommanderWidgetStyle;
use super::AppCommanderCommand;
use super::AppCommanderState;
pub struct AppCommanderWidget<T>
where
T: AppCommanderCommand,
{
style: CommanderWidgetStyle,
phantom: PhantomData<T>,
}
impl<T> std::default::Default for AppCommanderWidget<T>
where
T: AppCommanderCommand,
{
fn default() -> Self
{
Self::new()
}
}
impl<T> AppCommanderWidget<T>
where
T: AppCommanderCommand,
{
pub fn new() -> Self
{
Self {
style: CommanderWidgetStyle::default(),
phantom: PhantomData,
}
}
pub fn style(
mut self,
style: CommanderWidgetStyle,
) -> Self
{
self.style = style;
self
}
}
impl<T> StatefulWidget for AppCommanderWidget<T>
where
T: AppCommanderCommand,
{
type State = AppCommanderState<T>;
fn render(
self,
area: Rect,
buf: &mut Buffer,
state: &mut Self::State,
)
{
CommanderWidget::new()
.style(self.style)
.render(
area,
buf,
&mut state.commander,
);
}
}