Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))) {
Copy link
Owner

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 and CGRect. They can be used interchangeably. So it could just look like this:

if (!CGSizeEqualToSize(documentView.frame.size, self.contentSize)) {

CGRect documentFrame = documentView.frame;
documentFrame.size.width = self.contentSize.width;
documentView.frame = documentFrame;
Copy link
Owner

Choose a reason for hiding this comment

The 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 layoutDocumentView?

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link

Choose a reason for hiding this comment

The 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
found a better solution. Will try this tonight and will tell you tomorrow
if everything's alright in my side.

Thanks.
On Wed, 13 Jan 2016 at 08:10, Michał Zaborowski [email protected]
wrote:

In JNWCollectionView/JNWCollectionViewFramework.m
#157 (comment)
:

@@ -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;
    

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?


Reply to this email directly or view it on GitHub
https://github.com/jwilling/JNWCollectionView/pull/157/files#r49557321.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1entus Actually -layoutDocumentView is just a method I made that updates the document view frame based on the size calculated in the layout. You'd want to recalculate the layout before updating the document view frame.


[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