Skip to content

Commit

Permalink
Fix Issue jwilling#153 Wrong contentInsets when connected mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
m1entus committed Jan 12, 2016
1 parent aff16a6 commit 82be5a6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ static void JNWCollectionViewCommonInit(JNWCollectionView *collectionView) {

collectionView.backgroundColor = NSColor.whiteColor;
collectionView.drawsBackground = YES;

[[NSNotificationCenter defaultCenter] addObserver:collectionView selector:@selector(preferredScrollerStyleDidChangeNotification:) name:NSPreferredScrollerStyleDidChangeNotification object:nil];
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSPreferredScrollerStyleDidChangeNotification object:nil];
}

- (id)initWithFrame:(NSRect)frameRect {
Expand All @@ -131,9 +137,23 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
return self;
}

#pragma mark Notifications

- (void)preferredScrollerStyleDidChangeNotification:(NSNotification *)note {
NSView *documentView = self.documentView;

if (!CGSizeEqualToSize(NSSizeToCGSize(documentView.frame.size), NSSizeToCGSize(self.contentSize))) {
CGRect documentFrame = documentView.frame;
documentFrame.size.width = self.contentSize.width;
documentView.frame = documentFrame;

[self.collectionViewLayout invalidateLayout];
}
}

#pragma mark Delegate and data source

- (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
- (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
_delegate = delegate;
_collectionViewFlags.delegateMouseUp = [delegate respondsToSelector:@selector(collectionView:mouseUpInItemAtIndexPath:)];
_collectionViewFlags.delegateMouseDown = [delegate respondsToSelector:@selector(collectionView:mouseDownInItemAtIndexPath:)];
Expand Down

0 comments on commit 82be5a6

Please sign in to comment.