pub struct View {
pub metrics: Metrics,
pub width: f32,
pub height: f32,
/* private fields */
}Fields§
§metrics: Metrics§width: f32§height: f32Implementations§
Source§impl View
impl View
pub fn new(metrics: Metrics, width: f32, height: f32) -> Self
pub fn scroll_top(&self) -> f64
pub fn scroll_left(&self) -> f32
pub fn resize(&mut self, width: f32, height: f32)
Sourcepub fn set_wrap(&mut self, wrap: bool)
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.
pub fn wraps(&self) -> bool
Sourcepub fn set_minimap(&mut self, width: f32)
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.
pub fn minimap_width(&self) -> f32
Sourcepub fn set_sticky_scroll(&mut self, max: usize)
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.
Sourcepub fn sticky_lines(&self, rope: &Rope) -> Vec<(usize, f32)>
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.
pub fn gutter_width(&self, rope: &Rope) -> f32
Sourcepub fn sync(&mut self, model: &TextModel)
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.
Sourcepub fn add_zone(
&mut self,
model: &TextModel,
id: u32,
after: Option<usize>,
height: f32,
)
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.
Sourcepub fn remove_zone(&mut self, model: &TextModel, id: u32) -> bool
pub fn remove_zone(&mut self, model: &TextModel, id: u32) -> bool
Removes the view zone id. Returns false when there is none.
Sourcepub fn set_zones(
&mut self,
model: &TextModel,
zones: impl IntoIterator<Item = (u32, Option<usize>, f32)>,
)
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).
Sourcepub fn set_foldable(&mut self, ranges: Vec<(usize, usize)>)
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.
Sourcepub fn shown_segments(&self, lines: Range<usize>) -> Vec<Range<usize>>
pub fn shown_segments(&self, lines: Range<usize>) -> Vec<Range<usize>>
Runs of shown lines in lines, as ranges.
Sourcepub fn fold(&mut self, model: &TextModel, line: usize) -> bool
pub fn fold(&mut self, model: &TextModel, line: usize) -> bool
Collapses the innermost open region that holds line. Returns false if none does.
Sourcepub fn unfold(&mut self, model: &TextModel, line: usize) -> bool
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.
Sourcepub fn toggle_fold(&mut self, model: &TextModel, line: usize) -> bool
pub fn toggle_fold(&mut self, model: &TextModel, line: usize) -> bool
Folds or unfolds at line.
pub fn unfold_all(&mut self, model: &TextModel)
Sourcepub fn reveal_positions(
&mut self,
model: &TextModel,
positions: impl IntoIterator<Item = usize>,
) -> bool
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.
Sourcepub fn shown_line_for(&self, line: usize) -> usize
pub fn shown_line_for(&self, line: usize) -> usize
The header line of the fold hiding line, or line when it is shown.
Sourcepub fn line_top(&self, line: usize) -> f64
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.
Sourcepub fn line_height(&self, line: usize) -> f32
pub fn line_height(&self, line: usize) -> f32
Height of line: all its rows, or 0 when it is folded away.
Sourcepub fn line_at_y(&self, rope: &Rope, y: f64) -> usize
pub fn line_at_y(&self, rope: &Rope, y: f64) -> usize
The shown line at document y, clamped into the document.
Sourcepub fn content_height(&self, rope: &Rope) -> f64
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.
pub fn content_width(&self, rope: &Rope) -> f32
Sourcepub fn visible_lines(&self, rope: &Rope) -> Range<usize> ⓘ
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.
Sourcepub fn set_inlays(&mut self, model: &TextModel, hints: Vec<(usize, String)>)
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.
Sourcepub fn vertical_target(
&self,
rope: &Rope,
head: usize,
goal: Option<usize>,
lines: isize,
) -> (usize, Option<usize>)
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).
pub fn scroll_to(&mut self, rope: &Rope, top: f64, left: f32)
pub fn scroll_by(&mut self, rope: &Rope, dx: f32, dy: f64)
Sourcepub fn reveal(&mut self, rope: &Rope, pos: usize)
pub fn reveal(&mut self, rope: &Rope, pos: usize)
Scrolls the minimum distance that makes the char at pos fully visible.
Sourcepub fn hit_test(&self, rope: &Rope, x: f32, y: f32) -> usize
pub fn hit_test(&self, rope: &Rope, x: f32, y: f32) -> usize
Char offset nearest to a point in viewport coordinates.
Sourcepub fn line_and_cells_at(&self, rope: &Rope, x: f32, y: f32) -> (usize, f32)
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.
Sourcepub fn in_fold_gutter(&self, rope: &Rope, x: f32) -> bool
pub fn in_fold_gutter(&self, rope: &Rope, x: f32) -> bool
Whether viewport x falls on the fold marker column of the gutter.
Sourcepub fn offset_at_cells(&self, rope: &Rope, line: usize, cells: f32) -> usize
pub fn offset_at_cells(&self, rope: &Rope, line: usize, cells: f32) -> usize
Char offset of the column nearest to cells on line.
pub fn layout( &mut self, model: &TextModel, selections: &Selections, styler: &dyn Styler, ) -> Frame
Sourcepub fn minimap_lines(&self, rope: &Rope) -> Range<usize> ⓘ
pub fn minimap_lines(&self, rope: &Rope) -> Range<usize> ⓘ
Lines the minimap shows, folded ones included; a frontend highlights them too.
Sourcepub fn minimap_slider(&self, rope: &Rope) -> Rect
pub fn minimap_slider(&self, rope: &Rope) -> Rect
The minimap’s slider: the part of the minimap the viewport shows.
Sourcepub fn in_minimap(&self, x: f32) -> bool
pub fn in_minimap(&self, x: f32) -> bool
Whether viewport x falls on the minimap.
Sourcepub fn minimap_scroll_target(&self, rope: &Rope, y: f32) -> f64
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.
Sourcepub fn minimap_drag_factor(&self, rope: &Rope) -> f64
pub fn minimap_drag_factor(&self, rope: &Rope) -> f64
Scroll distance per pixel of slider drag.
Sourcepub fn position_rect(&self, rope: &Rope, pos: usize) -> Option<Rect>
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.
Sourcepub fn decoration_rects(&self, model: &TextModel) -> Vec<(Rect, u32)>
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.
Sourcepub fn line_bands(
&self,
model: &TextModel,
whole_line: impl Fn(u32) -> bool,
) -> Vec<(Rect, u32)>
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.
Sourcepub fn gutter_marks(
&self,
model: &TextModel,
accept: impl Fn(u32) -> bool,
) -> Vec<(f32, f32, u32)>
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.
Sourcepub fn overview_marks(
&self,
model: &TextModel,
track: f32,
accept: impl Fn(u32) -> bool,
) -> Vec<(f32, f32, u32)>
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.
Sourcepub fn indent_guides(&self, model: &TextModel, cursor_line: usize) -> Vec<Guide>
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.
Sourcepub fn char_rects(&self, model: &TextModel, pos: usize) -> Vec<Rect>
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.
Sourcepub fn char_range_rects(
&self,
model: &TextModel,
range: Range<usize>,
) -> Vec<Rect>
pub fn char_range_rects( &self, model: &TextModel, range: Range<usize>, ) -> Vec<Rect>
Rectangles covering range on the visible lines.