Now I want to be able to calculate the optimal width of the view so that the entire text is visible.

This worked wonders for me:

http://www.cocoabuilder.com/archive/message/cocoa/2008/3/31/202752

This also does not solve my problem.
Getting the height of a text for a given width is easy and I've done that countless times. Also getting the width of a string (layed out in one line if it has no newlines) is no problem.

But I have a different problem. I try to give an easier explanation of my problem:

I have a text view that has a height that can hold three lines of text. Now I have one long string (without newlines). When putting this string into the text view, the text is automatically wrapped around. But maybe - for the initial width of the view - it will need four (or more) lines instead of just three. Now I want to calculate the optimal (minimum) width of the text view, to that the string is wrapped around in just three (or less) lines.

In the meantime I guess I have the solution. I don't think that there is really a way in Cocoa or Quartz that solves this problem. So I really have to "try" different widths, let the layout manager layout the text and see how much lines it needs. So I can do a "binary search" to get an ideal width. Even if Cocoa or Quartz would have a method for calculating the width, it would internally also have to do such a binary search. I don't think that it's possible to calculate the perfect width in one step.
So I just do it myself and it works quite well.

Thanks for your attention,
Mani

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to