Re: How does NSButtonCell do its drawing?
Re: How does NSButtonCell do its drawing?
- Subject: Re: How does NSButtonCell do its drawing?
- From: Ricky Sharp <email@hidden>
- Date: Fri, 1 Feb 2008 11:46:16 -0600
On Feb 1, 2008, at 6:33 AM, RICKY SHARP wrote:
On Friday, February 01, 2008, at 05:01AM, "Uli Kusterer" <email@hidden
> wrote:
On 21.01.2008, at 20:15, Ricky Sharp wrote:
For me, it was as simple as using NSAttributedString instances,
sending a "size" message to get the NSSize and then exactly
centering a box of that width/height within my cell's bounds. Then,
I just use drawInRect: to do the rendering.
Thanks for the answer, sorry for the delay.
I'm doing something similar for one-line text. The trouble is, I'd
like to be able to also correctly measure wrapped multi-line text. I
was hoping that there was a way to just create and cache the text
system objects and measure those. The -size method is good for un-
wrapped text, but of course creates and tears down its text system
objects every time, which I was hoping to be able to avoid, as this
text is going to be moved around a lot.
Ahh, I should have also posted what I do for multi-line rendering
too. I'll write in when I get home this afternoon. Anyhow, my text
rendering allows me to do any of the three text alignments along
with either single-line or multi-line text.
Actually, for my button text rendering, it's the same process; I still
use NSAttributedString's size method. Whenever I need multi-line text
on a button, I just enter in a "soft" return in the button's title
(i.e. option-Return within IB).
I do have a "static text" widget which does render things differently
for multi-line. Although, all I do there is simply call drawInRect:.
I don't pre-measure anything to see how things will fit and thus the
text could be truncated. But, for my needs, I always just sized the
control width-wise in IB and then hit my custom palettes/plug-in's
'size to fit' button which then took care of setting an appropriate
vertical height. For this particular control, I never do any vertical
alignment.
So, my approach, unfortunately doesn't give you something for wrapped
text such that the text doesn't contain arbitrary line breaks.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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