Skip to main content

wiki_tui/renderer/
mod.rs

1pub mod default_renderer;
2#[cfg(debug_assertions)]
3pub mod test_renderer;
4
5use ratatui::style::Style;
6use textwrap::core::Fragment;
7use wiki_api::document::{Document, Node};
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
10pub struct Word {
11    pub index: usize,
12    pub content: String,
13    pub style: Style,
14    // TODO: Change width type to u64
15    pub width: f64,
16    // TODO: Change whitespace_width type to u8
17    pub whitespace_width: f64,
18    // TODO: Change penalty_width type to u8
19    pub penalty_width: f64,
20}
21
22impl<'a> Word {
23    pub fn node(&self, document: &'a Document) -> Option<Node<'a>> {
24        document.nth(self.index)
25    }
26}
27
28impl Fragment for Word {
29    #[inline]
30    fn width(&self) -> f64 {
31        self.width
32    }
33
34    #[inline]
35    fn whitespace_width(&self) -> f64 {
36        self.whitespace_width
37    }
38
39    #[inline]
40    fn penalty_width(&self) -> f64 {
41        self.penalty_width
42    }
43}
44
45#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
46pub struct RenderedDocument {
47    pub lines: Vec<Vec<Word>>,
48    /// Vec<(y-Coord, idx)>
49    pub links: Vec<(usize, usize)>,
50}