iterate on visible runs within textbounds (#108)
This commit is contained in:
parent
719d69a1ee
commit
f82094703e
1 changed files with 12 additions and 1 deletions
|
@ -60,7 +60,18 @@ impl TextRenderer {
|
||||||
let resolution = viewport.resolution();
|
let resolution = viewport.resolution();
|
||||||
|
|
||||||
for text_area in text_areas {
|
for text_area in text_areas {
|
||||||
for run in text_area.buffer.layout_runs() {
|
let is_run_visible = |run: &cosmic_text::LayoutRun| {
|
||||||
|
let start_y = (text_area.top + run.line_top) as i32;
|
||||||
|
let end_y = (text_area.top + run.line_top + run.line_height) as i32;
|
||||||
|
|
||||||
|
start_y <= text_area.bounds.bottom && text_area.bounds.top <= end_y
|
||||||
|
};
|
||||||
|
|
||||||
|
let layout_runs = text_area.buffer.layout_runs()
|
||||||
|
.skip_while(|run| !is_run_visible(run))
|
||||||
|
.take_while(is_run_visible);
|
||||||
|
|
||||||
|
for run in layout_runs {
|
||||||
for glyph in run.glyphs.iter() {
|
for glyph in run.glyphs.iter() {
|
||||||
let physical_glyph =
|
let physical_glyph =
|
||||||
glyph.physical((text_area.left, text_area.top), text_area.scale);
|
glyph.physical((text_area.left, text_area.top), text_area.scale);
|
||||||
|
|
Loading…
Reference in a new issue