NSWindow and text smoothing in NSTableView cell view

I am writing an OS X application and have a problem with font smoothing in a separate window.

I have a text box in which you put a text box and a tooltip in which a list of suggestions appears according to what you wrote. I use a View-cell-based NSTableView to display these suggestions and the SFBPopoverWindowController to display it as a pop-up window (tried other classes with the same effect). When the lines are first drawn, they look great, but after I select them (keyboard or mouse), the font changes its weight. This is only visual - how would you change the anti-aliasing method to a font, not a bold font.

Font smoothing problem within cell

"Musical note" is the selected cell here.

Which is even more strange, since after I hide and show the window 3 times, everything works fine from this point.

Font smoothing problem after showing the window 3 times

Again - "Musical Note" is the selected cell.

The selection is done by overwriting the NSTableRowView class and its drawSelectionInRect: method, but I tried to draw everything inside the custom NSTableCellView class, and that didn't help. The text is standard NSTextField - nothing has changed there.

SFBPopoverWindow (and its controller) are created once and reused with styleMask NSBorderlessWindowMask , supporting NSBackingStoreBuffered , defer installation to YES . The only change I made to the SFBPopoverWindowController to disable the window, becoming a key window, but it does not change anything.

+4
source share
1 answer

This may be due to the way the table view draws the selected cells ( setSelectionHightLightStyle: . Try setting the style to None / NSTableViewSelectionHighlightStyleNone in your code or in the IB / Storyboard file and draw the selection yourself (in a subclass of NSTableRowView ).

Reference Information. When you use NSTableViewSelectionHighlightStyleRegular or NSTableViewSelectionHighlightStyleSourceList , the table view assumes that you are using standard behavior and selection appearance and some kind of magic supports this.

===========

UPDATE

===========

My previous answer is still valid, but since it describes the problem and suggests a workaround, I would like to add a real solution. If you want to use NSTableViewSelectionHighlightStyleRegular for your type of table (with a custom font and colors), you need a way to "disable" the system magic that will be inserted after the row is selected. One proposed solution is to reject the status of the first responder . It has many shortcomings and is not at all a good solution.

So, let's take a closer look at the system β€œmagic” that fires as soon as a line is selected: NSTableRowView has an innerBackgroundStyle property, which, according to the documentation, indicates how the subitems should draw. ”In addition, this value is dynamically calculated based on the set properties set for NSTableRowView. Subclasses can override this value when they draw differently depending on the properties currently displayed. This method can also be called to determine which color should be used. Call a subview, or, alternatively, NSControls may have a -backgroundStyle value in their cell for that value. '

I assume that this style will be passed to the subview hierarchy and make your text fields look weird. The system assumes that the selected cell has a dark background and changes the interiorBackgroundStyle to dark. Other controls are trying to adapt accordingly.

I think there are two problems:

1) Override interiorBackgroundStyle in a subclass of NSTableRowView and return the style that matches your interface (in my case it is .light , because my highlight color is very bright blue). It worked for me.

2) If you change the whole style too much because you want certain elements to not change their style, you may only need to adjust these subclasses. I have not tried it yet.

+2
source

All Articles