Skip to content

Commit a677868

Browse files
committed
Added support tvOS and macOS.
1 parent 82747fa commit a677868

File tree

46 files changed

+3506
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3506
-326
lines changed

CGLayout.podspec

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'CGLayout'
11-
s.version = '0.5.3'
11+
s.version = '0.5.5'
1212
s.summary = 'Constraint-based autolayout system written on Swift. Not Autolayout wrapper.'
1313

1414
# This description is used to generate tags and improve search results.
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
1717
# * Write the description between the DESC delimiters below.
1818
# * Finally, don't worry about the indent, CocoaPods strips it!
1919

20-
s.description = 'Powerful autolayout framework, that can manage UIView, CALayer and not rendered views. Has cross-hierarchy coordinate space. Implementation performed on rect-based constraints. Fast, asynchronous, declarative, cacheable, extensible.'
20+
s.description = 'Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Has cross-hierarchy coordinate space. Implementation performed on rect-based constraints. Fast, asynchronous, declarative, cacheable, extensible. Supported iOS, macOS, tvOS.'
2121

2222
s.homepage = 'https://github.com/k-o-d-e-n/CGLayout'
2323
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
@@ -27,6 +27,8 @@ Pod::Spec.new do |s|
2727
s.social_media_url = 'https://twitter.com/K_o_D_e_N'
2828

2929
s.ios.deployment_target = '9.0'
30+
s.tvos.deployment_target = '10.0'
31+
s.macos.deployment_target = '10.10'
3032

3133
s.source_files = 'CGLayout/Classes/**/*'
3234

CGLayout/Classes/CGLayout.swift

+19-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
// Copyright © 2017 K-o-D-e-N. All rights reserved.
77
//
88

9+
#if os(iOS) || os(tvOS)
910
import UIKit
11+
#endif
12+
#if os(macOS)
13+
import Cocoa
14+
#endif
1015

1116
// TODO: !! Comment all code
1217
// TODO: ! Add RTL (right to left language)
1318
// TODO: !! Implement behavior on remove view from hierarchy (Unwrapped LayoutItem, break result in ConstraintsItem). Probably need add `isActive` property.
1419
// TODO: ! Add support UITraitCollection
15-
// TODO: !!! Add MacOS, tvOS support
20+
// TODO: !! Optimization for macOS API
1621
// TODO: !!! Resolve problem with create offset for adjusted views.
1722
// TODO: ! Add CGRect.integral
1823

@@ -155,9 +160,17 @@ public protocol LayoutItem: class, LayoutCoordinateSpace {
155160
weak var superItem: LayoutItem? { get }
156161
// TODO: Add subItems if will be need create layout sub elements. For instance, stack view.
157162
}
158-
extension UIView: AdjustableLayoutItem {
159-
public weak var superItem: LayoutItem? { return superview }
160-
}
163+
#if os(iOS) || os(tvOS)
164+
extension UIView: AdjustableLayoutItem {
165+
public weak var superItem: LayoutItem? { return superview }
166+
}
167+
#endif
168+
#if os(macOS)
169+
extension NSView: LayoutItem {
170+
public weak var superItem: LayoutItem? { return superview }
171+
}
172+
extension NSControl: AdjustableLayoutItem {}
173+
#endif
161174
extension CALayer: LayoutItem {
162175
public weak var superItem: LayoutItem? { return superlayer }
163176
}
@@ -575,9 +588,9 @@ public struct LayoutAnchor {
575588
///
576589
/// - Parameter value: UIEdgeInsets value
577590
/// - Returns: Inset constraint
578-
public static func insets(_ value: UIEdgeInsets) -> RectBasedConstraint { return Inset(insets: value) }
591+
public static func insets(_ value: EdgeInsets) -> RectBasedConstraint { return Inset(insets: value) }
579592
private struct Inset: RectBasedConstraint {
580-
let insets: UIEdgeInsets
593+
let insets: EdgeInsets
581594
/// Main function for constrain source space by other rect
582595
///
583596
/// - Parameters:

CGLayout/Classes/CGLayoutExtended.swift

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ open class LayoutGuide<Super: LayoutItem>: LayoutItem {
2727
self.bounds = CGRect(origin: .zero, size: frame.size)
2828
}
2929
}
30+
#if os(iOS) || os(tvOS)
3031
public extension LayoutGuide where Super: UIView {
3132
/// Fabric method for generation view with any type
3233
///
@@ -46,6 +47,7 @@ public extension LayoutGuide where Super: UIView {
4647
return view
4748
}
4849
}
50+
#endif
4951
public extension LayoutGuide where Super: CALayer {
5052
/// Fabric method for generation layer with any type
5153
///
@@ -86,6 +88,7 @@ extension LayoutGuide {
8688
}
8789
}
8890

91+
#if os(iOS) || os(tvOS)
8992
/// Base class for any view placeholder that need dynamic position and/or size.
9093
/// Used UIViewController pattern for loading target view, therefore will be very simply use him.
9194
open class ViewPlaceholder<View: UIView>: LayoutGuide<UIView> {
@@ -162,6 +165,7 @@ open class UIViewPlaceholder<View: UIView>: UILayoutGuide {
162165
}
163166
}
164167
}
168+
#endif
165169

166170
// MARK: Additional constraints
167171

@@ -209,6 +213,7 @@ public struct AnonymConstraint: LayoutConstraintProtocol {
209213
// TODO: Create constraint for attributed string and other data oriented constraints
210214

211215
/// Size-based constraint for constrain source rect by size of string. The size to draw gets from restrictive rect.
216+
@available(OSX 10.11, *)
212217
public struct StringLayoutConstraint: RectBasedConstraint {
213218
let string: String?
214219
let attributes: [String: Any]?
@@ -245,6 +250,7 @@ public extension String {
245250
/// - attributes: String attributes
246251
/// - context: Drawing context
247252
/// - Returns: String-based constraint
253+
@available(OSX 10.11, *)
248254
func layoutConstraint(with options: NSStringDrawingOptions = .usesLineFragmentOrigin, attributes: [String: Any]? = nil, context: NSStringDrawingContext? = nil) -> StringLayoutConstraint {
249255
return StringLayoutConstraint(string: self, options: options, attributes: attributes, context: context)
250256
}

CGLayout/Classes/CommonExtensions.swift

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,40 @@
88

99
import Foundation
1010

11+
#if os(iOS) || os(tvOS)
12+
typealias EdgeInsets = UIEdgeInsets
13+
#endif
14+
1115
extension CGRect {
1216
var left: CGFloat { return minX }
1317
var right: CGFloat { return maxX }
1418
var top: CGFloat { return minY }
1519
var bottom: CGFloat { return maxY }
16-
17-
mutating func apply(edgeInsets: UIEdgeInsets) {
18-
self = UIEdgeInsetsInsetRect(self, edgeInsets)
20+
}
21+
extension CGRect {
22+
mutating func apply(edgeInsets: EdgeInsets) {
23+
#if os(iOS) || os(tvOS)
24+
self = UIEdgeInsetsInsetRect(self, edgeInsets)
25+
#else
26+
self = CGRect(x: origin.x + edgeInsets.left, y: origin.y + edgeInsets.top,
27+
width: size.width - edgeInsets.horizontal, height: size.height - edgeInsets.vertical)
28+
#endif
1929
}
2030
}
2131

22-
extension UIEdgeInsets {
32+
extension EdgeInsets {
2333
var horizontal: CGFloat { return left + right }
2434
var vertical: CGFloat { return top + bottom }
2535
}
2636

37+
#if os(iOS) || os(tvOS)
2738
@available(iOS 9.0, *)
2839
extension UILayoutGuide: LayoutItem {
2940
public var frame: CGRect { get { return layoutFrame } set {} }
3041
public var bounds: CGRect { get { return CGRect(origin: .zero, size: layoutFrame.size) } set {} }
3142
public var superItem: LayoutItem? { return owningView }
3243
}
44+
#endif
3345

3446
public extension CALayer {
3547
convenience init(frame: CGRect) {

CGLayout/Classes/MultiCoordinateSpace.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
// TODO: !!! Add MacOS support (conversions more complex)
11+
// TODO: !!! Implement macOS coordinate space (conversions more complex)
1212

1313
// MARK: LayoutCoordinateSpace
1414

@@ -25,6 +25,7 @@ public protocol LayoutCoordinateSpace {
2525
var bounds: CGRect { get }
2626
var frame: CGRect { get }
2727
}
28+
#if os(iOS) || os(tvOS)
2829
extension LayoutCoordinateSpace where Self: UICoordinateSpace, Self: LayoutItem {
2930
public func convert(point: CGPoint, to item: LayoutItem) -> CGPoint {
3031
guard !(item is UICoordinateSpace) else { return convert(point, to: item as! UICoordinateSpace) }
@@ -79,6 +80,7 @@ extension LayoutCoordinateSpace where Self: UIView {
7980
return rect
8081
}
8182
}
83+
#endif
8284
extension LayoutCoordinateSpace where Self: CALayer {
8385
public func convert(point: CGPoint, to item: LayoutItem) -> CGPoint {
8486
guard !(item is CALayer) else { return convert(point, to: item as? CALayer) }
@@ -105,6 +107,7 @@ extension LayoutCoordinateSpace where Self: CALayer {
105107
return rect
106108
}
107109
}
110+
#if os(iOS) || os(tvOS)
108111
@available(iOS 9.0, *)
109112
extension LayoutCoordinateSpace where Self: UILayoutGuide {
110113
public func convert(point: CGPoint, to item: LayoutItem) -> CGPoint {
@@ -148,6 +151,7 @@ extension LayoutCoordinateSpace where Self: UILayoutGuide {
148151
return CGRect(x: rectInSuper.origin.x - frame.origin.x, y: rectInSuper.origin.y - frame.origin.y, width: rectInSuper.width, height: rectInSuper.height)
149152
}
150153
}
154+
#endif
151155

152156
fileprivate struct LinkedList<T>: Sequence {
153157
private let startObject: T
@@ -208,6 +212,7 @@ extension LayoutCoordinateSpace where Self: LayoutItem {
208212

209213
// MARK: LayoutGuide convertions
210214

215+
#if os(iOS) || os(tvOS)
211216
extension LayoutGuide where Super: UICoordinateSpace {
212217
public func convert(point: CGPoint, to item: LayoutItem) -> CGPoint {
213218
guard !(item is UICoordinateSpace) else { return convert(point, to: item as! UICoordinateSpace) }
@@ -262,6 +267,7 @@ extension LayoutGuide where Super: UIView {
262267
return rect
263268
}
264269
}
270+
#endif
265271
extension LayoutGuide where Super: CALayer {
266272
public func convert(point: CGPoint, to item: LayoutItem) -> CGPoint {
267273
guard !(item is CALayer) else { return convert(point, to: item as! CALayer) }
@@ -288,6 +294,7 @@ extension LayoutGuide where Super: CALayer {
288294
return rect
289295
}
290296
}
297+
#if os(iOS) || os(tvOS)
291298
extension LayoutGuide where Super: UICoordinateSpace {
292299
@available(iOS 8.0, *)
293300
public func convert(_ point: CGPoint, to coordinateSpace: UICoordinateSpace) -> CGPoint {
@@ -338,6 +345,7 @@ extension LayoutGuide where Super: UIView {
338345
return CGRect(x: rectInSuper.origin.x - frame.origin.x + bounds.origin.x, y: rectInSuper.origin.y - frame.origin.y + bounds.origin.y, width: rectInSuper.width, height: rectInSuper.height)
339346
}
340347
}
348+
#endif
341349
extension LayoutGuide where Super: CALayer {
342350
@available(iOS 8.0, *)
343351
public func convert(_ point: CGPoint, to coordinateSpace: CALayer) -> CGPoint {
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// AppDelegate.swift
3+
// CGLayout-macOS
4+
//
5+
// Created by Denis Koryttsev on 02/10/2017.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
@NSApplicationMain
12+
class AppDelegate: NSObject, NSApplicationDelegate {
13+
14+
15+
16+
func applicationDidFinishLaunching(_ aNotification: Notification) {
17+
// Insert code here to initialize your application
18+
}
19+
20+
func applicationWillTerminate(_ aNotification: Notification) {
21+
// Insert code here to tear down your application
22+
}
23+
24+
25+
}
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"size" : "16x16",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"size" : "16x16",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"size" : "32x32",
16+
"scale" : "1x"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"size" : "32x32",
21+
"scale" : "2x"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"size" : "128x128",
26+
"scale" : "1x"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"size" : "128x128",
31+
"scale" : "2x"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"size" : "256x256",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"size" : "256x256",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"size" : "512x512",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"size" : "512x512",
51+
"scale" : "2x"
52+
}
53+
],
54+
"info" : {
55+
"version" : 1,
56+
"author" : "xcode"
57+
}
58+
}

0 commit comments

Comments
 (0)