Struct md_tui::nodes::textcomponent::TextComponent
source · pub struct TextComponent { /* private fields */ }Implementations§
source§impl TextComponent
impl TextComponent
pub fn new(kind: TextNode, content: Vec<Word>) -> Self
pub fn new_formatted(kind: TextNode, content: Vec<Vec<Word>>) -> Self
pub fn kind(&self) -> TextNode
pub fn content(&self) -> &Vec<Vec<Word>>
pub fn content_as_lines(&self) -> Vec<String>
pub fn content_as_bytes(&self) -> Vec<u8>
pub fn content_owned(self) -> Vec<Vec<Word>>
pub fn meta_info(&self) -> &Vec<Word>
sourcepub fn height(&self) -> u16
pub fn height(&self) -> u16
Examples found in repository?
examples/demo.rs (line 98)
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);
}
_ => {}
}
}
}
}sourcepub fn y_offset(&self) -> u16
pub fn y_offset(&self) -> u16
Examples found in repository?
examples/demo.rs (line 97)
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);
}
_ => {}
}
}
}
}sourcepub fn scroll_offset(&self) -> u16
pub fn scroll_offset(&self) -> u16
Examples found in repository?
examples/demo.rs (line 97)
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 set_y_offset(&mut self, y_offset: u16)
pub fn set_scroll_offset(&mut self, offset: u16)
pub fn is_focused(&self) -> bool
pub fn deselect(&mut self)
pub fn visually_select(&mut self, index: usize) -> Result<(), String>
pub fn highlight_link(&self) -> Result<&str, String>
pub fn num_links(&self) -> usize
pub fn selected_heights(&self) -> Vec<usize>
pub fn words_mut(&mut self) -> Vec<&mut Word>
pub fn transform(&mut self, width: u16)
Trait Implementations§
source§impl Clone for TextComponent
impl Clone for TextComponent
source§fn clone(&self) -> TextComponent
fn clone(&self) -> TextComponent
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for TextComponent
impl Debug for TextComponent
source§impl From<TextComponent> for Component
impl From<TextComponent> for Component
source§fn from(comp: TextComponent) -> Self
fn from(comp: TextComponent) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for TextComponent
impl RefUnwindSafe for TextComponent
impl Send for TextComponent
impl Sync for TextComponent
impl Unpin for TextComponent
impl UnwindSafe for TextComponent
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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