Struct cosmic_text::LayoutCursor
source · Fields§
§line: usize§layout: usize§glyph: usizeImplementations§
source§impl LayoutCursor
impl LayoutCursor
sourcepub fn new(line: usize, layout: usize, glyph: usize) -> Self
pub fn new(line: usize, layout: usize, glyph: usize) -> Self
Examples found in repository?
src/buffer.rs (lines 303-307)
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
pub fn layout_cursor(&self, cursor: &Cursor) -> LayoutCursor {
let line = &self.lines[cursor.line];
//TODO: ensure layout is done?
let layout = line.layout_opt().as_ref().expect("layout not found");
for (layout_i, layout_line) in layout.iter().enumerate() {
for (glyph_i, glyph) in layout_line.glyphs.iter().enumerate() {
if cursor.index == glyph.start {
return LayoutCursor::new(
cursor.line,
layout_i,
glyph_i
);
}
}
match layout_line.glyphs.last() {
Some(glyph) => {
if cursor.index == glyph.end {
return LayoutCursor::new(
cursor.line,
layout_i,
layout_line.glyphs.len()
);
}
},
None => {
return LayoutCursor::new(
cursor.line,
layout_i,
0
);
}
}
}
// Fall back to start of line
//TODO: should this be the end of the line?
LayoutCursor::new(
cursor.line,
0,
0
)
}