How can I get horizontal scrollbars adequate to the widest list entry
How can I get horizontal scrollbars adequate to the widest list entry
- Subject: How can I get horizontal scrollbars adequate to the widest list entry
- From: Andreas Falkenhahn via Cocoa-dev <email@hidden>
- Date: Wed, 11 Nov 2020 15:54:02 +0100
I have a simple one-column NSTableView full of text. When I add very long lines
to it, the text that doesn't fit into the column gets cut off and replaced by
"...". I don't want that. Instead, I want to have a horizontal scrollbar that
allows the user to view the complete list entry.
Sounds simple enough but turns out to be much more complicated than I thought.
To my surprise, there doesn't seem to be any way to just tell the NSTableColumn
to be as wide as its largest entry. So I had the idea of just keeping track of
the widest entry and updating the NSTableColumn whenever a wider entry is
inserted.
To do that, on insertion of a new entry, I'm calculating entry lengths like
this:
NSCell *cell = [tableView preparedCellAtColumn:0 row:idx];
NSSize size = [cell cellSize];
Then I compare it against the previously widest entry and update the
NSTableColumn width if necessary, like so:
if(size.width > widestWidth) {
[tableColumn setWidth:size.width];
widestWidth = size.width;
}
However, this still isn't perfect because the last two characters of the widest
entry are still cut off and replaced by "...". Of course, I can solve this by
just adding something a few points to size.width but of course I don't want
that because I'm looking for a solution that works with all UI fonts and sizes
so hard-coding a certain point value that is added to size.width is definitely
a no-go...
Any hints on how to proceed from here? Thanks!
--
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