Skip to content

Introduce Override Layout Behavior API #84

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

Merged

Conversation

thecoolwinter
Copy link
Contributor

@thecoolwinter thecoolwinter commented Apr 10, 2025

Description

Introduces an API to override how text is laid out by the layout manager. An API consumer can implement an object conforming to the TextLayoutManagerRenderDelegate protocol to provide custom behavior.

Introduces tests for new APIs.

Specific changes:

  • Created a new TextLayoutManagerRenderDelegate which contains optional methods to override layout behavior. All methods are optional, and default to the default implementation.
  • Updates the layout manager to use these methods where relevant.
    • Estimated height, line height.
    • Finding x position in a line fragment.
    • Creating a view to render a line fragment (LineFragmentView by default, but the render delegate can give a custom one).
  • Makes lots of variables and methods public that weren't previously. Since we're allowing using the layout manager outside the context of a text view, these are necessarily public.
  • LineFragmentView is now an open class to allow for overriding methods.
  • Two methods on LineFragment have been marked as depreciated (xPos and rectFor). These were moved to the TextLayoutManger to ensure that the new render delegate can inject it's own behavior for both those methods if available.
  • TextSelectionManager
    • draw method is now public, for drawing selections in a custom context.
    • Updates some methods that were calculating drawing rects to use the layout manager information, rather than text view information. This allows the selection manager's behavior to reflect overridden layout manager behavior.
  • Documented exactly what layoutLines does in TextLayoutManager.
  • Removed two misleading methods. ensureLayoutUntil was used once, and it was not being used correctly. preparePositionForDisplay was only used by that method. Both of these methods destroyed layout information without recourse, sometimes causing text to just disappear despite a perfectly valid layout pass.
    • ensureLayoutUntil could be added back, but needs to be implemented in a way that's additive, rather than removing layout information.
    • Removing these changes didn't effect the ability to jump to scroll positions, or emphasize text ranges.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Copy link
Member

@tom-ludwig tom-ludwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Also, big thanks for the well-written PR description—it really makes the review process smoother. Just a few minor suggestions in the documentation to improve readability.

thecoolwinter and others added 3 commits April 18, 2025 08:11
Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
Co-authored-by: Tom Ludwig <tommludwig@icloud.com>
@thecoolwinter thecoolwinter merged commit 2603ff1 into CodeEditApp:main Apr 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants