Files
yoga/YogaKit/Source/YGLayoutExtensions.swift

46 lines
1.1 KiB
Swift
Raw Normal View History

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
2020-08-13 22:50:47 +08:00
import Yoga
postfix operator %
extension Int {
public static postfix func %(value: Int) -> YGValue {
2020-08-15 23:55:28 +08:00
return YGValue(value: YGFloat(value), unit: .percent)
}
}
extension Float {
public static postfix func %(value: Float) -> YGValue {
2020-08-15 23:55:28 +08:00
return YGValue(value: YGFloat(value), unit: .percent)
}
}
extension CGFloat {
public static postfix func %(value: CGFloat) -> YGValue {
2020-08-15 23:55:28 +08:00
return YGValue(value: YGFloat(value), unit: .percent)
}
}
extension YGValue : ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral {
public init(integerLiteral value: Int) {
2020-08-15 23:55:28 +08:00
self = YGValue(value: YGFloat(value), unit: .point)
}
public init(floatLiteral value: Float) {
2020-08-15 23:55:28 +08:00
self = YGValue(value: YGFloat(value), unit: .point)
}
public init(_ value: Float) {
2020-08-15 23:55:28 +08:00
self = YGValue(value: YGFloat(value), unit: .point)
}
public init(_ value: CGFloat) {
2020-08-15 23:55:28 +08:00
self = YGValue(value: YGFloat(value), unit: .point)
}
}