@@ -21,15 +21,15 @@ public typealias SLColor = UIColor
2121public typealias SLEdgeInsets = UIEdgeInsets
2222public typealias SLLayoutPriority = UILayoutPriority
2323public typealias SLAlignment = UIStackView . Alignment
24- public typealias SLScreen = UIScreen
24+ public typealias SLAxis = NSLayoutConstraint . Axis
2525#else
2626public typealias SLView = NSView
2727public typealias SLStackView = NSStackView
2828public typealias SLColor = NSColor
2929public typealias SLEdgeInsets = NSEdgeInsets
30- public typealias SLLayoutPriority = NSLayoutPriority
30+ public typealias SLLayoutPriority = NSLayoutConstraint . Priority
3131public typealias SLAlignment = NSLayoutConstraint . Attribute
32- public typealias SLScreen = NSScreen
32+ public typealias SLAxis = NSUserInterfaceLayoutOrientation
3333#endif
3434
3535fileprivate protocol StackLayoutUpdatable {
@@ -104,7 +104,7 @@ public class StackLayout: SLView, StackLayoutUpdatable {
104104 case vertical
105105 case horizontal
106106
107- fileprivate var toAxis : NSLayoutConstraint . Axis {
107+ fileprivate var toAxis : SLAxis {
108108 switch self {
109109 case . vertical:
110110 return . vertical
@@ -118,7 +118,9 @@ public class StackLayout: SLView, StackLayoutUpdatable {
118118 case top
119119 case center
120120 case bottom
121+ #if os(iOS)
121122 case fill
123+ #endif
122124 case firstBaseline
123125 case lastBaseline
124126
@@ -127,11 +129,17 @@ public class StackLayout: SLView, StackLayoutUpdatable {
127129 case . top:
128130 return . top
129131 case . center:
132+ #if os(iOS)
130133 return . center
134+ #else
135+ return . centerY
136+ #endif
131137 case . bottom:
132138 return . bottom
139+ #if os(iOS)
133140 case . fill:
134141 return . fill
142+ #endif
135143 case . firstBaseline:
136144 return . firstBaseline
137145 case . lastBaseline:
@@ -144,18 +152,26 @@ public class StackLayout: SLView, StackLayoutUpdatable {
144152 case left
145153 case center
146154 case right
155+ #if os(iOS)
147156 case fill
157+ #endif
148158
149159 fileprivate var toAlignment : SLAlignment {
150160 switch self {
151161 case . left:
152162 return . leading
153163 case . center:
164+ #if os(iOS)
154165 return . center
166+ #else
167+ return . centerX
168+ #endif
155169 case . right:
156170 return . trailing
171+ #if os(iOS)
157172 case . fill:
158173 return . fill
174+ #endif
159175 }
160176 }
161177 }
@@ -251,23 +267,45 @@ extension StackLayout {
251267 }
252268
253269 public func flex( bgColor: SLColor = . clear) -> SLView {
254- let width = orientation == . vertical ? 1 : SLScreen . main. bounds. width
255- let height = orientation == . vertical ? SLScreen . main. bounds. height : 1
270+ #if os(iOS)
271+ let width = orientation == . vertical ? 1 : UIScreen . main. bounds. width
272+ let height = orientation == . vertical ? UIScreen . main. bounds. height : 1
273+ #else
274+ let width : CGFloat = 0
275+ let height : CGFloat = 0
276+ #endif
256277 let v = StackFlexSpacingView ( width: width, height: height)
278+
279+ #if os(iOS)
257280 v. backgroundColor = bgColor
281+ #else
282+ v. wantsLayer = true
283+ v. layer? . backgroundColor = bgColor. cgColor
284+ #endif
285+
258286 v. setContentCompressionResistancePriority ( SLLayoutPriority ( rawValue: 999 ) , for: orientation == . vertical ? . vertical : . horizontal)
259287 return v
260288 }
261289
262290 public func fixed( w width: CGFloat = 1 , h height: CGFloat = 1 , bgColor: SLColor = . clear) -> SLView {
263291 let v = StackFixedSpacingView ( width: width, height: height)
292+ #if os(iOS)
264293 v. backgroundColor = bgColor
294+ #else
295+ v. wantsLayer = true
296+ v. layer? . backgroundColor = bgColor. cgColor
297+ #endif
265298 return v
266299 }
267300
268301 public func wrap( _ view: SLView , w width: CGFloat = 1 , h height: CGFloat = 1 , bgColor: SLColor = . clear) -> SLView {
269302 let v = StackWrapView ( view: view, width: width, height: height)
303+ #if os(iOS)
270304 v. backgroundColor = bgColor
305+ #else
306+ v. wantsLayer = true
307+ v. layer? . backgroundColor = bgColor. cgColor
308+ #endif
271309 return v
272310 }
273311}
@@ -362,8 +400,18 @@ extension StackLayout {
362400 let arrangedView = layoutViews. filter { return $0. intrinsicContentSize. width != 0 && $0. intrinsicContentSize. height != 0 }
363401 arrangedView. forEach { $0. removeFromSuperview ( ) }
364402
403+ #if os(iOS)
365404 let sv = SLStackView ( arrangedSubviews: arrangedView)
405+ #else
406+ let sv = SLStackView ( views: arrangedView)
407+ #endif
408+
409+ #if os(iOS)
366410 sv. axis = self . orientation. toAxis
411+ #else
412+ sv. orientation = self . orientation. toAxis
413+ #endif
414+
367415 sv. spacing = self . spacing
368416 sv. alignment = self . orientation == . vertical ? horizontalAlignment. toAlignment : verticalAlignment. toAlignment
369417 sv. distribution = self . distribution. toDistribution
0 commit comments