Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does an NSTextField leave artifacts over an NSTableView when the table scrolls?

I want to put a text label over a scroll table but the label conflicts with the drawing of the scrolling. Here you can see a test where I've intentionally put the label half out of the table and scroll up in the table, which results in the part of the label overlay being dragged below until it exits the window.

scrolling up breaks label overlay

Also, when I go to the other end of the table and scroll down, sometimes the label seems to be redrawn and chunks of it go up along with the scroll:

scrolling down is bad too

scrolling down is bad too

It seems that the table is redrawing its contents and does not notify the rest of the view objects to redraw themselves in case they are overlaid. How do I solve this? In fact, this seems highly related to How to place an NSButton over an NSTableView which seems to have the same problem but with a button instead of a label.

like image 938
Grzegorz Adam Hankiewicz Avatar asked Nov 06 '25 18:11

Grzegorz Adam Hankiewicz


2 Answers

Dont do that because you will lose a lot of performance and increase energy use.

Try the NSScrollView method - (void)addFloatingSubview:(NSView *)view forAxis:(NSEventGestureAxis)axis

like image 168
uchuugaka Avatar answered Nov 08 '25 19:11

uchuugaka


Another alternative way to get proper redrawing is to open the xib root view in the Effects Inspector, and mark it to use the Core Animation Layer. This avoids requiring to create a custom class with the redrawing hook.

like image 29
Grzegorz Adam Hankiewicz Avatar answered Nov 08 '25 21:11

Grzegorz Adam Hankiewicz