Refactor of scroll and shaping
- Scroll is identified by line index and layout index, instead of just layout index - Shaping has the option to prune, where caches outside of the scroll view are cleared - Syntax editor no longer requires layout of all lines, only of lines inside scroll - BufferLine has a metadata field that can be used by other abstractions to know when text was changed
This commit is contained in:
parent
e7261fc06e
commit
d0b4b4635e
16 changed files with 213 additions and 159 deletions
|
|
@ -13,6 +13,7 @@ pub struct BufferLine {
|
|||
shape_opt: Option<ShapeLine>,
|
||||
layout_opt: Option<Vec<LayoutLine>>,
|
||||
shaping: Shaping,
|
||||
metadata: Option<usize>,
|
||||
}
|
||||
|
||||
impl BufferLine {
|
||||
|
|
@ -27,6 +28,7 @@ impl BufferLine {
|
|||
shape_opt: None,
|
||||
layout_opt: None,
|
||||
shaping,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ impl BufferLine {
|
|||
pub fn set_attrs_list(&mut self, attrs_list: AttrsList) -> bool {
|
||||
if attrs_list != self.attrs_list {
|
||||
self.attrs_list = attrs_list;
|
||||
self.reset();
|
||||
self.reset_shaping();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
@ -129,23 +131,23 @@ impl BufferLine {
|
|||
new
|
||||
}
|
||||
|
||||
/// Reset shaping and layout information
|
||||
//TODO: make this private
|
||||
/// Reset shaping, layout, and metadata caches
|
||||
pub fn reset(&mut self) {
|
||||
self.shape_opt = None;
|
||||
self.layout_opt = None;
|
||||
self.metadata = None;
|
||||
self.reset_shaping();
|
||||
}
|
||||
|
||||
/// Reset only layout information
|
||||
/// Reset shaping and layout caches
|
||||
pub fn reset_shaping(&mut self) {
|
||||
self.shape_opt = None;
|
||||
self.reset_layout();
|
||||
}
|
||||
|
||||
/// Reset only layout cache
|
||||
pub fn reset_layout(&mut self) {
|
||||
self.layout_opt = None;
|
||||
}
|
||||
|
||||
/// Check if shaping and layout information is cleared
|
||||
pub fn is_reset(&self) -> bool {
|
||||
self.shape_opt.is_none()
|
||||
}
|
||||
|
||||
/// Shape line, will cache results
|
||||
pub fn shape(&mut self, font_system: &mut FontSystem) -> &ShapeLine {
|
||||
self.shape_in_buffer(&mut ShapeBuffer::default(), font_system)
|
||||
|
|
@ -215,4 +217,15 @@ impl BufferLine {
|
|||
pub fn layout_opt(&self) -> &Option<Vec<LayoutLine>> {
|
||||
&self.layout_opt
|
||||
}
|
||||
|
||||
/// Get line metadata. This will be None if [`BufferLine::set_metadata`] has not been called
|
||||
/// after the last reset of shaping and layout caches
|
||||
pub fn metadata(&self) -> Option<usize> {
|
||||
self.metadata
|
||||
}
|
||||
|
||||
/// Set line metadata. This is stored until the next line reset
|
||||
pub fn set_metadata(&mut self, metadata: usize) {
|
||||
self.metadata = Some(metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue