Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSView outside of NSWindow

I have an NSWindow and basically, what I am trying to pop up an NSWindow outside of the bounds of the NSWindow it's in every time a user hovers over the NSWindow.

But every time I try to do that, since the NSView is outside of the bounds of NSWindow it gets cut off.

Here's a picture of what I am trying to achieve: enter image description here

like image 775
0xSina Avatar asked Jan 17 '23 07:01

0xSina


2 Answers

You need to create a borderless NSWindow, large enough to contain your view, and make the window a child window of the main window it's attached to. To make a window a child of another window, you use the addChildWindow:ordered: method of NSWindow.

Child windows are attached to the parent window and will move with their parent window when the parent window moves. If you just open a new window without making it a child window, it will be "left behind" if the other window is moved.

To make a borderless window, pass NSBorderlessWindowMask as the styleMask to the initWithContentRect:styleMask:backing:defer: method of NSWindow.

like image 169
Rob Keniger Avatar answered Jan 25 '23 10:01

Rob Keniger


The easiest approach is to create another NSWindow with no border and put the button in that.

like image 27
Rob Napier Avatar answered Jan 25 '23 09:01

Rob Napier