Skip to main content

LayoutEngine

Struct LayoutEngine 

Source
pub struct LayoutEngine { /* private fields */ }
Expand description

Layout engine - manages visual representation of all lines

Implementations§

Source§

impl LayoutEngine

Source

pub fn new(viewport_width: usize) -> Self

Create a new layout engine

Source

pub fn set_viewport_width(&mut self, width: usize)

Set viewport width

Source

pub fn viewport_width(&self) -> usize

Get viewport width

Source

pub fn tab_width(&self) -> usize

Get tab width (in cells).

Source

pub fn set_tab_width(&mut self, tab_width: usize)

Set tab width (in cells) used for expanding '\t'.

If tab_width changes, all line layouts are recalculated.

Source

pub fn from_lines(&mut self, lines: &[&str])

Build layout from list of text lines

Source

pub fn add_line(&mut self, text: &str)

Add a line

Source

pub fn update_line(&mut self, line_index: usize, text: &str)

Update a specific line

Source

pub fn insert_line(&mut self, line_index: usize, text: &str)

Insert a line

Source

pub fn delete_line(&mut self, line_index: usize)

Delete a line

Source

pub fn get_line_layout(&self, line_index: usize) -> Option<&VisualLineInfo>

Get visual information for a specific logical line

Source

pub fn logical_line_count(&self) -> usize

Get total number of logical lines

Source

pub fn visual_line_count(&self) -> usize

Get total number of visual lines

Source

pub fn logical_to_visual_line(&self, logical_line: usize) -> usize

Convert logical line number to visual line number

Returns the line number of the first visual line of this logical line

Source

pub fn visual_to_logical_line(&self, visual_line: usize) -> (usize, usize)

Convert visual line number to logical line number and offset within line

Returns (logical_line, visual_line_in_logical)

Source

pub fn clear(&mut self)

Clear all lines

Source

pub fn logical_position_to_visual( &self, logical_line: usize, column: usize, ) -> Option<(usize, usize)>

Convert logical coordinates (line, column) to visual coordinates (visual row number, x cell offset within row).

  • logical_line: Logical line number (0-based)
  • column: Character column within the logical line (0-based, counted by char)

Return value:

  • Some((visual_row, x)): visual_row is the global visual row number, x is the cell offset within that visual row
  • None: Line number out of range
Source

pub fn logical_position_to_visual_allow_virtual( &self, logical_line: usize, column: usize, ) -> Option<(usize, usize)>

Convert logical coordinates (line, column) to visual coordinates, allowing column to exceed line end (virtual spaces).

Difference from logical_position_to_visual:

  • column is not clamped to line_char_len
  • Excess portion is treated as virtual spaces of ' ' (width=1)

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