Struct cosmic_text::TextBuffer
source · [−]pub struct TextBuffer<'a> {
pub lines: Vec<TextBufferLine<'a>>,
pub cursor_moved: bool,
pub redraw: bool,
/* private fields */
}
Expand description
A buffer of text that is shaped and laid out
Fields
lines: Vec<TextBufferLine<'a>>
Lines (or paragraphs) of text in the buffer
cursor_moved: bool
True if the cursor has been moved. Set to false after processing
Usually, if this is true, you should run Self::shape_until_cursor before redrawing. Otherwise, you should run Self::shape_until_scroll
redraw: bool
True if a redraw is requires. Set to false after processing
Implementations
sourceimpl<'a> TextBuffer<'a>
impl<'a> TextBuffer<'a>
pub fn new(font_system: &'a FontSystem<'a>, metrics: TextMetrics) -> Self
sourcepub fn shape_until(&mut self, lines: i32) -> i32
pub fn shape_until(&mut self, lines: i32) -> i32
Pre-shape lines in the buffer, up to lines
, return actual number of layout lines
sourcepub fn shape_until_cursor(&mut self)
pub fn shape_until_cursor(&mut self)
Shape lines until cursor, also scrolling to include cursor in view
sourcepub fn shape_until_scroll(&mut self)
pub fn shape_until_scroll(&mut self)
Shape lines until scroll
sourcepub fn cursor(&self) -> TextCursor
pub fn cursor(&self) -> TextCursor
Get the current cursor position
sourcepub fn metrics(&self) -> TextMetrics
pub fn metrics(&self) -> TextMetrics
Get the current TextMetrics
sourcepub fn set_metrics(&mut self, metrics: TextMetrics)
pub fn set_metrics(&mut self, metrics: TextMetrics)
Set the current TextMetrics
sourcepub fn set_text(&mut self, text: &str, attrs: Attrs<'a>)
pub fn set_text(&mut self, text: &str, attrs: Attrs<'a>)
Set text of buffer, using provided attributes for each line by default
sourcepub fn action(&mut self, action: TextAction)
pub fn action(&mut self, action: TextAction)
Perform a TextAction on the buffer
sourcepub fn hit(&self, x: i32, y: i32) -> Option<TextCursor>
pub fn hit(&self, x: i32, y: i32) -> Option<TextCursor>
Convert x, y position to TextCursor (hit detection)
sourcepub fn layout_runs<'b>(&'b self) -> TextLayoutRunIter<'a, 'b>ⓘNotable traits for TextLayoutRunIter<'a, 'b>impl<'a, 'b> Iterator for TextLayoutRunIter<'a, 'b> type Item = TextLayoutRun<'b>;
pub fn layout_runs<'b>(&'b self) -> TextLayoutRunIter<'a, 'b>ⓘNotable traits for TextLayoutRunIter<'a, 'b>impl<'a, 'b> Iterator for TextLayoutRunIter<'a, 'b> type Item = TextLayoutRun<'b>;
Get the visible layout runs for rendering and other tasks