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

text: Lazily layout text #7749

Closed
wants to merge 10 commits into from
Closed

Conversation

Herschel
Copy link
Member

@Herschel Herschel commented Aug 25, 2022

Continuing from #7735, reflow text lazily instead of every time a text parameter is changed.

When a text field property is modified (such as changing the text or font size), Flash marks the text layout as dirty. The layout is then recalculated lazily when the textfield is rendered, or when a value that depends on the layout is accessed via ActionScript.

  • Add RenderContext::gc_context to allow mutating the EditText during render.
    • This adds a lifetime parameter to RenderContext.
    • We want this for other places such as caching bitmaps as well.
    • We probably want to unify our Contexts some eventually, but that's orthogonal to this PR.
  • Change LayoutContext to only require the Library instead of a full UpdateContext.
    • It only needs the library to grab fonts.
  • Store a dirty flag for the text layout, and relayout the text on demand.
    • Changing various text field parameters like text, autoSize, _width marks the layout as dirty.
    • The layout will be recalculated when the text is rendered, or when AS accesses specific values.

This is more efficient and necessary for accuracy, as the layout will be calculated at different times depending on the order of property access.

TODO:

  • Don't relayout on getting _width/_height if autosize is disabled.
  • Check for any other properties that should trigger layout (scroll, etc.)
  • Use bitflags for various EditText bools.
  • Add a separate dirty flag for redraw_border?
  • Add tests.

@Herschel Herschel marked this pull request as draft August 25, 2022 06:28
@Toad06
Copy link
Member

Toad06 commented Jun 19, 2023

Seems like #7735 introduced a regression in #11632 (truncated texts in boxes), so it will be interesting to check if this PR fixes this issue.

@danielhjacobs danielhjacobs added A-core Area: Core player, where no other category fits T-perf T-perf Type: Performance Improvements and removed T-perf labels Sep 17, 2024
@kjarosh
Copy link
Member

kjarosh commented Jan 16, 2025

Superseded by #18870. We still could do lazy layout, but strictly for performance reasons and it would look a lot different anyway.

@kjarosh kjarosh closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core player, where no other category fits T-perf Type: Performance Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants