Re: Intelligently resizing table columns
Re: Intelligently resizing table columns
- Subject: Re: Intelligently resizing table columns
- From: Brian Webster <email@hidden>
- Date: Wed, 27 Mar 2002 09:08:43 -0600
On Wednesday, March 27, 2002, at 07:57 AM, cocoa-dev-
email@hidden wrote:
I know that this is (most likely) a pain to answer, but I also
know that
there are a lot of really smart people on this list. What would
be a fast
way of doing the resize that I want to do?
Well, getting the best performance for this will depend on a few
factors, such as:
- how often does this resize have to be performed? Are new rows
added/removed frequently? Are new columns added/removed
frequently?
- are you using only one font, or might there be a user choice of font?
Depending on the above, some things you might do include:
- using a monospaced font, which would cut down on the string
width calculation time
- keeping track of what the longest string in each column is, or
possibly keeping a sorted copy of each column by length,
depending on how much memory you want to use. That way, each
time a new string comes along, you can just compare it to the
longest string so far and resize only if it's longer.
One thing I can say is that -[NSString sizeWithAttributes:]
isn't the speediest method in the world. You'll probably want
to use NSLayoutManager to do the calculations, or if you can use
a monospaced font, just use -[NSFont maximumAdvancement]
multiplied by the string's length. You could even do that with
a non-monospaced font, if you don't mind a little extra padding.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.