Re: NSTableColumn width computation doesn't work correctly on macOS 11
Re: NSTableColumn width computation doesn't work correctly on macOS 11
- Subject: Re: NSTableColumn width computation doesn't work correctly on macOS 11
- From: Rob Petrovec via Cocoa-dev <email@hidden>
- Date: Fri, 25 Jun 2021 12:16:48 -0600
You are using deprecated cell based table views/API. I would advise switching
to view based API (available in macOS 10.7 and newer). Cell based was
deprecated in 10.10 back in 2014.
With that said, I would create an NSTextFieldCell subclass (if you haven’t
already) and stuff it into the text field for the row being truncated. Then
override:
- (NSSize)cellSizeForBounds:(NSRect)rect;
- (NSRect)imageRectForBounds:(NSRect)rect;
- (NSRect)titleRectForBounds:(NSRect)rect;
and see what they return on 10.13 & 11. -cellSize calls -cellSizeForBounds:
which calls the other two methods to calculate the ideal size of the text field
(including measuring width of the text). Maybe that will give you some
insight. Good luck.
—Rob
> On Jun 25, 2021, at 8:22 AM, Andreas Falkenhahn via Cocoa-dev
> <email@hidden> wrote:
>
> I'm manually calculating the minimum size of my NSTableColumn to avoid text
> ellipsization. The calculation looks like this:
>
> NSCell *cell = [m_view preparedCellAtColumn:m_column row:row];
>
> int width = ceil([cell cellSize].width);
>
> if(m_column == [m_view outlineTableColumn]) {
> width += [m_view indentationPerLevel] * [m_view levelForRow:row];
> width += m_expander;
> }
>
> The m_expander value is calculated like this:
>
> // assume that row 0 has an expander
> NSRect rc = [m_view frameOfOutlineCellAtRow:0];
> m_expander = ceil(rc.origin.x + rc.size.width);
>
> This works nicely on 10.13. See here: https://imgur.com/w8uT4gu
>
> On macOS 11, however, the calculation is not correct and the text gets
> ellipsized, see here: https://imgur.com/HiOBVjh
>
> Debugging has shown that m_expander is missing 4 pixels on macOS 11. On macOS
> 10.13 rc.origin.x is 6 and rc.size.width is 12. On macOS 11, rc.origin.x is 2
> and rc.size.width is 12. However, this seems to be correct because you can
> see that the space to the left of the expander is smaller on macOS 11 than on
> macOS 10.13 so the values look correct. All other values are identical
> between 10.13 and 11. The column width computed by 10.13 is 169 and the
> column width computed by macOS 11 is 165.
>
> Still, as you can see, the overall column width calculation is not correct on
> macOS 11 because the text gets ellipsized. Anybody got an idea what the
> problem here is?
>
> --
> Best regards,
> Andreas Falkenhahn mailto:email@hidden
>
> _______________________________________________
>
> 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
_______________________________________________
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