Skip to main content

Viewport

Struct Viewport 

Source
pub struct Viewport {
    pub width: usize,
    pub height: usize,
    pub key_map: KeyMap,
    pub mouse_wheel_enabled: bool,
    pub mouse_wheel_delta: usize,
    pub style: Style,
    /* private fields */
}
Expand description

Viewport model for scrollable content.

Fields§

§width: usize

Width of the viewport.

§height: usize

Height of the viewport.

§key_map: KeyMap

Key bindings for navigation.

§mouse_wheel_enabled: bool

Whether mouse wheel scrolling is enabled.

§mouse_wheel_delta: usize

Number of lines to scroll per mouse wheel tick.

§style: Style

Style for rendering the viewport.

Implementations§

Source§

impl Viewport

Source

pub fn new(width: usize, height: usize) -> Self

Creates a new viewport with the given dimensions.

Source

pub fn set_content(&mut self, content: &str)

Sets the content of the viewport.

Source

pub fn y_offset(&self) -> usize

Returns the vertical scroll offset.

Source

pub fn set_y_offset(&mut self, n: usize)

Sets the vertical scroll offset.

Source

pub fn x_offset(&self) -> usize

Returns the horizontal scroll offset.

Source

pub fn set_x_offset(&mut self, n: usize)

Sets the horizontal scroll offset.

Source

pub fn set_horizontal_step(&mut self, n: usize)

Sets the horizontal scroll step size.

Source

pub fn at_top(&self) -> bool

Returns whether the viewport is at the top.

Source

pub fn at_bottom(&self) -> bool

Returns whether the viewport is at the bottom.

Source

pub fn past_bottom(&self) -> bool

Returns whether the viewport is past the bottom.

Source

pub fn scroll_percent(&self) -> f64

Returns the scroll percentage (0.0 to 1.0).

Source

pub fn horizontal_scroll_percent(&self) -> f64

Returns the horizontal scroll percentage (0.0 to 1.0).

Source

pub fn total_line_count(&self) -> usize

Returns the total number of lines.

Source

pub fn visible_line_count(&self) -> usize

Returns the number of visible lines.

Source

pub fn scroll_down(&mut self, n: usize)

Scrolls down by the given number of lines.

Source

pub fn scroll_up(&mut self, n: usize)

Scrolls up by the given number of lines.

Source

pub fn scroll_left(&mut self, n: usize)

Scrolls left by the given number of columns.

Source

pub fn scroll_right(&mut self, n: usize)

Scrolls right by the given number of columns.

Source

pub fn page_down(&mut self)

Moves down one page.

Source

pub fn page_up(&mut self)

Moves up one page.

Source

pub fn half_page_down(&mut self)

Moves down half a page.

Source

pub fn half_page_up(&mut self)

Moves up half a page.

Source

pub fn goto_top(&mut self)

Goes to the top.

Source

pub fn goto_bottom(&mut self)

Goes to the bottom.

Source

pub fn update(&mut self, msg: &Message)

Updates the viewport based on key/mouse input.

Source

pub fn view(&self) -> String

Renders the viewport content.

Trait Implementations§

Source§

impl Clone for Viewport

Source§

fn clone(&self) -> Viewport

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Viewport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Model for Viewport

Implement the Model trait for standalone bubbletea usage.

Source§

fn init(&self) -> Option<Cmd>

Initialize the model and return an optional startup command. Read more
Source§

fn update(&mut self, msg: Message) -> Option<Cmd>

Process a message and return a new command. Read more
Source§

fn view(&self) -> String

Render the model as a string for display. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more