2

NSStackView has 2 additional priorities compared to a regular NSView, namely clippingResistancePriority and huggingPriority. The documentation provides a somewhat reasonable explanation what they're for and what they do.

But 4 priorities is a bit overkill.

Now, in said documentation they mention:

A stack view has no intrinsic content size and does not have a configurable content compression resistance. Calling the setContentCompressionResistancePriority:forOrientation: method on a stack view has no effect.

However, contentHuggingPriority is left in the shadows. It seems like NSStackView doesn't react to this one as well - or at least I wasn't able to make it do.

Could anybody please confirm or disprove this?

Alexander N.
  • 564
  • 3
  • 10

1 Answers1

3

Yes, this is correct. The inherited content constraint priorities from NSView:

- (NSLayoutPriority)contentHuggingPriorityForOrientation:(NSLayoutConstraintOrientation)orientation NS_AVAILABLE_MAC(10_7); - (NSLayoutPriority)contentCompressionResistancePriorityForOrientation:(NSLayoutConstraintOrientation)orientation NS_AVAILABLE_MAC(10_7);

only apply to the constraints created based on the view's intrinsicContentSize, which NSStackView does not have. So like you and the documentation mention, they have no effect. (unless you subclass NSStackView and override intrinsicContentSize to give it some value...)

Taylor
  • 3,183
  • 17
  • 18
  • Thanks. Hey, while we're at it, maybe you could help clarify smth else about `NSStackView`s? Like this piece of documentation: "To allow view clipping, set a clipping resistance lower than the default value of `NSLayoutPriorityRequired` and set the visibility priority of all the stack view’s views to `NSStackViewVisibilityPriorityMustHold`". This is not true at all. For me the stack view only starts clipping and hiding subviews when clipping resistance is <500. Maybe you have some insights about things like this and where (apart from wwdc, ugh) they can be clarified? – Alexander N. Sep 08 '16 at 19:07
  • That clipping resistance priority plays into the rest of the priorities of constraints in the window. So you're right that it's not strictly true that all it takes is < Required, but it's that point when it becomes possible to clip and then just depends on the priorities of the other constraints the stack view is interacting with. The 500 # makes it sounds like your stack view is being sized against the size of the window since the DragThatCanResizeWindow priority is 510 and WindowSizeStayPut is 500. – Taylor Sep 29 '16 at 04:32
  • The auto layout guide goes into priorities a bit (but not the macOS specific ones): https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#//apple_ref/doc/uid/TP40010853-CH9-SW19 . The various NSLayoutPriority constants also have header comments describing their values and semantic meanings – Taylor Sep 29 '16 at 04:36