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

Drag and drop #54

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions JNWCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
AB38E39017DF099A00D50B3C /* JNWScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB38E38C17DF099A00D50B3C /* JNWScrollView.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB38E39117DF099A00D50B3C /* JNWScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB38E38D17DF099A00D50B3C /* JNWScrollView.m */; };
AB39819D1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */; };
AB3A2E3C18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB3A2E3D18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */; };
AB3C71F4170CA8D3004A91DB /* JNWCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3C71E8170CA8D3004A91DB /* JNWCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB3C71F5170CA8D3004A91DB /* JNWCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB3C71E9170CA8D3004A91DB /* JNWCollectionView.m */; };
AB3C71F7170CA8D3004A91DB /* JNWCollectionView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */; };
Expand Down Expand Up @@ -144,6 +146,8 @@
AB38E38C17DF099A00D50B3C /* JNWScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWScrollView.h; path = external/JNWScrollView/JNWScrollView.h; sourceTree = SOURCE_ROOT; };
AB38E38D17DF099A00D50B3C /* JNWScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWScrollView.m; path = external/JNWScrollView/JNWScrollView.m; sourceTree = SOURCE_ROOT; };
AB39819C1731A1B50062B2E0 /* JNWCollectionViewReusableView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionViewReusableView+Private.h"; path = "JNWCollectionView/JNWCollectionViewReusableView+Private.h"; sourceTree = SOURCE_ROOT; };
AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionViewReorderableLayout.h; path = JNWCollectionView/JNWCollectionViewReorderableLayout.h; sourceTree = SOURCE_ROOT; };
AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionViewReorderableLayout.m; path = JNWCollectionView/JNWCollectionViewReorderableLayout.m; sourceTree = SOURCE_ROOT; };
AB3C71E8170CA8D3004A91DB /* JNWCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JNWCollectionView.h; path = JNWCollectionView/JNWCollectionView.h; sourceTree = SOURCE_ROOT; };
AB3C71E9170CA8D3004A91DB /* JNWCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JNWCollectionView.m; path = JNWCollectionView/JNWCollectionView.m; sourceTree = SOURCE_ROOT; };
AB3C71EA170CA8D3004A91DB /* JNWCollectionView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "JNWCollectionView+Private.h"; path = "JNWCollectionView/JNWCollectionView+Private.h"; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -243,6 +247,8 @@
AB1514731714D39600871248 /* JNWCollectionViewListLayout.m */,
AB1514801715361D00871248 /* JNWCollectionViewGridLayout.h */,
AB1514811715361D00871248 /* JNWCollectionViewGridLayout.m */,
AB3A2E3A18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h */,
AB3A2E3B18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m */,
);
name = Layouts;
sourceTree = "<group>";
Expand Down Expand Up @@ -379,6 +385,7 @@
AB1514821715361E00871248 /* JNWCollectionViewGridLayout.h in Headers */,
AB1514741714D39600871248 /* JNWCollectionViewListLayout.h in Headers */,
AB3C7202170CA8D3004A91DB /* NSIndexPath+JNWAdditions.h in Headers */,
AB3A2E3C18047D540066FBC6 /* JNWCollectionViewReorderableLayout.h in Headers */,
AB38E38E17DF099A00D50B3C /* JNWClipView.h in Headers */,
AB38E39017DF099A00D50B3C /* JNWScrollView.h in Headers */,
AB3C71F7170CA8D3004A91DB /* JNWCollectionView+Private.h in Headers */,
Expand Down Expand Up @@ -574,6 +581,7 @@
AB3C7203170CA8D3004A91DB /* NSIndexPath+JNWAdditions.m in Sources */,
AB38E39117DF099A00D50B3C /* JNWScrollView.m in Sources */,
AB1514701714C90800871248 /* JNWCollectionViewLayout.m in Sources */,
AB3A2E3D18047D540066FBC6 /* JNWCollectionViewReorderableLayout.m in Sources */,
AB1514751714D39600871248 /* JNWCollectionViewListLayout.m in Sources */,
AB1514831715361E00871248 /* JNWCollectionViewGridLayout.m in Sources */,
ABA276B3171D1C4B005C8E56 /* JNWCollectionViewDocumentView.m in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions JNWCollectionView/JNWCollectionViewGridLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
IN THE SOFTWARE.
*/

#import "JNWCollectionViewLayout.h"
#import <JNWCollectionView/JNWCollectionViewReorderableLayout.h>

// The supplementary view kind identifiers used for the header and the footer.
extern NSString * const JNWCollectionViewGridLayoutHeaderKind;
Expand All @@ -43,7 +43,7 @@ extern NSString * const JNWCollectionViewGridLayoutFooterKind;

// A layout subclass that displays items in an evenly spaced grid. All items
// have the same size, and are evenly spaced apart from each other.
@interface JNWCollectionViewGridLayout : JNWCollectionViewLayout
@interface JNWCollectionViewGridLayout : JNWCollectionViewReorderableLayout

// The delegate for the grid layout. The delegate, if needed, should be set before
// the collection view is reloaded.
Expand Down
4 changes: 2 additions & 2 deletions JNWCollectionView/JNWCollectionViewListLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
IN THE SOFTWARE.
*/

#import "JNWCollectionViewLayout.h"
#import <JNWCollectionView/JNWCollectionViewReorderableLayout.h>

// The supplementary view kind identifiers used for the header and the footer.
extern NSString * const JNWCollectionViewListLayoutHeaderKind;
Expand All @@ -44,7 +44,7 @@ extern NSString * const JNWCollectionViewListLayoutFooterKind;

// A layout subclass that displays items in a vertical list with rows of
// items, similar to a table view.
@interface JNWCollectionViewListLayout : JNWCollectionViewLayout
@interface JNWCollectionViewListLayout : JNWCollectionViewReorderableLayout

// The delegate for the list layout. The delegate, if needed, should be set before
// the collection view is reloaded.
Expand Down
54 changes: 54 additions & 0 deletions JNWCollectionView/JNWCollectionViewReorderableLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright (c) 2013, Jonathan Willing. All rights reserved.
Licensed under the MIT license <http://opensource.org/licenses/MIT>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/

#import <JNWCollectionView/JNWCollectionViewLayout.h>

typedef NS_ENUM(NSInteger, JNWReorderingType) {
JNWReorderingTypeDisplacement,
JNWReorderingTypeMarker
};

@interface JNWCollectionViewReorderableLayout : JNWCollectionViewLayout

// Determines how the layout should handle reordering.
//
// Reordering by displacement (JNWReorderingTypeDisplacement) occurs by
// determining which cell is closest to the item that is being dragged
// within the bounds of the collection view, and swapping its position
// with that of the nearby item.
//
// Reordering by marker (JNWReorderingTypeMarker) occurs by drawing a
// marker to indicate the proposed drop position. The position of the marker
// is determined by the frame returned from -markerRect.
//
// Defaults to JNWReorderingTypeDisplacement.
@property (nonatomic, assign) JNWReorderingType reorderingType;

// The rect in which the drop marker should be placed. This is only utilized
// if the reorderingType is JNWReorderingTypeMarker.
//
// Specified relative the scroll view, not the visible frame.
//
// Defaults to CGRectZero.
- (CGRect)markerRect;

// The fill color of the marker.
- (NSColor *)markerColor;

@end
24 changes: 24 additions & 0 deletions JNWCollectionView/JNWCollectionViewReorderableLayout.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (c) 2013, Jonathan Willing. All rights reserved.
Licensed under the MIT license <http://opensource.org/licenses/MIT>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/

#import "JNWCollectionViewReorderableLayout.h"

@implementation JNWCollectionViewReorderableLayout

@end