Re: Tables created in code have different row height from those created in IB
Re: Tables created in code have different row height from those created in IB
- Subject: Re: Tables created in code have different row height from those created in IB
- From: Corbin Dunn <email@hidden>
- Date: Wed, 22 Mar 2006 13:23:53 -0800
Peter,
So if your application:
1. Is developed on 10.4
Just to note: it isn't what it is developed on, but what it is linked
against. Since you want it to run on 10.3, you will probably link
against that SDK version.
2. Creates an NSTable using [[NSTableView alloc] init]
3. Needs to run and look good/native on 10.3, 10.4 and Leopard
then:
1. You always call [table setFont:[NSFont systemFontOfSize:[NSFont
systemFontSize]]] to get the right font and font size.
Sounds good! This is what the default setup is for the NSTextFieldCell
dataCell created for an init'ed NSTableColumn (on Tiger) -- so you
probably meant [[table tableColumn] dataCell] setFont...
2. What recipe do you follow to get the right row height for the
table?
So, I dug through IB's source to really see what they do. They do
something similar to this (slightly modified to be simple):
NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSFont
systemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
NSSize defaultTextSize = [@"" sizeWithAttributes:attr];
// [table setRowHeight:defaultTextSize.height];
NSLog(@"%f", defaultTextSize.height);
This is the recipe you should follow. As I mentioned before, I'll
consider changing the default for Leopard linked apps. The above
returns 17 on Tiger and later. It should return 16 for Panther, but
please double check that.
Thanks!
--corbin
On 3/21/06, Aki Inoue <email@hidden> wrote:
The default line height is affected by the typesetter behavior.
-[NSLayoutManager defaultLineHeightForFont:] would return the correct
value (this case 17) by using
NSTypesetterBehavior_10_2_WithCompatibility.
If the default row height in Panther is 16 and is 17 in Tiger, why do
I need to set the typsetter behavior to
NSTypesetterBehavior_10_2_WithCompatibility to get the proper Tiger
value?
I tried NSTypesetterBehavior_10_2 and NSTypesetterBehavior_10_3 and
they both return 16.
-peter
On 3/22/06, Corbin Dunn <email@hidden> wrote:
On Mar 21, 2006, at 6:48 PM, Greg Herlihy wrote:
Actually, Interface Builder does adjust the height of an
NSTableView's rows
to match the table's font. For example selecting a table, choosing
Format->Font->Smaller changes both the table's font size (from 13 to
12) and
reduces the height of its rows (from 17 to 16).
Yes, I realize this -- (generally) all IB inspectors will change
properties of their corresponding controls. However, tableview itself
will not dynamically change its set rowHeight if you change the font.
Mainly because doing so is ambiguous; one could have one particular
font in one tablecolumn, and a different font in another.
The size of the default font for a table (more precisely, the font
size of
of NSTableColumn's default cell) changed between Panther and Tiger.
For apps
linking against Panther or earlier the default font is Lucida Grande
12, for
Tiger-linked apps the default font is Lucida Grande 13. The default
height
for the former is 16 and for the latter, 17.
This change may help explain the apparent discrepancy.
Yes...this is true! The unfortunate thing is that some people may be
depending on the default row height to be 16. For example, they may
code a tablecolumn that has a font size of 12, which looks okay
with a
row height of 16, and don't worry about resetting the row height
because of that. I'll consider making this change for Leopard linked
apps. Ideally, this sort of change should have happened for
Tiger..but
unfortunately, it did not.
Thank you everyone for the feedback! I appreciate it.
--corbin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden