Struct md_tui::nodes::root::ComponentRoot
source · pub struct ComponentRoot { /* private fields */ }Implementations§
source§impl ComponentRoot
impl ComponentRoot
pub fn new(file_name: Option<String>, components: Vec<Component>) -> Self
sourcepub fn children(&self) -> Vec<&Component>
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);
}
_ => {}
}
}
}
}pub fn children_mut(&mut self) -> Vec<&mut Component>
pub fn components(&self) -> Vec<&TextComponent>
pub fn components_mut(&mut self) -> Vec<&mut TextComponent>
pub fn file_name(&self) -> Option<&str>
pub fn words(&self) -> Vec<&Word>
pub fn find_and_mark(&mut self, search: &str)
pub fn search_results_heights(&self) -> Vec<usize>
pub fn clear(&mut self)
pub fn select(&mut self, index: usize) -> Result<u16, String>
pub fn deselect(&mut self)
pub fn link_index_and_height(&self) -> Vec<(usize, u16)>
sourcepub fn set_scroll(&mut self, scroll: u16)
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);
}
_ => {}
}
}
}
}pub fn heading_offset(&self, heading: &str) -> Result<u16, String>
sourcepub fn content(&self) -> Vec<String>
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
}pub fn selected(&self) -> &str
sourcepub fn transform(&mut self, width: u16)
pub fn transform(&mut self, width: u16)
Transforms the content of the components to fit the given width
sourcepub fn add_missing_components(self) -> Self
pub fn add_missing_components(self) -> Self
Because of the parsing, every table has a missing newline at the end
pub fn height(&self) -> u16
pub fn num_links(&self) -> usize
Auto Trait Implementations§
impl Freeze for ComponentRoot
impl !RefUnwindSafe for ComponentRoot
impl Send for ComponentRoot
impl Sync for ComponentRoot
impl Unpin for ComponentRoot
impl !UnwindSafe for ComponentRoot
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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