rtlibs-tui 0.1.4

rtools library: ratatui widgets
Documentation
use tui_scrollview::ScrollViewState;

use super::ScrollService;

#[derive(Debug)]
pub struct ScrollState
{
    pub(crate) scrollview: ScrollViewState,
    pub(crate) text: Option<String>,
}

impl std::default::Default for ScrollState
{
    fn default() -> Self
    {
        Self::new()
    }
}

impl ScrollState
{
    pub fn new() -> Self
    {
        Self {
            scrollview: ScrollViewState::new(),
            text: None,
        }
    }

    pub fn update_from(
        &mut self,
        service: &mut ScrollService,
    )
    {
        self.text = service
            .text
            .clone();
    }

    pub fn with_text<S>(
        mut self,
        text: S,
    ) -> Self
    where
        S: AsRef<str>,
    {
        self.text = Some(
            text.as_ref()
                .to_string(),
        );
        self
    }

    // fn build_from_text(&self) -> Vec<Line>
    // {
    //     self.text
    //         .as_ref()
    //         .map(|a| a.lines())
    //         .map(
    //             |lines| {
    //                 lines
    //                     .map(Line::raw)
    //                     .collect::<Vec<_>>()
    //             },
    //         )
    //         .unwrap_or_default()
    // }

    // fn build(&self) -> Vec<Line>
    // {
    //     self.build_from_text()
    // }
}