• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Repositioning an NSTextFieldCell?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Repositioning an NSTextFieldCell?


  • Subject: Re: Repositioning an NSTextFieldCell?
  • From: Daniel Jalkut <email@hidden>
  • Date: Sat, 25 Nov 2006 12:10:57 -0500

Hi Matt - I am not sure if my way is the best way or not. The way it works is essentially the same as your idea of overriding drawInteriorWithFrame, except that instead of overriding that method, I'm overriding one that is known to be called by the superclass when implementing that (drawingRectForBounds:). This has the benefit of also propagating the desired location change to the field editor and selection mechanisms.

THAT said, I have discovered some nuanced bugs with NSTextFieldCell, where it doesn't always seem to call drawingRectForBounds:. In particular if the NSTextFieldCell is configured to draw its background, it never seems to call the method, and instead just figures it out on its own. What a drag. For those instances, I discovered that if I take advantage of a private NSTextFieldCell method, "_setVerticallyCentered:", then it figures it out on its own to my liking.

So now (I haven't updated the version on my blog) I've got an initTextCell: method that makes an effort to let AppKit know what I want:

// this private method is required for rendering in the center when the
// cell has a custom background color ... go figure. Apple's weird.
if ([self respondsToSelector:@selector(_setVerticallyCentered:)] == YES)
{
	[self _setVerticallyCentered:YES];
}

So I guess my final question is ... in the example case you were trying to test against, did the NSTextField happen to be configured to draw its background? That would explain the failing :(

Daniel

On Nov 25, 2006, at 11:30 AM, Matt Neuburg wrote:

On Fri, 24 Nov 2006 17:46:15 -0500, Daniel Jalkut <jalkut@red- sweater.com>
said:
Take a look at my vertically centered text cell subclass:

http://www.red-sweater.com/blog/148/what-a-difference-a-cell-makes

That should be easily modifiable to achieve the result you're looking
for.

I'm sure that works great in, say, a table, but I'm not seeing how it works
for the place where I want to use a vertically centered text field cell -
namely, in an actual NSTextField. In my testing, the text is not vertically
centered, but the field editor is (so they are in two different places - in
fact, if the text field is tall enough, I can see both at the same time,
because the field editor fails to cover the text field's text). Am I missing
some key point here? I could, for example, be misusing the cell (i.e. the
way I'm substituting the vertically centered cell for the NSTextField's cell
as it comes out the nib might be wrong).


In my experience, relocating the text of an NSTextField requires its cell's
drawInteriorWithFrame to be overridden. (Your class doesn't do that.) But
again, I could be completely wrong; that's what I've been doing, and it
works for me, but if your class is showing me a better way, I'd like to
understand it.


Thx - m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Repositioning an NSTextFieldCell?
      • From: Matt Neuburg <email@hidden>
References: 
 >Re: Repositioning an NSTextFieldCell? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Debugging an ignored exception
  • Next by Date: Re: Debugging an ignored exception
  • Previous by thread: Re: Repositioning an NSTextFieldCell?
  • Next by thread: Re: Repositioning an NSTextFieldCell?
  • Index(es):
    • Date
    • Thread