Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move text area bounds outside run/glyph loops #110

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/text_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ impl TextRenderer {
let resolution = viewport.resolution();

for text_area in text_areas {
let bounds_min_x = text_area.bounds.left.max(0);
let bounds_min_y = text_area.bounds.top.max(0);
let bounds_max_x = text_area.bounds.right.min(resolution.width as i32);
let bounds_max_y = text_area.bounds.bottom.min(resolution.height as i32);

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
start_y <= bounds_max_y && bounds_min_y <= end_y
};

let layout_runs = text_area.buffer.layout_runs()
let layout_runs = text_area
.buffer
.layout_runs()
.skip_while(|run| !is_run_visible(run))
.take_while(is_run_visible);

Expand Down Expand Up @@ -198,11 +205,6 @@ impl TextRenderer {
let mut width = details.width as i32;
let mut height = details.height as i32;

let bounds_min_x = text_area.bounds.left.max(0);
let bounds_min_y = text_area.bounds.top.max(0);
let bounds_max_x = text_area.bounds.right.min(resolution.width as i32);
let bounds_max_y = text_area.bounds.bottom.min(resolution.height as i32);

// Starts beyond right edge or ends beyond left edge
let max_x = x + width;
if x > bounds_max_x || max_x < bounds_min_x {
Expand Down