• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Text layout responsibility
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Text layout responsibility


  • Subject: Re: Text layout responsibility
  • From: Martin Wierschin <email@hidden>
  • Date: Fri, 12 Dec 2008 11:46:56 -0800

Try changing the container size once the layout is complete, you can do this by using the delegate method:
- (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)textContainer atEnd:(BOOL)layoutFinishedFlag
and checking the layoutFinishedFlag.

In my experience it is not safe to do anything that can trigger layout in the "didCompleteLayoutForTextContainer" delegate method. This is unfortunately just one of a few ways in which the layout system seems to be fragile. The rules I've come to live by:


1. Never trigger recursive layout. This means that if there is any NSLayoutManager code below you on the stack, you cannot safely:
a. invalidate layout for any characters/glyphs.
b. change geometry for a text container.
c. request layout information for an unfinished region, unless you use the "withoutAdditionalLayout:YES" flag.


2. As Rimas discovered, do not trigger layout before NSTextStorage has completely cleared its edited state.

3. Never edit the contents of the NSTextStorage while layout is active on the stack.

To my knowledge these aren't really documented anywhere, excluding #3 which is sort of mentioned in the documentation for -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:]. Unfortunately these issues make it very awkward to do many of the things one might want in response to delegate/notification methods. Basically you just have to queue up your changes until you know layout/editing isn't in progress.

~Martin

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Text layout responsibility
      • From: Rimas <email@hidden>
References: 
 >Text layout responsibility (From: Rimas <email@hidden>)
 >Re: Text layout responsibility (From: Martin Wierschin <email@hidden>)
 >Re: Re: Text layout responsibility (From: Rimas <email@hidden>)
 >Re: Text layout responsibility (From: Martin Wierschin <email@hidden>)
 >Re: Text layout responsibility (From: Rimas <email@hidden>)
 >Re: Text layout responsibility (From: Martin Wierschin <email@hidden>)
 >Re: Text layout responsibility (From: Rimas <email@hidden>)
 >Re: Text layout responsibility (From: chaitanya pandit <email@hidden>)

  • Prev by Date: Re: NSApp beginSheet:NSWindow notification of sheet opening?
  • Next by Date: Re: - [NSBitmapImageRep tiffRepresentation] malloc error
  • Previous by thread: Re: Text layout responsibility
  • Next by thread: Re: Text layout responsibility
  • Index(es):
    • Date
    • Thread