Struct termimad::TextView

source ·
pub struct TextView<'a, 't> {
    pub scroll: usize,
    pub show_scrollbar: bool,
    /* private fields */
}
Expand description

A scrollable text, in a specific area.

The text is assumed to have been computed for the given area.

For example:

use termimad::*;

// You typically borrow those 3 vars from elsewhere
let markdown = "#title\n* item 1\n* item 2";
let area = Area::new(0, 0, 10, 12);
let skin = MadSkin::default();

// displaying
let text = skin.area_text(markdown, &area);
let view = TextView::from(&area, &text);
view.write().unwrap();

This struct is just a very thin wrapper and may be created dynamically for renderings or event handling.

If the text and skin are constant, you might prefer to use a MadView instead of a TextView: the MadView owns the markdown string and ensures the formatted text is computed accordingly to the area.

Fields§

§scroll: usize§show_scrollbar: bool

Implementations§

source§

impl<'a, 't> TextView<'a, 't>

source

pub const fn from(area: &'a Area, text: &'t FmtText<'_, '_>) -> TextView<'a, 't>

make a displayed text, that is a text in an area

source

pub fn content_height(&self) -> usize

source

pub fn scrollbar(&self) -> Option<(u16, u16)>

return an option which when filled contains a tupple with the top and bottom of the vertical scrollbar. Return none when the content fits the available space (or if show_scrollbar is false).

source

pub fn write(&self) -> Result<(), Error>

display the text in the area, taking the scroll into account.

source

pub fn write_on<W: Write>(&self, w: &mut W) -> Result<(), Error>

display the text in the area, taking the scroll into account.

source

pub fn set_scroll(&mut self, scroll: usize) -> usize

set the scroll position but makes it fit into allowed positions. Return the actual scroll.

source

pub fn try_scroll_lines(&mut self, lines_count: i32)

Change the scroll position.

lines_count can be negative

source

pub fn try_scroll_pages(&mut self, pages_count: i32)

change the scroll position pages_count can be negative

source

pub fn line_up(&mut self) -> bool

source

pub fn line_down(&mut self) -> bool

source

pub fn page_up(&mut self) -> bool

source

pub fn page_down(&mut self) -> bool

source

pub fn apply_key_event(&mut self, key: KeyEvent) -> bool

Apply an event being a key: page_up, page_down, up and down.

Return true when the event led to a change, false when it was discarded.

source

pub fn apply_key_combination<K: Into<KeyCombination>>(&mut self, key: K) -> bool

Apply an event being a key: page_up, page_down, up and down.

Return true when the event led to a change, false when it was discarded.

Auto Trait Implementations§

§

impl<'a, 't> Freeze for TextView<'a, 't>

§

impl<'a, 't> RefUnwindSafe for TextView<'a, 't>

§

impl<'a, 't> Send for TextView<'a, 't>

§

impl<'a, 't> Sync for TextView<'a, 't>

§

impl<'a, 't> Unpin for TextView<'a, 't>

§

impl<'a, 't> UnwindSafe for TextView<'a, 't>

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> 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.