Add layout_opt and shape_opt getters to TextBufferLine
This commit is contained in:
parent
46a922194c
commit
88bd1c9235
2 changed files with 26 additions and 11 deletions
|
|
@ -116,8 +116,8 @@ impl<'a, 'b> Iterator for TextLayoutRunIter<'a, 'b> {
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
while let Some(line) = self.buffer.lines.get(self.line_i) {
|
while let Some(line) = self.buffer.lines.get(self.line_i) {
|
||||||
let shape = line.shape_opt.as_ref()?;
|
let shape = line.shape_opt().as_ref()?;
|
||||||
let layout = line.layout_opt.as_ref()?;
|
let layout = line.layout_opt().as_ref()?;
|
||||||
while let Some(layout_line) = layout.get(self.layout_i) {
|
while let Some(layout_line) = layout.get(self.layout_i) {
|
||||||
self.layout_i += 1;
|
self.layout_i += 1;
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if line.shape_opt.is_none() {
|
if line.shape_opt().is_none() {
|
||||||
reshaped += 1;
|
reshaped += 1;
|
||||||
}
|
}
|
||||||
let layout = line.layout(
|
let layout = line.layout(
|
||||||
|
|
@ -261,7 +261,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if line.shape_opt.is_none() {
|
if line.shape_opt().is_none() {
|
||||||
reshaped += 1;
|
reshaped += 1;
|
||||||
}
|
}
|
||||||
let layout = line.layout(
|
let layout = line.layout(
|
||||||
|
|
@ -314,8 +314,8 @@ impl<'a> TextBuffer<'a> {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
|
|
||||||
for line in self.lines.iter_mut() {
|
for line in self.lines.iter_mut() {
|
||||||
if line.shape_opt.is_some() {
|
if line.shape_opt().is_some() {
|
||||||
line.layout_opt = None;
|
line.reset_layout();
|
||||||
line.layout(
|
line.layout(
|
||||||
self.font_system,
|
self.font_system,
|
||||||
self.metrics.font_size,
|
self.metrics.font_size,
|
||||||
|
|
@ -333,7 +333,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
fn layout_cursor(&self, cursor: &TextCursor) -> TextLayoutCursor {
|
fn layout_cursor(&self, cursor: &TextCursor) -> TextLayoutCursor {
|
||||||
let line = &self.lines[cursor.line];
|
let line = &self.lines[cursor.line];
|
||||||
|
|
||||||
let layout = line.layout_opt.as_ref().unwrap(); //TODO: ensure layout is done?
|
let layout = line.layout_opt().as_ref().unwrap(); //TODO: ensure layout is done?
|
||||||
for (layout_i, layout_line) in layout.iter().enumerate() {
|
for (layout_i, layout_line) in layout.iter().enumerate() {
|
||||||
for (glyph_i, glyph) in layout_line.glyphs.iter().enumerate() {
|
for (glyph_i, glyph) in layout_line.glyphs.iter().enumerate() {
|
||||||
if cursor.index == glyph.start {
|
if cursor.index == glyph.start {
|
||||||
|
|
@ -516,7 +516,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
self.cursor_x_opt = None;
|
self.cursor_x_opt = None;
|
||||||
},
|
},
|
||||||
TextAction::Left => {
|
TextAction::Left => {
|
||||||
let rtl_opt = self.lines[self.cursor.line].shape_opt.as_ref().map(|shape| shape.rtl);
|
let rtl_opt = self.lines[self.cursor.line].shape_opt().as_ref().map(|shape| shape.rtl);
|
||||||
if let Some(rtl) = rtl_opt {
|
if let Some(rtl) = rtl_opt {
|
||||||
if rtl {
|
if rtl {
|
||||||
self.action(TextAction::Next);
|
self.action(TextAction::Next);
|
||||||
|
|
@ -526,7 +526,7 @@ impl<'a> TextBuffer<'a> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TextAction::Right => {
|
TextAction::Right => {
|
||||||
let rtl_opt = self.lines[self.cursor.line].shape_opt.as_ref().map(|shape| shape.rtl);
|
let rtl_opt = self.lines[self.cursor.line].shape_opt().as_ref().map(|shape| shape.rtl);
|
||||||
if let Some(rtl) = rtl_opt {
|
if let Some(rtl) = rtl_opt {
|
||||||
if rtl {
|
if rtl {
|
||||||
self.action(TextAction::Previous);
|
self.action(TextAction::Previous);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ pub struct TextBufferLine<'a> {
|
||||||
text: String,
|
text: String,
|
||||||
attrs_list: AttrsList<'a>,
|
attrs_list: AttrsList<'a>,
|
||||||
wrap_simple: bool,
|
wrap_simple: bool,
|
||||||
pub(crate) shape_opt: Option<ShapeLine>,
|
shape_opt: Option<ShapeLine>,
|
||||||
pub(crate) layout_opt: Option<Vec<LayoutLine>>,
|
layout_opt: Option<Vec<LayoutLine>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TextBufferLine<'a> {
|
impl<'a> TextBufferLine<'a> {
|
||||||
|
|
@ -121,6 +121,11 @@ impl<'a> TextBufferLine<'a> {
|
||||||
self.layout_opt = None;
|
self.layout_opt = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset only layout information
|
||||||
|
pub fn reset_layout(&mut self) {
|
||||||
|
self.layout_opt = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if shaping and layout information is cleared
|
/// Check if shaping and layout information is cleared
|
||||||
pub fn is_reset(&self) -> bool {
|
pub fn is_reset(&self) -> bool {
|
||||||
self.shape_opt.is_none()
|
self.shape_opt.is_none()
|
||||||
|
|
@ -135,6 +140,11 @@ impl<'a> TextBufferLine<'a> {
|
||||||
self.shape_opt.as_ref().unwrap()
|
self.shape_opt.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get line shaping cache
|
||||||
|
pub fn shape_opt(&self) -> &Option<ShapeLine> {
|
||||||
|
&self.shape_opt
|
||||||
|
}
|
||||||
|
|
||||||
/// Layout line, will cache results
|
/// Layout line, will cache results
|
||||||
pub fn layout(&mut self, font_system: &'a FontSystem<'a>, font_size: i32, width: i32) -> &[LayoutLine] {
|
pub fn layout(&mut self, font_system: &'a FontSystem<'a>, font_size: i32, width: i32) -> &[LayoutLine] {
|
||||||
if self.layout_opt.is_none() {
|
if self.layout_opt.is_none() {
|
||||||
|
|
@ -152,4 +162,9 @@ impl<'a> TextBufferLine<'a> {
|
||||||
}
|
}
|
||||||
self.layout_opt.as_ref().unwrap()
|
self.layout_opt.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get line layout cache
|
||||||
|
pub fn layout_opt(&self) -> &Option<Vec<LayoutLine>> {
|
||||||
|
&self.layout_opt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue