Last active
December 22, 2015 12:38
-
-
Save amka/6473715 to your computer and use it in GitHub Desktop.
NSSplitView Delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define kSnapToDelta 8.0 | |
#define kMinSourceListWidth 150.0 | |
#define kSnapSourceListWidth 250.0 | |
#define kMinContentWidth 150.0 | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
#pragma mark - NSSplitView Delegate | |
- (void) splitView:(NSSplitView*) splitView resizeSubviewsWithOldSize:(NSSize) oldSize | |
{ | |
if (splitView == _splitView) | |
{ | |
CGFloat dividerPos = NSWidth([[[splitView subviews] objectAtIndex:0] frame]); | |
CGFloat width = NSWidth([splitView frame]); | |
if (dividerPos < kMinSourceListWidth) | |
dividerPos = kMinSourceListWidth; | |
if (width - dividerPos < kMinContentWidth + [splitView dividerThickness]) | |
dividerPos = width - (kMinContentWidth + [splitView dividerThickness]); | |
[splitView adjustSubviews]; | |
[splitView setPosition:dividerPos ofDividerAtIndex:0]; | |
} | |
} | |
- (CGFloat) splitView:(NSSplitView*) splitView constrainSplitPosition:(CGFloat) proposedPosition ofSubviewAt:(NSInteger) dividerIndex | |
{ | |
if (splitView == _splitView) | |
{ | |
CGFloat width = NSWidth([splitView frame]); | |
if (ABS(kSnapSourceListWidth - proposedPosition) <= kSnapToDelta) | |
proposedPosition = kSnapSourceListWidth; | |
if (proposedPosition < kMinSourceListWidth) | |
proposedPosition = kMinSourceListWidth; | |
if (width - proposedPosition < kMinContentWidth + [splitView dividerThickness]) | |
proposedPosition = width - (kMinContentWidth + [splitView dividerThickness]); | |
} | |
return proposedPosition; | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment