rtlibs-tui 0.1.5

rtools library: ratatui widgets
Documentation
use ratatui::layout::Position;

use super::Modal;
use super::ModalService;

#[derive(Debug)]
pub struct ModalContainerState<RESPONSE, EVENT>
{
    pub(crate) modal: Option<Box<dyn Modal<RESPONSE, EVENT>>>,
    pub(crate) modal_event: Option<EVENT>,
}

impl<RESPONSE, EVENT> std::default::Default for ModalContainerState<RESPONSE, EVENT>
{
    fn default() -> Self
    {
        Self::new()
    }
}

impl<RESPONSE, EVENT> ModalContainerState<RESPONSE, EVENT>
{
    pub fn new() -> Self
    {
        Self {
            modal: None,
            modal_event: None,
        }
    }

    pub fn update_from(
        &mut self,
        service: &mut dyn ModalService<RESPONSE, EVENT>,
    )
    {
        if let Some(modal) = service.modal()
        {
            self.modal = Some(modal);
        }
        if let Some(modal_event) = service.modal_event()
        {
            self.modal_event = Some(modal_event);
        }
    }

    pub fn cursor(&self) -> Option<Position>
    {
        if let Some(modal) = self
            .modal
            .as_ref()
        {
            modal.cursor()
        }
        else
        {
            None
        }
    }
}