Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers-mac/NSView+embed.m @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #import "NSView+embed.h" | |
| 2 | |
| 3 #if 0 | |
| 4 @implementation NSView (embed) | |
| 5 | |
| 6 - (void)embedInView:(NSView *)superview { | |
| 7 NSViewEmbed( superview, self ); | |
| 8 } | |
| 9 - (void)embedInViewV2:(NSView *)superview { | |
| 10 NSViewEmbedConstraints( superview, self ); | |
| 11 } | |
| 12 | |
| 13 @end | |
| 14 #endif | |
| 15 | |
| 16 void NSViewEmbed( NSView * superview, NSView * childview ) { | |
| 17 if ( childview == nil || superview == nil ) return; | |
| 18 childview.autoresizingMask = NSViewHeightSizable | NSViewWidthSizable; | |
| 19 childview.frame = superview.bounds; | |
| 20 [superview addSubview: childview]; | |
| 21 } | |
| 22 | |
| 23 void NSViewEmbedConstraints( NSView * superview, NSView * childview ) { | |
| 24 if ( childview == nil || superview == nil ) return; | |
| 25 childview.autoresizingMask = 0; | |
| 26 [superview addSubview: childview]; | |
| 27 NSMutableArray <NSLayoutConstraint * > * constraints = [NSMutableArray arrayWithCapacity: 4]; | |
| 28 static const NSLayoutAttribute params[4] = { NSLayoutAttributeLeft, NSLayoutAttributeRight, NSLayoutAttributeTop, NSLayoutAttributeBottom }; | |
| 29 for( unsigned i = 0; i < 4; ++ i) { | |
| 30 NSLayoutAttribute a = params[i]; | |
| 31 [constraints addObject: [NSLayoutConstraint constraintWithItem: childview attribute:a relatedBy:NSLayoutRelationEqual toItem:superview attribute:a multiplier:1 constant:0]]; | |
| 32 } | |
| 33 | |
| 34 [superview addConstraints: constraints]; | |
| 35 } |
