Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing height of NSSearchField

I currently have a standard NSSearchField (in a nib). The height is fixed by Apple at 22px. The application supports or uses Tibetan Unicode. Tibetan characters are written left to right, but certain adjacent characters stack vertically which makes for an unusually large line height. Text entered into the search field is clipped. My solution is to subclass NSSearchFieldCell and if necessarily NSSearchField.

First problem: It's hard to figure out what methods to override. I find hints in the Apple documentation but nothing systematic. Any pointers are appreciated.

What I have so far: I subclassed NSSearchFieldCell. I replaced searchTextRectForBounds, cancelButtonRectForBounds, searchButtonRectForBounds, and finally drawWithFrame inView.

I get a decent graphical image at the desired size. The cancel button is drawn in the expected location, but I have no idea where the cancel button controls are on the screen.

What other methods to I need to override?

To illustrate the problem, the following text ཀླུའི་རྒྱལ་པོ་

transliterated into Latin/Roman letters klu'i rgyal po in the search bar used by Finder. Notice the gigu "U" is clipped along the bottom.

standard search field in Finder with Tibetan Text

like image 425
Bill Avatar asked Apr 07 '14 03:04

Bill


2 Answers

I wouldn't go down that road at all. Instead you should subclass NSView and stick an NSTextField + NSPopUpButton + NSButton inside it.

With a bunch of hacking you'll get it working but then OS X 10.10 will ship and it will be broken.

like image 135
Abhi Beckert Avatar answered Oct 20 '22 08:10

Abhi Beckert


You need to make a custom NSSearchFieldCell subclass, and override drawWithFrame:, then set your NSSearchField to use that cell. You can either draw your custom border in code, or use end-cap images and a background image for the center that you tile horizontally. (I Haven't tried this)

Try that out.

Alternatively, just create a NSTextFeild, then update the view.

like image 37
MrHaze Avatar answered Oct 20 '22 09:10

MrHaze