Skip to main content

View

Struct View 

Source
pub struct View {
    pub metrics: Metrics,
    pub width: f32,
    pub height: f32,
    /* private fields */
}

Fields§

§metrics: Metrics§width: f32§height: f32

Implementations§

Source§

impl View

Source

pub fn new(metrics: Metrics, width: f32, height: f32) -> Self

Source

pub fn scroll_top(&self) -> f64

Source

pub fn scroll_left(&self) -> f32

Source

pub fn resize(&mut self, width: f32, height: f32)

Source

pub fn set_wrap(&mut self, wrap: bool)

Turns word wrap at the viewport’s width on or off. Takes effect at the next sync.

Source

pub fn wraps(&self) -> bool

Source

pub fn set_minimap(&mut self, width: f32)

Shows a minimap width pixels wide at the right (0 hides it). The text area narrows by the same amount.

Source

pub fn minimap_width(&self) -> f32

Source

pub fn set_sticky_scroll(&mut self, max: usize)

Pins up to max headers of the scopes (foldable regions) the viewport’s top is inside; 0 turns sticky scroll off.

Source

pub fn sticky_lines(&self, rope: &Rope) -> Vec<(usize, f32)>

The scope headers to pin, outermost first, each with its viewport y. The innermost one slides up as the end of its scope scrolls past, so the next line can take its place.

Source

pub fn gutter_width(&self, rope: &Rope) -> f32

Source

pub fn line_rows(&self, rope: &Rope, line: usize) -> LineRows

The rows line shows as.

Source

pub fn sync(&mut self, model: &TextModel)

Brings line heights and folds up to date with model. Layout calls it; call it too before hit testing or revealing right after an edit.

Source

pub fn add_zone( &mut self, model: &TextModel, id: u32, after: Option<usize>, height: f32, )

Adds a view zone after after (None: above the first line), height pixels tall. Other zones keep the positions edits gave them.

Source

pub fn remove_zone(&mut self, model: &TextModel, id: u32) -> bool

Removes the view zone id. Returns false when there is none.

Source

pub fn set_zones( &mut self, model: &TextModel, zones: impl IntoIterator<Item = (u32, Option<usize>, f32)>, )

Replaces the view zones: (id, line the zone follows or None for above the first line, height in pixels).

Source

pub fn set_foldable(&mut self, ranges: Vec<(usize, usize)>)

Replaces the regions that can be folded: (header line, last line) pairs, for example from indent_fold_ranges or a syntax tree.

Source

pub fn is_hidden(&self, line: usize) -> bool

Source

pub fn shown_segments(&self, lines: Range<usize>) -> Vec<Range<usize>>

Runs of shown lines in lines, as ranges.

Source

pub fn is_folded(&self, rope: &Rope, line: usize) -> bool

Whether line heads a collapsed fold.

Source

pub fn fold(&mut self, model: &TextModel, line: usize) -> bool

Collapses the innermost open region that holds line. Returns false if none does.

Source

pub fn unfold(&mut self, model: &TextModel, line: usize) -> bool

Opens the folds headed at line or hiding it. Returns false if there were none.

Source

pub fn toggle_fold(&mut self, model: &TextModel, line: usize) -> bool

Folds or unfolds at line.

Source

pub fn fold_all(&mut self, model: &TextModel)

Collapses every foldable region.

Source

pub fn unfold_all(&mut self, model: &TextModel)

Source

pub fn reveal_positions( &mut self, model: &TextModel, positions: impl IntoIterator<Item = usize>, ) -> bool

Opens folds hiding any of positions (char offsets), as when a caret lands inside one. Returns whether anything changed.

Source

pub fn shown_line_for(&self, line: usize) -> usize

The header line of the fold hiding line, or line when it is shown.

Source

pub fn line_top(&self, line: usize) -> f64

Document y of the top of line. A hidden line sits at the top of the next shown line.

Source

pub fn line_height(&self, line: usize) -> f32

Height of line: all its rows, or 0 when it is folded away.

Source

pub fn line_at_y(&self, rope: &Rope, y: f64) -> usize

The shown line at document y, clamped into the document.

Source

pub fn content_height(&self, rope: &Rope) -> f64

Height of the scrollable content. The last line can scroll up to the top of the viewport.

Source

pub fn content_width(&self, rope: &Rope) -> f32

Source

pub fn visible_lines(&self, rope: &Rope) -> Range<usize> ⓘ

Lines from the first to the last on screen. Folded lines inside are included; layout skips them.

Source

pub fn set_inlays(&mut self, model: &TextModel, hints: Vec<(usize, String)>)

Shows inlay hints: label drawn before the char at each offset, pushing the text after it right. A caret at that offset stays before the hint.

Source

pub fn vertical_target( &self, rope: &Rope, head: usize, goal: Option<usize>, lines: isize, ) -> (usize, Option<usize>)

The caret target lines rows above (negative) or below head, skipping folded lines and keeping goal (x in cells within the row) when given: (offset, goal).

Source

pub fn page_rows(&self) -> usize

Rows a page holds.

Source

pub fn scroll_to(&mut self, rope: &Rope, top: f64, left: f32)

Source

pub fn scroll_by(&mut self, rope: &Rope, dx: f32, dy: f64)

Source

pub fn reveal(&mut self, rope: &Rope, pos: usize)

Scrolls the minimum distance that makes the char at pos fully visible.

Source

pub fn hit_test(&self, rope: &Rope, x: f32, y: f32) -> usize

Char offset nearest to a point in viewport coordinates.

Source

pub fn line_and_cells_at(&self, rope: &Rope, x: f32, y: f32) -> (usize, f32)

The line and visual column (fractional cells from the line start, may lie past the line’s end) at a point in viewport coordinates. Column selection uses cells, so it stays rectangular across lines with tabs.

Source

pub fn in_fold_gutter(&self, rope: &Rope, x: f32) -> bool

Whether viewport x falls on the fold marker column of the gutter.

Source

pub fn offset_at_cells(&self, rope: &Rope, line: usize, cells: f32) -> usize

Char offset of the column nearest to cells on line.

Source

pub fn layout( &mut self, model: &TextModel, selections: &Selections, styler: &dyn Styler, ) -> Frame

Source

pub fn minimap_lines(&self, rope: &Rope) -> Range<usize> ⓘ

Lines the minimap shows, folded ones included; a frontend highlights them too.

Source

pub fn minimap_slider(&self, rope: &Rope) -> Rect

The minimap’s slider: the part of the minimap the viewport shows.

Source

pub fn in_minimap(&self, x: f32) -> bool

Whether viewport x falls on the minimap.

Source

pub fn minimap_scroll_target(&self, rope: &Rope, y: f32) -> f64

Scroll position that puts the document y under minimap y y in the middle of the viewport, for a click on the minimap.

Source

pub fn minimap_drag_factor(&self, rope: &Rope) -> f64

Scroll distance per pixel of slider drag.

Source

pub fn position_rect(&self, rope: &Rope, pos: usize) -> Option<Rect>

Where a caret at char pos would be drawn, if its line is visible: for placing widgets next to text.

Source

pub fn decoration_rects(&self, model: &TextModel) -> Vec<(Rect, u32)>

Rectangles for decorations on the visible lines, with each decoration’s kind. Call after View::layout for the same frame.

Source

pub fn line_bands( &self, model: &TextModel, whole_line: impl Fn(u32) -> bool, ) -> Vec<(Rect, u32)>

Bands across the text area for whole-line decorations (kinds whole_line accepts) on the visible lines: one band per shown line the decoration touches.

Source

pub fn gutter_marks( &self, model: &TextModel, accept: impl Fn(u32) -> bool, ) -> Vec<(f32, f32, u32)>

Marks for the gutter: for each visible shown line a decoration (of a kind accept takes) touches, the line’s y and height with the kind.

Source

pub fn overview_marks( &self, model: &TextModel, track: f32, accept: impl Fn(u32) -> bool, ) -> Vec<(f32, f32, u32)>

Marks for the overview ruler, a strip track pixels tall standing for the whole document: for every decoration of an accepted kind, its top and height on the strip (at least 2 px) with its kind. Folded lines map to their fold’s header. Cached until decorations or line positions change, since a search can leave tens of thousands of decorations and the marks do not depend on the scroll position.

Source

pub fn indent_guides(&self, model: &TextModel, cursor_line: usize) -> Vec<Guide>

Indentation guides for the visible lines: one vertical segment per indentation level and run of lines. A blank line takes the smaller level of the nearest non-blank lines around it, so guides continue through blank lines inside a block but not past its end. The guide of the block holding cursor_line is marked active. Folded lines are skipped: a guide runs on through a fold only if the lines on both sides are inside it.

Source

pub fn char_rects(&self, model: &TextModel, pos: usize) -> Vec<Rect>

The rectangle of the char at pos (one cell wide for a line end), if visible.

Source

pub fn char_range_rects( &self, model: &TextModel, range: Range<usize>, ) -> Vec<Rect>

Rectangles covering range on the visible lines.

Source

pub fn ruler_positions(&self, model: &TextModel, columns: &[usize]) -> Vec<f32>

X positions of rulers drawn at the given columns.

Source

pub fn whitespace_marks( &self, model: &TextModel, ) -> Vec<(f32, f32, usize, bool)>

Positions of spaces and tabs on the visible lines, for drawing them as · and →: (x of the cell start, y of the row top, width in cells, is a tab).

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for View

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for View

§

impl !RefUnwindSafe for View

§

impl !Sync for View

§

impl Forget for View

§

impl Move for View

§

impl Send for View

§

impl Unpin for View

§

impl UnsafeUnpin for View

§

impl UnwindSafe for View

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.