Add SwiftPM support (#1339)
Summary: Using yoga in Swift ```swift import UIKit import yoga let YGUndefined = Float.nan UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), true, 0) let scale = UIGraphicsGetCurrentContext()?.ctm.a ?? 1 UIGraphicsEndImageContext() let config = YGConfigNew() YGConfigSetUseWebDefaults(config, true) YGConfigSetPointScaleFactor(config, Float(scale)) let root = YGNodeNewWithConfig(config) YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow) YGNodeStyleSetFlexWrap(root, YGWrapWrap) YGNodeStyleSetWidth(root, 200) for i in 0..<4 { let leaf = YGNodeNewWithConfig(config) YGNodeStyleSetAspectRatio(leaf, 1) YGNodeStyleSetWidthPercent(leaf, 50) YGNodeInsertChild(root, leaf, UInt32(i)) } YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGNodeStyleGetDirection(root)) for i in 0..<4 { let leaf = YGNodeGetChild(root, UInt32(i)) let left = YGNodeLayoutGetLeft(leaf) let top = YGNodeLayoutGetTop(leaf) let width = YGNodeLayoutGetWidth(leaf) let height = YGNodeLayoutGetHeight(leaf) print("leaf \(i): origin: \(left), \(top), size: \(width), \(height)") } let width = YGNodeLayoutGetWidth(root) let height = YGNodeLayoutGetHeight(root) print("root size: \(width), \(height)") YGNodeFreeRecursive(root) YGConfigFree(config) ``` Pull Request resolved: https://github.com/facebook/yoga/pull/1339 Reviewed By: cipolleschi Differential Revision: D48166958 Pulled By: NickGerleman fbshipit-source-id: 72fef99729d01c7ba291b11f047cf75fd39f7630
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c18e2566a0
commit
ef5784aca6
16
yoga/module.modulemap
Normal file
16
yoga/module.modulemap
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
module yoga [system] {
|
||||
module core {
|
||||
header "YGEnums.h"
|
||||
header "YGMacros.h"
|
||||
header "YGValue.h"
|
||||
header "Yoga.h"
|
||||
export *
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user