-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from PB-Digital/develop
- Loading branch information
Showing
24 changed files
with
3,348 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "1.5.1", | ||
"release_notes": "Custom fonts exports and related swift files was removed" | ||
"version": "1.5.2", | ||
"release_notes": "Imported `SpreadsheetView` library into codebase" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Address.swift | ||
// SpreadsheetView | ||
// | ||
// Created by Kishikawa Katsumi on 3/16/17. | ||
// Copyright © 2017 Kishikawa Katsumi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Address: Hashable { | ||
let row: Int | ||
let column: Int | ||
let rowIndex: Int | ||
let columnIndex: Int | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(rowIndex) | ||
hasher.combine(columnIndex) | ||
} | ||
|
||
static func ==(lhs: Address, rhs: Address) -> Bool { | ||
return lhs.rowIndex == rhs.rowIndex && lhs.columnIndex == rhs.columnIndex | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Array+BinarySearch.swift | ||
// SpreadsheetView | ||
// | ||
// Created by Kishikawa Katsumi on 4/23/17. | ||
// Copyright © 2017 Kishikawa Katsumi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array where Element: Comparable { | ||
func insertionIndex(of element: Element) -> Int { | ||
var lower = 0 | ||
var upper = count - 1 | ||
while lower <= upper { | ||
let middle = (lower + upper) / 2 | ||
if self[middle] < element { | ||
lower = middle + 1 | ||
} else if element < self[middle] { | ||
upper = middle - 1 | ||
} else { | ||
return middle | ||
} | ||
} | ||
return lower | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// Borders.swift | ||
// SpreadsheetView | ||
// | ||
// Created by Kishikawa Katsumi on 5/8/17. | ||
// Copyright © 2017 Kishikawa Katsumi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public struct Borders { | ||
public var top: BorderStyle | ||
public var bottom: BorderStyle | ||
public var left: BorderStyle | ||
public var right: BorderStyle | ||
|
||
public static func all(_ style: BorderStyle) -> Borders { | ||
return Borders(top: style, bottom: style, left: style, right: style) | ||
} | ||
} | ||
|
||
public enum BorderStyle { | ||
case none | ||
case solid(width: CGFloat, color: UIColor) | ||
} | ||
|
||
extension BorderStyle: Equatable { | ||
public static func ==(lhs: BorderStyle, rhs: BorderStyle) -> Bool { | ||
switch (lhs, rhs) { | ||
case (.none, .none): | ||
return true | ||
case let (.solid(lWidth, lColor), .solid(rWidth, rColor)): | ||
return lWidth == rWidth && lColor == rColor | ||
default: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
final class Border: UIView { | ||
var borders: Borders = .all(.none) | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
isUserInteractionEnabled = false | ||
backgroundColor = .clear | ||
layer.zPosition = 1000 | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
} | ||
|
||
override func draw(_ rect: CGRect) { | ||
guard let context = UIGraphicsGetCurrentContext() else { | ||
return | ||
} | ||
context.setFillColor(UIColor.clear.cgColor) | ||
if case let .solid(width, color) = borders.left { | ||
context.move(to: CGPoint(x: width * 0.5, y: 0)) | ||
context.addLine(to: CGPoint(x: width * 0.5, y: bounds.height)) | ||
context.setLineWidth(width) | ||
context.setStrokeColor(color.cgColor) | ||
context.strokePath() | ||
} | ||
if case let .solid(width, color) = borders.right { | ||
context.move(to: CGPoint(x: bounds.width - width * 0.5, y: 0)) | ||
context.addLine(to: CGPoint(x: bounds.width - width * 0.5, y: bounds.height)) | ||
context.setLineWidth(width) | ||
context.setStrokeColor(color.cgColor) | ||
context.strokePath() | ||
} | ||
if case let .solid(width, color) = borders.top { | ||
context.move(to: CGPoint(x: 0, y: width * 0.5)) | ||
context.addLine(to: CGPoint(x: bounds.width, y: width * 0.5)) | ||
context.setLineWidth(width) | ||
context.setStrokeColor(color.cgColor) | ||
context.strokePath() | ||
} | ||
if case let .solid(width, color) = borders.bottom { | ||
context.move(to: CGPoint(x: 0, y: bounds.height - width * 0.5)) | ||
context.addLine(to: CGPoint(x: bounds.width, y: bounds.height - width * 0.5)) | ||
context.setLineWidth(width) | ||
context.setStrokeColor(color.cgColor) | ||
context.strokePath() | ||
} | ||
} | ||
|
||
override func layoutSubviews() { | ||
super.layoutSubviews() | ||
|
||
if case let .solid(width, _) = borders.left { | ||
frame.origin.x -= width * 0.5 | ||
frame.size.width += width * 0.5 | ||
} | ||
if case let .solid(width, _) = borders.right { | ||
frame.size.width += width * 0.5 | ||
} | ||
if case let .solid(width, _) = borders.top { | ||
frame.origin.y -= width * 0.5 | ||
frame.size.height += width * 0.5 | ||
} | ||
if case let .solid(width, _) = borders.bottom { | ||
frame.size.height += width * 0.5 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// Cell.swift | ||
// SpreadsheetView | ||
// | ||
// Created by Kishikawa Katsumi on 3/16/17. | ||
// Copyright © 2017 Kishikawa Katsumi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
open class Cell: UIView { | ||
public let contentView = UIView() | ||
|
||
public var backgroundView: UIView? { | ||
willSet { | ||
backgroundView?.removeFromSuperview() | ||
} | ||
didSet { | ||
guard let backgroundView = backgroundView else { | ||
return | ||
} | ||
backgroundView.frame = bounds | ||
backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
insertSubview(backgroundView, at: 0) | ||
} | ||
} | ||
public var selectedBackgroundView: UIView? { | ||
willSet { | ||
selectedBackgroundView?.removeFromSuperview() | ||
} | ||
didSet { | ||
guard let selectedBackgroundView = selectedBackgroundView else { | ||
return | ||
} | ||
selectedBackgroundView.frame = bounds | ||
selectedBackgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
selectedBackgroundView.alpha = 0 | ||
if let backgroundView = backgroundView { | ||
insertSubview(selectedBackgroundView, aboveSubview: backgroundView) | ||
} else { | ||
insertSubview(selectedBackgroundView, at: 0) | ||
} | ||
} | ||
} | ||
|
||
open var isHighlighted = false { | ||
didSet { | ||
selectedBackgroundView?.alpha = isHighlighted || isSelected ? 1 : 0 | ||
} | ||
} | ||
open var isSelected = false { | ||
didSet { | ||
selectedBackgroundView?.alpha = isSelected ? 1 : 0 | ||
} | ||
} | ||
|
||
public var gridlines = Gridlines(top: .default, bottom: .default, left: .default, right: .default) | ||
public var borders = Borders(top: .none, bottom: .none, left: .none, right: .none) { | ||
didSet { | ||
hasBorder = borders.top != .none || borders.bottom != .none || borders.left != .none || borders.right != .none | ||
} | ||
} | ||
var hasBorder = false | ||
|
||
public internal(set) var reuseIdentifier: String? | ||
|
||
var indexPath: IndexPath! | ||
|
||
public override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setup() | ||
} | ||
|
||
public required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
setup() | ||
} | ||
|
||
open func setup() { | ||
backgroundColor = .white | ||
|
||
contentView.frame = bounds | ||
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
insertSubview(contentView, at: 0) | ||
} | ||
|
||
open func prepareForReuse() {} | ||
|
||
func setSelected(_ selected: Bool, animated: Bool) { | ||
if animated { | ||
UIView.animate(withDuration: CATransaction.animationDuration()) { | ||
self.isSelected = selected | ||
} | ||
} else { | ||
isSelected = selected | ||
} | ||
} | ||
} | ||
|
||
extension Cell: Comparable { | ||
public static func <(lhs: Cell, rhs: Cell) -> Bool { | ||
return lhs.indexPath < rhs.indexPath | ||
} | ||
} | ||
|
||
final class BlankCell: Cell {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// CellRange.swift | ||
// SpreadsheetView | ||
// | ||
// Created by Kishikawa Katsumi on 3/16/17. | ||
// Copyright © 2017 Kishikawa Katsumi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public final class CellRange { | ||
public let from: Location | ||
public let to: Location | ||
|
||
public let columnCount: Int | ||
public let rowCount: Int | ||
|
||
var size: CGSize? | ||
|
||
public convenience init(from: (row: Int, column: Int), to: (row: Int, column: Int)) { | ||
self.init(from: Location(row: from.row, column: from.column), | ||
to: Location(row: to.row, column: to.column)) | ||
} | ||
|
||
public convenience init(from: IndexPath, to: IndexPath) { | ||
self.init(from: Location(row: from.row, column: from.column), | ||
to: Location(row: to.row, column: to.column)) | ||
} | ||
|
||
init(from: Location, to: Location) { | ||
guard from.column <= to.column && from.row <= to.row else { | ||
fatalError("the value of `from` must be less than or equal to the value of `to`") | ||
} | ||
self.from = from | ||
self.to = to | ||
columnCount = to.column - from.column + 1 | ||
rowCount = to.row - from.row + 1 | ||
} | ||
|
||
public func contains(_ indexPath: IndexPath) -> Bool { | ||
return from.column <= indexPath.column && to.column >= indexPath.column && | ||
from.row <= indexPath.row && to.row >= indexPath.row | ||
} | ||
|
||
public func contains(_ cellRange: CellRange) -> Bool { | ||
return from.column <= cellRange.from.column && to.column >= cellRange.to.column && | ||
from.row <= cellRange.from.row && to.row >= cellRange.to.row | ||
} | ||
} | ||
|
||
extension CellRange: Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(from) | ||
} | ||
|
||
public static func ==(lhs: CellRange, rhs: CellRange) -> Bool { | ||
return lhs.from == rhs.from | ||
} | ||
} | ||
|
||
extension CellRange: CustomStringConvertible, CustomDebugStringConvertible { | ||
public var description: String { | ||
return "R\(from.row)C\(from.column):R\(to.row)C\(to.column)" | ||
} | ||
|
||
public var debugDescription: String { | ||
return description | ||
} | ||
} |
Oops, something went wrong.