Lifecycle of NSTextLayoutFragment

36 Views Asked by At

I'm trying to figure out how all these elements in TextKit 2 work together.

  1. NSTextElement - Abstract class and meant to be subclassed. macOS provides a concrete subclass NSTextParagraph.
  2. NSTextLayoutManager - Probably not meant to be subclassed. Accepts a delegate that can provide a NSTextLayoutFragment for a given NSTextElement.
  3. NSTextContentManager - Abstract class. Interface allows for concrete instances to provide an array of NSTextElement for a given NSTextRange.

I'd like to customize the way text is presented, and am having the devils time doing it :-)

I have subclassed NSTextContentManager and generate NSTextElements (on the paragraph level). If it's an NSTextParagraph, TextKit seems to automagically (?) generate the corresponding NSTextLineFragments when the NSTextLayoutFragment is created.

When the NSTextLayoutFragment is created it's state will be .none (I think). What makes it move between the different states (.none -> .layoutAvailable)? I don't see any customization points for this. When customizing NSTextLayoutFragment, should I just do layout at init (and store it somewhere)? Or is there a better place to do this?

Thanks

0

There are 0 best solutions below