Skip to content

Instantly share code, notes, and snippets.

@amka
Last active December 22, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amka/6473715 to your computer and use it in GitHub Desktop.
Save amka/6473715 to your computer and use it in GitHub Desktop.
NSSplitView Delegate
#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