-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue #153 Wrong contentInsets when connected mouse #157
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this still work if the collection view is resized after connecting a mouse? Could it be replaced by invalidating the layout first, then calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am iOS dev so i even didn't know about layoutDocumentView, in free time i will try replace it wigh layoutDocumentView, btw. cell frame are based on document view frame so anyway shouldn't invalidate layout be after layout document view? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently only setting the property to Overlay doesn't work, so glad you Thanks.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @m1entus Actually |
||
|
||
[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:)]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this library is 64-bit only, there's no need to bridge between
NSRect
andCGRect
. They can be used interchangeably. So it could just look like this:if (!CGSizeEqualToSize(documentView.frame.size, self.contentSize)) {