forked from michiamling/SpreadsheetView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollPosition.swift
57 lines (50 loc) · 1.81 KB
/
ScrollPosition.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// ScrollPosition.swift
// SpreadsheetView
//
// Created by Kishikawa Katsumi on 4/23/17.
// Copyright © 2017 Kishikawa Katsumi. All rights reserved.
//
import Foundation
public struct ScrollPosition: OptionSet {
// The vertical positions are mutually exclusive to each other, but are bitwise or-able with the horizontal scroll positions.
// Combining positions from the same grouping (horizontal or vertical) will result in an NSInvalidArgumentException.
public static var top = ScrollPosition(rawValue: 1 << 0)
public static var centeredVertically = ScrollPosition(rawValue: 1 << 1)
public static var bottom = ScrollPosition(rawValue: 1 << 2)
// Likewise, the horizontal positions are mutually exclusive to each other.
public static var left = ScrollPosition(rawValue: 1 << 3)
public static var centeredHorizontally = ScrollPosition(rawValue: 1 << 4)
public static var right = ScrollPosition(rawValue: 1 << 5)
public let rawValue: Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
}
extension ScrollPosition: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
var options = [String]()
if contains(.top) {
options.append(".top")
}
if contains(.centeredVertically) {
options.append(".centeredVertically")
}
if contains(.bottom) {
options.append(".bottom")
}
if contains(.left) {
options.append(".left")
}
if contains(.centeredHorizontally) {
options.append(".centeredHorizontally")
}
if contains(.right) {
options.append(".right")
}
return options.description
}
public var debugDescription: String {
return description
}
}