Re: Cocoa Text System - Temporarily Disabling Layout
Re: Cocoa Text System - Temporarily Disabling Layout
- Subject: Re: Cocoa Text System - Temporarily Disabling Layout
- From: Jonathan Dann <email@hidden>
- Date: Fri, 24 Sep 2010 10:50:01 +0200
On 23 Sep 2010, at 23:46, Martin Wierschin wrote:
>>> The problem I've had to continuously hack around is that NSTextView, in conjunction with NSLayoutManager, is rather eager to get the text to re-layout.
>>
>> Maybe, to disable layout, set the textview's textContainer to nil, then restore it to enable layout?
>
> That's one idea, though I wouldn't be surprised if other things go weird as a result.
>
> Personally I'd try to work with the text system in a way it expects. For example:
>
>>> when I resize the window and need to adjust the frames of both scroll views, calling -[NSTextView setFrame:] results in the layout manager invalidating and ensuring layout for the newly visible character range.
>
> Why not just turn off text view width/height tracking for the container during the resize? That should let the layout manager use the existing layout information (ie: for the stale container size).
Because that's just moving the problem further down the line. When I finally update the text container size for the first text view it will begin to layout before I've reached the next line of my code where I can fix the size of the second view.
The hacky fix for such things is to force the text views (or containers) to be the same size in the first call -[NSLayoutManager layoutParagraphAtPoint] or something thereabouts, but the underlying problem (the automatic layout) keeps rearing it's ugly head in other situations.
>
> The other "state change" you explicitly touch upon is editing the text. If you bracket all your changes to the text storage with begin/end editing calls, you shouldn't trigger layout until all your changes are finished (unless you're also inadvertently triggering layout in other ways).
I'll see how that fits in with setting the 2 strings that are dependent on each other. It may be a nice workaround.
>
> Are there any other scenarios where you trigger layout before you're ready?
Yeah I have line numbers views set up in all of this too, for which I have to set the width before I set the strings of the text views so you don't see the views resizing on first load if the line numbers aren't wide enough to accommodate the number of lines in the new string. Resizing the line numbers shrinks the available width for the text views and then everything lays out again.
It's, all in all, a very complex setup :)
Thanks,
Jonathan
_______________________________________________
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