Skip to content

Commit

Permalink
text: Cull text lines above text field
Browse files Browse the repository at this point in the history
We do not need to render text lines which are above the text field,
as they are masked anyway.
  • Loading branch information
kjarosh committed Oct 16, 2024
1 parent 2c2d418 commit fbb9108
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ impl<'gc> EditText<'gc> {
// If text's top is under the textbox's bottom, skip drawing.
// TODO: FP actually skips drawing a line as soon as its bottom is under the textbox;
// Current logic is conservative for safety (and even of this I'm not 100% sure).
// TODO: we should also cull text that's above the textbox
// (instead of culling, this can be implemented as having the loop start from `scrollY`th line)
// (maybe we could cull-before-render all glyphs, thus removing the need for masking?)
// [KJ] FP always displays the first visible line (sometimes masked, sometimes sticking out of bounds),
// culls any other line which is not fully visible; masking is always used for left/right bounds
// TODO: also cull text that's simply out of screen, just like we cull whole DOs in render_self().
if origin.y() + Twips::from_pixels(Self::INTERNAL_PADDING)
- edit_text.vertical_scroll_offset()
Expand Down Expand Up @@ -2376,7 +2376,9 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
..Default::default()
});

for line in edit_text.layout.lines() {
// Skip lines that are off-screen.
let lines_to_skip = self.scroll().saturating_sub(1);
for line in edit_text.layout.lines().iter().skip(lines_to_skip) {
self.render_layout_line(context, line);
}

Expand Down

0 comments on commit fbb9108

Please sign in to comment.