I have one line in my UI, that consists of fixed-sized string (FS), fixed-sized image and variable-sized string (VS). I need this line to be centered in its superview, possibly truncating the VS if it no longer fits in. Just like simple centered NSTextField with truncate enabled would do. But NSTextField can't hold an NSImage AFAIK.
I suppose NSStackView should be able to do this. I have set it up to be centered in its superview and have an NSTextField, NSImage and NSTextField inside. But when I set VS to something very long, both FS and VS are pushed out of superview bounds and clipped.
Is there a way to tell NSStackView to never move FS out of superview bounds and rather truncate VS? Or is there any other technique to achieve my goal?
What I have tried so far:
- Use NSStackView and set compressionResistance to 499 on the VS - no effect
Use NSTextView - could not make it truncate text and fit on single line. Also seems like an overkill
Use NSView - it requires me to set x-position so it is not properly centered.
I could use NSView and calculate sizes of the strings and modify constraints to make this work. But I think there must be a better way.
Thanks for any ideas,
J.