How can you get an NSButton to detach from an NSStackView when the stack view resizes?

841 views Asked by At

How can you get an NSButton to detach from an NSStackView when the stack view resizes?

NSControl subclasses that use NSCell drawing seem to have a different mind than other NSView subclasses on visibility with compression resistance in Auto Layout. NSStackView doesn't seem to make a difference here either.

If I set the Visibility Priority for a control higher than 1, it will not drop. If I set it to 0, well, of course it will only drop and never appear.

How is this supposed to work?
What does it take to get a button or other control to drop when the stack view is resized smaller?
Maybe it's the dearth of docs and examples of NSStackView...

2

There are 2 answers

1
s4y On BEST ANSWER

Before I saw any views detach, I had to do two things:

  1. Call -[NSStackView setClippingResistancePriority:forOrientation:]. If the size of the stack view is tied to the size of the window, the priority needs to be less than NSLayoutPriorityWindowSizeStayPut (500) or the stack view doesn't allow the window to get smaller than its content.

  2. Each time I added a view to the stack view that I wanted to detach, call -[NSStackView setVisibilityPriority:forView:] for that view.

1
Wil Shipley On

Try setting the priority to NSStackViewVisibilityPriorityDetachOnlyIfNecessary?