Struct md_tui::nodes::root::ComponentRoot

source ·
pub struct ComponentRoot { /* private fields */ }

Implementations§

source§

impl ComponentRoot

source

pub fn new(file_name: Option<String>, components: Vec<Component>) -> Self

source

pub fn children(&self) -> Vec<&Component>

Examples found in repository?
examples/demo.rs (line 94)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    fn draw(&mut self, frame: &mut Frame) {
        self.area = frame.area();

        self.markdown = Some(parser::parse_markdown(
            None,
            &CONTENT.to_string(),
            self.area.width,
        ));

        if let Some(markdown) = &mut self.markdown {
            markdown.set_scroll(self.scroll);

            let area = Rect {
                width: self.area.width - 1,
                height: self.area.height - 1,
                x: 1,
                ..self.area
            };

            for child in markdown.children() {
                match child {
                    Component::TextComponent(comp) => {
                        if comp.y_offset().saturating_sub(comp.scroll_offset()) >= area.height
                            || (comp.y_offset() + comp.height())
                                .saturating_sub(comp.scroll_offset())
                                == 0
                        {
                            continue;
                        }

                        frame.render_widget(comp.clone(), area);
                    }
                    _ => {}
                }
            }
        }
    }
source

pub fn children_mut(&mut self) -> Vec<&mut Component>

source

pub fn components(&self) -> Vec<&TextComponent>

source

pub fn components_mut(&mut self) -> Vec<&mut TextComponent>

source

pub fn file_name(&self) -> Option<&str>

source

pub fn words(&self) -> Vec<&Word>

source

pub fn find_and_mark(&mut self, search: &str)

source

pub fn search_results_heights(&self) -> Vec<usize>

source

pub fn clear(&mut self)

source

pub fn select(&mut self, index: usize) -> Result<u16, String>

source

pub fn deselect(&mut self)

source

pub fn set_scroll(&mut self, scroll: u16)

Sets the y offset of the components

Examples found in repository?
examples/demo.rs (line 85)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    fn draw(&mut self, frame: &mut Frame) {
        self.area = frame.area();

        self.markdown = Some(parser::parse_markdown(
            None,
            &CONTENT.to_string(),
            self.area.width,
        ));

        if let Some(markdown) = &mut self.markdown {
            markdown.set_scroll(self.scroll);

            let area = Rect {
                width: self.area.width - 1,
                height: self.area.height - 1,
                x: 1,
                ..self.area
            };

            for child in markdown.children() {
                match child {
                    Component::TextComponent(comp) => {
                        if comp.y_offset().saturating_sub(comp.scroll_offset()) >= area.height
                            || (comp.y_offset() + comp.height())
                                .saturating_sub(comp.scroll_offset())
                                == 0
                        {
                            continue;
                        }

                        frame.render_widget(comp.clone(), area);
                    }
                    _ => {}
                }
            }
        }
    }
source

pub fn heading_offset(&self, heading: &str) -> Result<u16, String>

source

pub fn content(&self) -> Vec<String>

Return the content of the components, where each element a line

Examples found in repository?
examples/demo.rs (line 57)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    fn scroll_down(&mut self) -> bool {
        if let Some(markdown) = &self.markdown {
            let len = markdown.content().len() as u16;
            if self.area.height > len {
                self.scroll = 0;
            } else {
                self.scroll = std::cmp::min(
                    self.scroll.saturating_add(1),
                    len.saturating_sub(self.area.height),
                )
            }
        }
        true
    }
source

pub fn selected(&self) -> &str

source

pub fn transform(&mut self, width: u16)

Transforms the content of the components to fit the given width

source

pub fn add_missing_components(self) -> Self

Because of the parsing, every table has a missing newline at the end

source

pub fn height(&self) -> u16

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.