Mac Developer Library

Developer

AppKit Framework Reference NSLayoutManagerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSLayoutManagerDelegate

The NSLayoutManagerDelegate protocol defines the optional methods implemented by delegates of NSLayoutManager objects.

  • Informs the delegate that the given layout manager has invalidated layout information (not glyph information).

    Declaration

    Swift

    optional func layoutManagerDidInvalidateLayout(_ sender: NSLayoutManager)

    Objective-C

    - (void)layoutManagerDidInvalidateLayout:(NSLayoutManager *)sender

    Parameters

    sender

    The layout manager that invalidated layout.

    Discussion

    This method is invoked only when layout was complete and then became invalidated for some reason. Delegates can use this information to show an indicator of background layout or to enable a button that forces immediate layout of text.

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Enables customizing the initial glyph generation process.

    Declaration

    Swift

    optional func layoutManager(_ layoutManager: NSLayoutManager, shouldGenerateGlyphs glyphs: UnsafePointer<CGGlyph>, properties props: UnsafePointer<NSGlyphProperty>, characterIndexes charIndexes: UnsafePointer<Int>, font aFont: NSFont, forGlyphRange glyphRange: NSRange) -> Int

    Objective-C

    - (NSUInteger)layoutManager:(NSLayoutManager *)layoutManager shouldGenerateGlyphs:(const CGGlyph *)glyphs properties:(const NSGlyphProperty *)props characterIndexes:(const NSUInteger *)charIndexes font:(NSFont *)aFont forGlyphRange:(NSRange)glyphRange

    Parameters

    layoutManager

    The layout manager doing the layout.

    glyphs

    A pointer to the layout manager's glyph cache.

    props

    A pointer to a buffer containing glyph properties for the glyphs in the cache.

    charIndexes

    A pointer to the starting index for the characters in the text storage for which glyphs are generated.

    aFont

    A font to override the font attributes in the text storage for the specified character range.

    glyphRange

    The range of glyphs in the glyph cache to set.

    Return Value

    The actual glyph range stored in this method. By returning 0, it can indicate for the layout manager to do the default processing.

    Discussion

    This message is sent whenever the layout manager is about to store the initial glyph information via setGlyphs:properties:characterIndexes:font:forGlyphRange:. To customize the initial glyph generation process, this method can invoke setGlyphs:properties:characterIndexes:font:forGlyphRange: with modified glyph information.

    Availability

    Available in OS X v10.11 and later.

  • Returns the control character action for the control character at the given character index.

    Declaration

    Swift

    optional func layoutManager(_ layoutManager: NSLayoutManager, shouldUseAction action: NSControlCharacterAction, forControlCharacterAtIndex charIndex: Int) -> NSControlCharacterAction

    Objective-C

    - (NSControlCharacterAction)layoutManager:(NSLayoutManager *)layoutManager shouldUseAction:(NSControlCharacterAction)action forControlCharacterAtIndex:(NSUInteger)charIndex

    Parameters

    layoutManager

    The layout manager doing the layout.

    action

    The proposed control character action for the character at the given index. Possible values are enumerated by NSControlCharacterAction.

    charIndex

    The index of the control character for which the action is proposed.

    Return Value

    The control character action for the control character at the given index.

    Availability

    Available in OS X v10.11 and later.

  • Informs the delegate that the given layout manager has finished laying out text in the given text container.

    Declaration

    Swift

    optional func layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutForTextContainer textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool)

    Objective-C

    - (void)layoutManager:(NSLayoutManager *)aLayoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)aTextContainer atEnd:(BOOL)flag

    Parameters

    aLayoutManager

    The layout manager doing the layout.

    aTextContainer

    The text container in which layout is complete. If nil, if there aren’t enough containers to hold all the text; the delegate can use this information as a cue to add another text container.

    flag

    If YEStrue, aLayoutManager is finished laying out its text—this also means that aTextContainer is the final text container used by the layout manager. Delegates can use this information to show an indicator or background or to enable or disable a button that forces immediate layout of text.

    Discussion

    This message is sent whenever a text container has been filled. This method can be useful for paginating.

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Sent right before the layout manager invalidates layout due to the text container changing geometry.

    Declaration

    Swift

    optional func layoutManager(_ layoutManager: NSLayoutManager, textContainer textContainer: NSTextContainer, didChangeGeometryFromSize oldSize: NSSize)

    Objective-C

    - (void)layoutManager:(NSLayoutManager *)layoutManager textContainer:(NSTextContainer *)textContainer didChangeGeometryFromSize:(NSSize)oldSize

    Parameters

    layoutManager

    The layout manager invalidating layout.

    textContainer

    The text container that changed geometry.

    oldSize

    The size of the text container before it changed geometry.

    Discussion

    The delegate can react to the geometry change and perform adjustments such as recreate an exclusion path.

    Availability

    Available in OS X v10.11 and later.

  • Sent when the layout manager is drawing and needs to decide whether or not to use temporary attributes.

    Declaration

    Swift

    optional func layoutManager(_ layoutManager: NSLayoutManager, shouldUseTemporaryAttributes attrs: [String : AnyObject], forDrawingToScreen toScreen: Bool, atCharacterIndex charIndex: Int, effectiveRange effectiveCharRange: NSRangePointer) -> [String : AnyObject]?

    Objective-C

    - (NSDictionary<NSString *,id> *)layoutManager:(NSLayoutManager *)layoutManager shouldUseTemporaryAttributes:(NSDictionary<NSString *,id> *)attrs forDrawingToScreen:(BOOL)toScreen atCharacterIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveCharRange

    Parameters

    layoutManager

    The layout manager sending the message.

    attrs

    The temporary attributes currently in effect for the given character range.

    toScreen

    YEStrue if the layout manager is drawing to the screen; otherwise, NOfalse.

    charIndex

    Index of the first character in the range being drawn.

    effectiveCharRange

    On input and output, the effective range to which the temporary attributes apply.

    Return Value

    The temporary attributes for the layout manager to use, or nil if no temporary attributes are to be used.

    Discussion

    The default behavior, if this method is not implemented, is to use temporary attributes only when drawing to the screen, so an implementation to match that behavior would return attrs if toScreen is YEStrue and nil otherwise, without changing effectiveCharRange.

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.