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

Leading view #27

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
63 changes: 51 additions & 12 deletions CollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -82,6 +82,7 @@
DE13C18A1E4CE46100CEC80C /* ManagedObjectContextObservationCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedObjectContextObservationCoordinator.swift; sourceTree = "<group>"; };
DE1EE9A42072B00B00B76FE2 /* CollapsableCollectionViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsableCollectionViewProvider.swift; sourceTree = "<group>"; };
DE297DDF1E6A8B5400AAFC2A /* SupplementaryViewIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupplementaryViewIdentifier.swift; sourceTree = "<group>"; };
DE331AE62ACB313400CB3D6E /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
DE35BE1E20376FCC008FEF6F /* SortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortDescriptor.swift; sourceTree = "<group>"; };
DE3E47551E4259B800F19D9E /* EditDistance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditDistance.swift; sourceTree = "<group>"; };
DE46308D2044C114001AF02E /* WagnerFischer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WagnerFischer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -148,6 +149,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
DE331AE52ACB313400CB3D6E /* Frameworks */ = {
isa = PBXGroup;
children = (
DE331AE62ACB313400CB3D6E /* Metal.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
DE4630892044C114001AF02E /* DataStructures */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -219,6 +228,7 @@
DE9071EB1CAC7FD800AD0E37 /* CollectionView */,
DEA638AF200874950023F2BD /* CollectionViewTests */,
DE9071EA1CAC7FD800AD0E37 /* Products */,
DE331AE52ACB313400CB3D6E /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -333,7 +343,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1310;
LastUpgradeCheck = 1420;
ORGANIZATIONNAME = "Noun Project";
TargetAttributes = {
DE9071E81CAC7FD800AD0E37 = {
Expand Down Expand Up @@ -387,6 +397,7 @@
/* Begin PBXShellScriptBuildPhase section */
1CB6A657211D6BAC00907CEF /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -510,6 +521,7 @@
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -568,6 +580,7 @@
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -597,6 +610,7 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -606,8 +620,13 @@
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = CollectionView/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = thenounproject.CollectionView;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -625,6 +644,7 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -634,13 +654,19 @@
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = CollectionView/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = thenounproject.CollectionView;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
};
name = Release;
Expand All @@ -653,13 +679,19 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = CollectionViewTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_BUNDLE_IDENTIFIER = com.thenounproject.CollectionViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
Expand All @@ -676,16 +708,23 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEAD_CODE_STRIPPING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_OPTIMIZATION_LEVEL = s;
INFOPLIST_FILE = CollectionViewTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
PRODUCT_BUNDLE_IDENTIFIER = com.thenounproject.CollectionViewTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 4.2;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
37 changes: 16 additions & 21 deletions CollectionView/CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,24 @@ open class CollectionView: ScrollView, NSDraggingSource {
self.layer?.backgroundColor = self.drawsBackground ? self.backgroundColor.cgColor : nil
}

@available(*, deprecated, message: "Use a leading supplementary view instead")
public var leadingView: NSView? {
didSet {
if oldValue == leadingView { return }
oldValue?.removeFromSuperview()
self.needsLayoutReload = true
self.needsLayout = true
if let v = leadingView {
self.contentDocumentView.addSubview(v)

self.contentDocumentView.addConstraints([
NSLayoutConstraint(item: self.contentDocumentView, attribute: .left, relatedBy: .equal,
toItem: v, attribute: .left, multiplier: 1, constant: 0),
NSLayoutConstraint(item: self.contentDocumentView, attribute: .top, relatedBy: .equal,
toItem: v, attribute: .top, multiplier: 1, constant: 0),
NSLayoutConstraint(item: self.contentDocumentView, attribute: .right, relatedBy: .equal,
toItem: v, attribute: .right, multiplier: 1, constant: 0)
// NSLayoutConstraint(item: self.contentDocumentView.contentView, attribute: .top, relatedBy: .equal,
// toItem: v, attribute: .bottom, multiplier: 1, constant: 0)
])
v.translatesAutoresizingMaskIntoConstraints = false
v.setContentHuggingPriority(NSLayoutConstraint.Priority(rawValue: 1000), for: .vertical)
Expand Down Expand Up @@ -389,7 +393,7 @@ open class CollectionView: ScrollView, NSDraggingSource {
/// The layout used to organize the collected view’s items.
///
/// - Note: Assigning a new layout object to this property does **NOT** apply the layout to the collection view. Call `reloadData()` or `reloadLayout(_:)` to do so.
public var collectionViewLayout: CollectionViewLayout = CollectionViewLayout() {
public var collectionViewLayout: CollectionViewLayout = CollectionViewListLayout() {
didSet {
collectionViewLayout.collectionView = self
self.hasHorizontalScroller = collectionViewLayout.scrollDirection == .horizontal
Expand Down Expand Up @@ -520,17 +524,13 @@ open class CollectionView: ScrollView, NSDraggingSource {
self.reloadLayout(animated, scrollPosition: .none, completion: nil)
}
}

}

open override func layout() {
self._floatingSupplementaryView.frame = self.bounds
// self.layoutLeadingViews()

super.layout()
if needsLayoutReload || self.collectionViewLayout.shouldInvalidateLayout(forBoundsChange: self.contentVisibleRect) {

setContentViewSize()

prepareLayout(reloadData: reloadDataOnBoundsChange)
setContentViewSize()

Expand Down Expand Up @@ -581,14 +581,6 @@ open class CollectionView: ScrollView, NSDraggingSource {
self.collectionViewLayout.prepare()
}

// private func layoutLeadingViews() {
// if let v = self.leadingView {
// v.frame.size.width = self.bounds.size.width - (self.contentInsets.left + self.contentInsets.right)
// v.frame.origin.x = 0
// v.needsLayout = true
// }
// }

private func _reloadLayout(_ animated: Bool, scrollPosition: CollectionViewScrollPosition = .nearest, completion: AnimationCompletion?, needsRecalculation: Bool) {
self._layoutRequested = false
// self.layoutLeadingViews()
Expand Down Expand Up @@ -1086,7 +1078,10 @@ open class CollectionView: ScrollView, NSDraggingSource {
}

mutating func index(of previousIndex: Int) -> Int? {
return final[previousIndex]
if previousIndex < final.count {
return final[previousIndex]
}
return nil
}
}

Expand Down Expand Up @@ -1701,7 +1696,7 @@ open class CollectionView: ScrollView, NSDraggingSource {
: needApproval
}

if clear {
if clear && (allowsEmptySelection || !approved.isEmpty) {
let deselect = self._selectedIndexPaths.removing(indexPaths)
self._deselectItems(at: deselect, animated: true, notify: notify)
}
Expand Down Expand Up @@ -1779,12 +1774,12 @@ open class CollectionView: ScrollView, NSDraggingSource {

// Standard selection
else {
var de = self._selectedIndexPaths
de.remove(ip)
self._deselectItems(at: de, animated: true, notify: true)
// var de = self._selectedIndexPaths
// de.remove(ip)
// self._deselectItems(at: de, animated: true, notify: true)

self._extendingStart = ip
self._selectItems(at: Set([ip]), animated: true, notify: true)
self._selectItems(at: Set([ip]), animated: true, clear: true, notify: true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion CollectionView/CollectionViewCells.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ open class CollectionReusableView: NSView {
if let c = self.backgroundColor {
NSGraphicsContext.saveGraphicsState()
c.setFill()
dirtyRect.fill()
self.bounds.intersection(dirtyRect).fill()
NSGraphicsContext.restoreGraphicsState()
}
super.draw(dirtyRect)
Expand Down
7 changes: 7 additions & 0 deletions CollectionView/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ public enum CollectionViewDirection {
case up
case down
}

/// CollectionViewLayoutElementKind
public struct CollectionViewLayoutElementKind {
public static let LeadingView: String = "CollectionElementKindLeadingView"
public static let SectionHeader: String = "CollectionElementKindSectionHeader"
public static let SectionFooter: String = "CollectionElementKindSectionFooter"
}
4 changes: 2 additions & 2 deletions CollectionView/DataStructures/EditDistance/EditDistance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public struct EditOperationIndex<T: Hashable> {
deletes.insert(e, for: e.index)
case .substitution:
substitutions.insert(e, for: e.index)
case .move(origin: _):
case .move:
moves.insert(e, for: e.index)
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public struct EditOperationIndex<T: Hashable> {
case .deletion: self.deletes.remove(edit)
case .insertion: self.inserts.remove(edit)
case .substitution: self.substitutions.remove(edit)
case .move(origin: _): self.moves.remove(edit)
case .move: self.moves.remove(edit)
}
}

Expand Down
8 changes: 3 additions & 5 deletions CollectionView/DataStructures/OrderedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,9 @@ public struct OrderedSet<Element: Hashable>: ExpressibleByArrayLiteral, Collecti

public mutating func insert<C: Collection>(contentsOf newElements: C, at index: Int) -> Set<Element> where C.Iterator.Element == Element {
var inserted = Set<Element>()
for (idx, e) in newElements.enumerated() {
if !self.contains(e) {
self._data.insert(e, at: index + idx)
inserted.insert(e)
}
for (idx, e) in newElements.enumerated() where !self.contains(e) {
self._data.insert(e, at: index + idx)
inserted.insert(e)
}
if !inserted.isEmpty {
self._remap(startingAt: index)
Expand Down
2 changes: 1 addition & 1 deletion CollectionView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Loading