Re: how can one programmatically check if text fits in cells and text-views?
Re: how can one programmatically check if text fits in cells and text-views?
- Subject: Re: how can one programmatically check if text fits in cells and text-views?
- From: Mike Morton <email@hidden>
- Date: Fri, 26 Aug 2005 12:58:26 -0400
All --
FYI, I never found a good, general way to do this.
For most NSControls, I was able to compare the sizes of [[theControll
cell] cellSize] with [aControl bounds]. But this gave flaky results for
certain types of buttons, and didn’t work at all for wrapping
NSTextFields.
In the end, I added a panel which displays the text the mouse is over,
and our QA folks look at that to see if the displayed text is subtly
clipped. Much less work, and everyone’s happy.
-- Mike
Begin forwarded message:
From: Mike Morton <email@hidden>
Date: August 15, 2005 4:16:22 PM EDT
To: Cocoa-Dev <email@hidden>
Subject: how can one programmatically check if text fits in cells and
text-views?
Folks --
If you localize nibs by extracting text and translating out of
context, it’s hard to detect when the translated text no longer fits.
(And even if you translate by working in IB, you may not notice
problems with text which your app constructs on the fly.)
I’d like to have the debugging version of an app check for clipped
text in text fields and buttons (more generally, any cell) and in
NSTextViews.
Text-views are probably easy -- if it’s not in a scroll-view, set it
to be resizable only vertically, then send sizeToFit and check that it
didn’t grow.
Cells are trickier. For a non-wrapping cell, I hope you can just
measure the text with NSFont’s widthOfString: and ensure that that’s
less than the width of the cell’s titleRectForBounds:. But when I’ve
done stuff like that in the past, it’s often been off by a pixel or
two — maybe I did something dumb. And for a text field which wraps,
how can you check if the text fits?
As is probably clear, I haven’t begun work on this, and would welcome
any suggestions.
Thanks in advance,
-- Mike _______________________________________________
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