pythonnative 0.40.0__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. pythonnative/__init__.py +411 -0
  2. pythonnative/_ios_log.py +92 -0
  3. pythonnative/_yoga.cp313-win_amd64.pyd +0 -0
  4. pythonnative/alerts.py +236 -0
  5. pythonnative/animated.py +1687 -0
  6. pythonnative/animation_graph.py +78 -0
  7. pythonnative/appearance.py +124 -0
  8. pythonnative/bootstrap.py +100 -0
  9. pythonnative/bridge/__init__.py +302 -0
  10. pythonnative/bridge/android.py +78 -0
  11. pythonnative/bridge/codec.py +170 -0
  12. pythonnative/bridge/commits.py +114 -0
  13. pythonnative/bridge/fake.py +243 -0
  14. pythonnative/bridge/ios.py +138 -0
  15. pythonnative/bridge/web.py +489 -0
  16. pythonnative/cli/__init__.py +7 -0
  17. pythonnative/cli/pn.py +1214 -0
  18. pythonnative/component.py +271 -0
  19. pythonnative/components/__init__.py +111 -0
  20. pythonnative/components/_base.py +166 -0
  21. pythonnative/components/controls.py +521 -0
  22. pythonnative/components/layout.py +518 -0
  23. pythonnative/components/lists.py +785 -0
  24. pythonnative/components/media.py +204 -0
  25. pythonnative/components/overlays.py +107 -0
  26. pythonnative/components/pressable.py +252 -0
  27. pythonnative/components/structural.py +167 -0
  28. pythonnative/components/text.py +291 -0
  29. pythonnative/devclient.py +824 -0
  30. pythonnative/devserver/__init__.py +34 -0
  31. pythonnative/devserver/server.py +718 -0
  32. pythonnative/devserver/static/animation_graph.js +82 -0
  33. pythonnative/devserver/static/bridge.js +147 -0
  34. pythonnative/devserver/static/colors.js +70 -0
  35. pythonnative/devserver/static/host.js +552 -0
  36. pythonnative/devserver/static/index.html +60 -0
  37. pythonnative/devserver/static/layout.js +85 -0
  38. pythonnative/devserver/static/preview.css +415 -0
  39. pythonnative/devserver/static/renderer.js +1994 -0
  40. pythonnative/devserver/static/shell.js +345 -0
  41. pythonnative/devserver/static/yoga/LICENSE +21 -0
  42. pythonnative/devserver/static/yoga/binaries/yoga-wasm-base64-esm.js +75 -0
  43. pythonnative/devserver/static/yoga/src/generated/YGEnums.d.ts +189 -0
  44. pythonnative/devserver/static/yoga/src/generated/YGEnums.js +211 -0
  45. pythonnative/devserver/static/yoga/src/generated/YGEnums.js.map +1 -0
  46. pythonnative/devserver/static/yoga/src/index.d.ts +12 -0
  47. pythonnative/devserver/static/yoga/src/index.js +16 -0
  48. pythonnative/devserver/static/yoga/src/index.js.map +1 -0
  49. pythonnative/devserver/static/yoga/src/load.d.ts +11 -0
  50. pythonnative/devserver/static/yoga/src/load.js +17 -0
  51. pythonnative/devserver/static/yoga/src/load.js.map +1 -0
  52. pythonnative/devserver/static/yoga/src/wrapAssembly.d.ts +155 -0
  53. pythonnative/devserver/static/yoga/src/wrapAssembly.js +125 -0
  54. pythonnative/devserver/static/yoga/src/wrapAssembly.js.map +1 -0
  55. pythonnative/devserver/watcher.py +267 -0
  56. pythonnative/devserver/ws.py +421 -0
  57. pythonnative/diagnostics.py +241 -0
  58. pythonnative/element.py +159 -0
  59. pythonnative/equality.py +19 -0
  60. pythonnative/events.py +231 -0
  61. pythonnative/gestures.py +1333 -0
  62. pythonnative/hooks.py +1621 -0
  63. pythonnative/hosts/__init__.py +63 -0
  64. pythonnative/hosts/base.py +596 -0
  65. pythonnative/hosts/native.py +302 -0
  66. pythonnative/hot_reload.py +585 -0
  67. pythonnative/layout.py +328 -0
  68. pythonnative/mutations.py +142 -0
  69. pythonnative/native/android/build.gradle +52 -0
  70. pythonnative/native/android/gradle.properties +3 -0
  71. pythonnative/native/android/settings.gradle +12 -0
  72. pythonnative/native/android/src/main/AndroidManifest.xml +11 -0
  73. pythonnative/native/android/src/main/cpp/CMakeLists.txt +9 -0
  74. pythonnative/native/android/src/main/cpp/yoga_jni.cpp +52 -0
  75. pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeModules.kt +5 -0
  76. pythonnative/native/android/src/main/java/com/pythonnative/generated/NativeProps.kt +3705 -0
  77. pythonnative/native/android/src/main/java/com/pythonnative/generated/PNContracts.kt +129 -0
  78. pythonnative/native/android/src/main/java/com/pythonnative/runtime/PNBridge.kt +261 -0
  79. pythonnative/native/android/src/main/java/com/pythonnative/runtime/PythonHost.kt +20 -0
  80. pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationGraph.kt +108 -0
  81. pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/AnimationSpecs.kt +141 -0
  82. pythonnative/native/android/src/main/java/com/pythonnative/runtime/animation/PNAnimator.kt +257 -0
  83. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/CommitState.kt +106 -0
  84. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/JsonUtil.kt +175 -0
  85. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/MainThread.kt +40 -0
  86. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNLog.kt +33 -0
  87. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNRegistry.kt +82 -0
  88. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/PNTransaction.kt +80 -0
  89. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/TransactionApplier.kt +117 -0
  90. pythonnative/native/android/src/main/java/com/pythonnative/runtime/bridge/ViewRegistry.kt +74 -0
  91. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/BuiltinComponents.kt +37 -0
  92. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ButtonManager.kt +32 -0
  93. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ComponentManager.kt +213 -0
  94. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ContainerManagers.kt +69 -0
  95. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ControlManagers.kt +186 -0
  96. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/DatePickerManager.kt +123 -0
  97. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageLoader.kt +141 -0
  98. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ImageManager.kt +162 -0
  99. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ModalManager.kt +134 -0
  100. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PNColor.kt +201 -0
  101. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PickerManager.kt +86 -0
  102. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PortalManager.kt +55 -0
  103. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/PressableManager.kt +122 -0
  104. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScreenStackManager.kt +110 -0
  105. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ScrollViewManager.kt +214 -0
  106. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/SegmentedControlManager.kt +113 -0
  107. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/StatusBarManager.kt +52 -0
  108. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TabBarManager.kt +131 -0
  109. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextInputManager.kt +250 -0
  110. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/TextManager.kt +233 -0
  111. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/ViewStyler.kt +355 -0
  112. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/VirtualListManager.kt +159 -0
  113. pythonnative/native/android/src/main/java/com/pythonnative/runtime/components/WebViewManager.kt +149 -0
  114. pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureArbiter.kt +233 -0
  115. pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureCoordinator.kt +127 -0
  116. pythonnative/native/android/src/main/java/com/pythonnative/runtime/gestures/GestureRecognizers.kt +527 -0
  117. pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/NativeLayout.kt +145 -0
  118. pythonnative/native/android/src/main/java/com/pythonnative/runtime/layout/YogaNode.kt +29 -0
  119. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/BuiltinModules.kt +73 -0
  120. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/DeviceModules.kt +316 -0
  121. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/HostModule.kt +61 -0
  122. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/MediaModules.kt +200 -0
  123. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NativeModule.kt +158 -0
  124. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/NotificationsModule.kt +100 -0
  125. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/PermissionsModule.kt +99 -0
  126. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/StorageModules.kt +89 -0
  127. pythonnative/native/android/src/main/java/com/pythonnative/runtime/modules/SystemModules.kt +178 -0
  128. pythonnative/native/android/src/main/java/com/pythonnative/runtime/plugins/GeneratedPlugins.kt +16 -0
  129. pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/PNScreenFragment.kt +188 -0
  130. pythonnative/native/android/src/main/java/com/pythonnative/runtime/screens/ScreenRegistry.kt +80 -0
  131. pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNAccessibilityDelegate.kt +48 -0
  132. pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNBorderDrawable.kt +76 -0
  133. pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNEditText.kt +18 -0
  134. pythonnative/native/android/src/main/java/com/pythonnative/runtime/views/PNFrameLayout.kt +49 -0
  135. pythonnative/native/android/src/test/java/com/pythonnative/runtime/AnimationSpecsTest.kt +75 -0
  136. pythonnative/native/android/src/test/java/com/pythonnative/runtime/GestureArbiterTest.kt +197 -0
  137. pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNColorTest.kt +47 -0
  138. pythonnative/native/android/src/test/java/com/pythonnative/runtime/PNTransactionTest.kt +78 -0
  139. pythonnative/native/android/src/test/java/com/pythonnative/runtime/PromiseTest.kt +89 -0
  140. pythonnative/native/ios/Package.swift +23 -0
  141. pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimationGraph.swift +199 -0
  142. pythonnative/native/ios/Sources/PythonNativeKit/Animation/PNAnimator.swift +312 -0
  143. pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNBridge.swift +255 -0
  144. pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNCommit.swift +104 -0
  145. pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNRegistry.swift +142 -0
  146. pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNTransaction.swift +166 -0
  147. pythonnative/native/ios/Sources/PythonNativeKit/Bridge/PNViewRegistry.swift +53 -0
  148. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNButtonManagers.swift +207 -0
  149. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNColor.swift +173 -0
  150. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNComponentManager.swift +183 -0
  151. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNContainerView.swift +56 -0
  152. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNControlManagers.swift +281 -0
  153. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNImageManager.swift +222 -0
  154. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNOverlayManagers.swift +243 -0
  155. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNPressableManager.swift +114 -0
  156. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScreenStackManager.swift +107 -0
  157. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNScrollViewManager.swift +197 -0
  158. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTabBarManager.swift +106 -0
  159. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextInputManager.swift +297 -0
  160. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTextManager.swift +230 -0
  161. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNTransform.swift +82 -0
  162. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewManager.swift +86 -0
  163. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewState.swift +87 -0
  164. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNViewStyler.swift +340 -0
  165. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNVirtualListManager.swift +155 -0
  166. pythonnative/native/ios/Sources/PythonNativeKit/Components/PNWebViewManager.swift +124 -0
  167. pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeModules.swift +1 -0
  168. pythonnative/native/ios/Sources/PythonNativeKit/Generated/NativeProps.swift +3775 -0
  169. pythonnative/native/ios/Sources/PythonNativeKit/Generated/PNContracts.swift +46 -0
  170. pythonnative/native/ios/Sources/PythonNativeKit/Gestures/PNGestureCoordinator.swift +260 -0
  171. pythonnative/native/ios/Sources/PythonNativeKit/Layout/PNLayout.swift +173 -0
  172. pythonnative/native/ios/Sources/PythonNativeKit/Modules/AlertModule.swift +92 -0
  173. pythonnative/native/ios/Sources/PythonNativeKit/Modules/HostModule.swift +80 -0
  174. pythonnative/native/ios/Sources/PythonNativeKit/Modules/LifecycleModules.swift +174 -0
  175. pythonnative/native/ios/Sources/PythonNativeKit/Modules/MediaModules.swift +177 -0
  176. pythonnative/native/ios/Sources/PythonNativeKit/Modules/PNNativeModule.swift +168 -0
  177. pythonnative/native/ios/Sources/PythonNativeKit/Modules/PermissionModules.swift +266 -0
  178. pythonnative/native/ios/Sources/PythonNativeKit/Modules/SystemModules.swift +251 -0
  179. pythonnative/native/ios/Sources/PythonNativeKit/Plugins/PNPluginRegistration.swift +8 -0
  180. pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNScreenRegistry.swift +46 -0
  181. pythonnative/native/ios/Sources/PythonNativeKit/Screens/PNViewController.swift +237 -0
  182. pythonnative/native/ios/Sources/PythonNativeKit/Support/PNCompat.swift +46 -0
  183. pythonnative/native/ios/Sources/PythonNativeKit/Support/PNJSON.swift +173 -0
  184. pythonnative/native/ios/Sources/PythonNativeKit/Support/PNLog.swift +47 -0
  185. pythonnative/native/ios/Sources/PythonNativeKit/Support/PNWindow.swift +51 -0
  186. pythonnative/native/ios/Tests/PythonNativeKitTests/PNAnimationGraphTests.swift +26 -0
  187. pythonnative/native/ios/Tests/PythonNativeKitTests/PNColorTests.swift +50 -0
  188. pythonnative/native/ios/Tests/PythonNativeKitTests/PNCommitTests.swift +86 -0
  189. pythonnative/native/ios/Tests/PythonNativeKitTests/PNGestureTests.swift +101 -0
  190. pythonnative/native/ios/Tests/PythonNativeKitTests/PNManagerTests.swift +126 -0
  191. pythonnative/native/ios/Tests/PythonNativeKitTests/PNModuleTests.swift +111 -0
  192. pythonnative/native/ios/Tests/PythonNativeKitTests/PNTransactionTests.swift +91 -0
  193. pythonnative/native/yoga/LICENSE +21 -0
  194. pythonnative/native/yoga/Package.swift +9 -0
  195. pythonnative/native/yoga/VENDORED.md +2 -0
  196. pythonnative/native/yoga/include/PNStyle.h +10 -0
  197. pythonnative/native/yoga/include/module.modulemap +5 -0
  198. pythonnative/native/yoga/include/yoga/YGConfig.h +158 -0
  199. pythonnative/native/yoga/include/yoga/YGEnums.h +142 -0
  200. pythonnative/native/yoga/include/yoga/YGMacros.h +99 -0
  201. pythonnative/native/yoga/include/yoga/YGNode.h +304 -0
  202. pythonnative/native/yoga/include/yoga/YGNodeLayout.h +35 -0
  203. pythonnative/native/yoga/include/yoga/YGNodeStyle.h +130 -0
  204. pythonnative/native/yoga/include/yoga/YGPixelGrid.h +29 -0
  205. pythonnative/native/yoga/include/yoga/YGValue.h +84 -0
  206. pythonnative/native/yoga/include/yoga/Yoga.h +21 -0
  207. pythonnative/native/yoga/python.cpp +16 -0
  208. pythonnative/native/yoga/style.cpp +272 -0
  209. pythonnative/native/yoga/yoga/CMakeLists.txt +41 -0
  210. pythonnative/native/yoga/yoga/YGConfig.cpp +92 -0
  211. pythonnative/native/yoga/yoga/YGConfig.h +158 -0
  212. pythonnative/native/yoga/yoga/YGEnums.cpp +262 -0
  213. pythonnative/native/yoga/yoga/YGEnums.h +142 -0
  214. pythonnative/native/yoga/yoga/YGMacros.h +99 -0
  215. pythonnative/native/yoga/yoga/YGNode.cpp +366 -0
  216. pythonnative/native/yoga/yoga/YGNode.h +304 -0
  217. pythonnative/native/yoga/yoga/YGNodeLayout.cpp +92 -0
  218. pythonnative/native/yoga/yoga/YGNodeLayout.h +35 -0
  219. pythonnative/native/yoga/yoga/YGNodeStyle.cpp +405 -0
  220. pythonnative/native/yoga/yoga/YGNodeStyle.h +130 -0
  221. pythonnative/native/yoga/yoga/YGPixelGrid.cpp +22 -0
  222. pythonnative/native/yoga/yoga/YGPixelGrid.h +29 -0
  223. pythonnative/native/yoga/yoga/YGValue.cpp +20 -0
  224. pythonnative/native/yoga/yoga/YGValue.h +84 -0
  225. pythonnative/native/yoga/yoga/Yoga.h +21 -0
  226. pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.cpp +563 -0
  227. pythonnative/native/yoga/yoga/algorithm/AbsoluteLayout.h +41 -0
  228. pythonnative/native/yoga/yoga/algorithm/Align.h +72 -0
  229. pythonnative/native/yoga/yoga/algorithm/Baseline.cpp +78 -0
  230. pythonnative/native/yoga/yoga/algorithm/Baseline.h +21 -0
  231. pythonnative/native/yoga/yoga/algorithm/BoundAxis.h +79 -0
  232. pythonnative/native/yoga/yoga/algorithm/Cache.cpp +121 -0
  233. pythonnative/native/yoga/yoga/algorithm/Cache.h +30 -0
  234. pythonnative/native/yoga/yoga/algorithm/CalculateLayout.cpp +2428 -0
  235. pythonnative/native/yoga/yoga/algorithm/CalculateLayout.h +38 -0
  236. pythonnative/native/yoga/yoga/algorithm/FlexDirection.h +120 -0
  237. pythonnative/native/yoga/yoga/algorithm/FlexLine.cpp +124 -0
  238. pythonnative/native/yoga/yoga/algorithm/FlexLine.h +75 -0
  239. pythonnative/native/yoga/yoga/algorithm/PixelGrid.cpp +132 -0
  240. pythonnative/native/yoga/yoga/algorithm/PixelGrid.h +29 -0
  241. pythonnative/native/yoga/yoga/algorithm/SizingMode.h +73 -0
  242. pythonnative/native/yoga/yoga/algorithm/TrailingPosition.h +44 -0
  243. pythonnative/native/yoga/yoga/config/Config.cpp +135 -0
  244. pythonnative/native/yoga/yoga/config/Config.h +92 -0
  245. pythonnative/native/yoga/yoga/debug/AssertFatal.cpp +53 -0
  246. pythonnative/native/yoga/yoga/debug/AssertFatal.h +29 -0
  247. pythonnative/native/yoga/yoga/debug/Log.cpp +107 -0
  248. pythonnative/native/yoga/yoga/debug/Log.h +34 -0
  249. pythonnative/native/yoga/yoga/enums/Align.h +47 -0
  250. pythonnative/native/yoga/yoga/enums/BoxSizing.h +40 -0
  251. pythonnative/native/yoga/yoga/enums/Dimension.h +40 -0
  252. pythonnative/native/yoga/yoga/enums/Direction.h +41 -0
  253. pythonnative/native/yoga/yoga/enums/Display.h +41 -0
  254. pythonnative/native/yoga/yoga/enums/Edge.h +47 -0
  255. pythonnative/native/yoga/yoga/enums/Errata.h +41 -0
  256. pythonnative/native/yoga/yoga/enums/ExperimentalFeature.h +39 -0
  257. pythonnative/native/yoga/yoga/enums/FlexDirection.h +42 -0
  258. pythonnative/native/yoga/yoga/enums/Gutter.h +41 -0
  259. pythonnative/native/yoga/yoga/enums/Justify.h +44 -0
  260. pythonnative/native/yoga/yoga/enums/LogLevel.h +44 -0
  261. pythonnative/native/yoga/yoga/enums/MeasureMode.h +41 -0
  262. pythonnative/native/yoga/yoga/enums/NodeType.h +40 -0
  263. pythonnative/native/yoga/yoga/enums/Overflow.h +41 -0
  264. pythonnative/native/yoga/yoga/enums/PhysicalEdge.h +21 -0
  265. pythonnative/native/yoga/yoga/enums/PositionType.h +41 -0
  266. pythonnative/native/yoga/yoga/enums/Unit.h +42 -0
  267. pythonnative/native/yoga/yoga/enums/Wrap.h +41 -0
  268. pythonnative/native/yoga/yoga/enums/YogaEnums.h +85 -0
  269. pythonnative/native/yoga/yoga/event/event.cpp +87 -0
  270. pythonnative/native/yoga/yoga/event/event.h +130 -0
  271. pythonnative/native/yoga/yoga/module.modulemap +21 -0
  272. pythonnative/native/yoga/yoga/node/CachedMeasurement.h +53 -0
  273. pythonnative/native/yoga/yoga/node/LayoutResults.cpp +48 -0
  274. pythonnative/native/yoga/yoga/node/LayoutResults.h +122 -0
  275. pythonnative/native/yoga/yoga/node/LayoutableChildren.h +148 -0
  276. pythonnative/native/yoga/yoga/node/Node.cpp +443 -0
  277. pythonnative/native/yoga/yoga/node/Node.h +337 -0
  278. pythonnative/native/yoga/yoga/numeric/Comparison.h +81 -0
  279. pythonnative/native/yoga/yoga/numeric/FloatOptional.h +93 -0
  280. pythonnative/native/yoga/yoga/style/SmallValueBuffer.h +133 -0
  281. pythonnative/native/yoga/yoga/style/Style.h +757 -0
  282. pythonnative/native/yoga/yoga/style/StyleLength.h +107 -0
  283. pythonnative/native/yoga/yoga/style/StyleValueHandle.h +98 -0
  284. pythonnative/native/yoga/yoga/style/StyleValuePool.h +127 -0
  285. pythonnative/native_modules/__init__.py +124 -0
  286. pythonnative/native_modules/app_state.py +99 -0
  287. pythonnative/native_modules/battery.py +75 -0
  288. pythonnative/native_modules/biometrics.py +42 -0
  289. pythonnative/native_modules/camera.py +65 -0
  290. pythonnative/native_modules/clipboard.py +46 -0
  291. pythonnative/native_modules/fallback.py +324 -0
  292. pythonnative/native_modules/file_system.py +145 -0
  293. pythonnative/native_modules/haptics.py +75 -0
  294. pythonnative/native_modules/linking.py +123 -0
  295. pythonnative/native_modules/location.py +75 -0
  296. pythonnative/native_modules/net_info.py +112 -0
  297. pythonnative/native_modules/notifications.py +129 -0
  298. pythonnative/native_modules/permissions.py +108 -0
  299. pythonnative/native_modules/registry.py +526 -0
  300. pythonnative/native_modules/secure_store.py +52 -0
  301. pythonnative/native_modules/share.py +51 -0
  302. pythonnative/native_views/__init__.py +375 -0
  303. pythonnative/native_views/base.py +316 -0
  304. pythonnative/native_views/bridge_backend.py +277 -0
  305. pythonnative/navigation/__init__.py +103 -0
  306. pythonnative/navigation/container.py +154 -0
  307. pythonnative/navigation/handle.py +540 -0
  308. pythonnative/navigation/hooks.py +133 -0
  309. pythonnative/navigation/host.py +58 -0
  310. pythonnative/navigation/linking.py +200 -0
  311. pythonnative/navigation/navigators.py +659 -0
  312. pythonnative/navigation/screen.py +149 -0
  313. pythonnative/navigation/state.py +269 -0
  314. pythonnative/net.py +248 -0
  315. pythonnative/platform.py +166 -0
  316. pythonnative/platform_metrics.py +252 -0
  317. pythonnative/preview.py +287 -0
  318. pythonnative/profiling.py +101 -0
  319. pythonnative/project/__init__.py +68 -0
  320. pythonnative/project/android.py +557 -0
  321. pythonnative/project/builder.py +817 -0
  322. pythonnative/project/config.py +773 -0
  323. pythonnative/project/deps.py +719 -0
  324. pythonnative/project/devices.py +304 -0
  325. pythonnative/project/doctor.py +283 -0
  326. pythonnative/project/fingerprint.py +171 -0
  327. pythonnative/project/icons.py +247 -0
  328. pythonnative/project/ios.py +325 -0
  329. pythonnative/project/lockfile.py +100 -0
  330. pythonnative/project/permissions.py +361 -0
  331. pythonnative/project/plugins.py +519 -0
  332. pythonnative/project/runtime_assets.py +183 -0
  333. pythonnative/py.typed +0 -0
  334. pythonnative/query.py +153 -0
  335. pythonnative/reconciler/__init__.py +29 -0
  336. pythonnative/reconciler/boundaries.py +375 -0
  337. pythonnative/reconciler/children.py +88 -0
  338. pythonnative/reconciler/core.py +1165 -0
  339. pythonnative/reconciler/layout_pass.py +393 -0
  340. pythonnative/reconciler/vnode.py +266 -0
  341. pythonnative/refresh.py +55 -0
  342. pythonnative/runtime.py +306 -0
  343. pythonnative/scheduler.py +159 -0
  344. pythonnative/sdk/__init__.py +153 -0
  345. pythonnative/sdk/_components.py +427 -0
  346. pythonnative/sdk/builtins.py +91 -0
  347. pythonnative/sdk/codegen.py +149 -0
  348. pythonnative/sdk/module_codegen.py +184 -0
  349. pythonnative/sdk/schema.py +224 -0
  350. pythonnative/sdk/templates/contracts.kt +46 -0
  351. pythonnative/sdk/templates/contracts.swift +46 -0
  352. pythonnative/storage.py +184 -0
  353. pythonnative/style.py +841 -0
  354. pythonnative/suspense.py +183 -0
  355. pythonnative/templates/android_template/app/build.gradle +75 -0
  356. pythonnative/templates/android_template/app/proguard-rules.pro +21 -0
  357. pythonnative/templates/android_template/app/src/androidTest/java/com/pythonnative/android_template/ExampleInstrumentedTest.kt +24 -0
  358. pythonnative/templates/android_template/app/src/debug/AndroidManifest.xml +7 -0
  359. pythonnative/templates/android_template/app/src/main/AndroidManifest.xml +32 -0
  360. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/MainActivity.kt +130 -0
  361. pythonnative/templates/android_template/app/src/main/java/com/pythonnative/android_template/ScreenFragment.kt +13 -0
  362. pythonnative/templates/android_template/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
  363. pythonnative/templates/android_template/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
  364. pythonnative/templates/android_template/app/src/main/res/layout/activity_main.xml +10 -0
  365. pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
  366. pythonnative/templates/android_template/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
  367. pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  368. pythonnative/templates/android_template/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  369. pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  370. pythonnative/templates/android_template/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  371. pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  372. pythonnative/templates/android_template/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  373. pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  374. pythonnative/templates/android_template/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  375. pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  376. pythonnative/templates/android_template/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  377. pythonnative/templates/android_template/app/src/main/res/navigation/nav_graph.xml +22 -0
  378. pythonnative/templates/android_template/app/src/main/res/values/colors.xml +5 -0
  379. pythonnative/templates/android_template/app/src/main/res/values/strings.xml +5 -0
  380. pythonnative/templates/android_template/app/src/main/res/values/themes.xml +9 -0
  381. pythonnative/templates/android_template/app/src/main/res/values-night/themes.xml +7 -0
  382. pythonnative/templates/android_template/app/src/main/res/xml/backup_rules.xml +13 -0
  383. pythonnative/templates/android_template/app/src/main/res/xml/data_extraction_rules.xml +19 -0
  384. pythonnative/templates/android_template/app/src/test/java/com/pythonnative/android_template/ExampleUnitTest.kt +17 -0
  385. pythonnative/templates/android_template/build.gradle +10 -0
  386. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.jar +0 -0
  387. pythonnative/templates/android_template/gradle/wrapper/gradle-wrapper.properties +6 -0
  388. pythonnative/templates/android_template/gradle.properties +23 -0
  389. pythonnative/templates/android_template/gradlew +185 -0
  390. pythonnative/templates/android_template/gradlew.bat +89 -0
  391. pythonnative/templates/android_template/settings.gradle +17 -0
  392. pythonnative/templates/ios_template/ios_template/AppDelegate.swift +51 -0
  393. pythonnative/templates/ios_template/ios_template/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  394. pythonnative/templates/ios_template/ios_template/Assets.xcassets/AppIcon.appiconset/Contents.json +13 -0
  395. pythonnative/templates/ios_template/ios_template/Assets.xcassets/Contents.json +6 -0
  396. pythonnative/templates/ios_template/ios_template/Base.lproj/LaunchScreen.storyboard +25 -0
  397. pythonnative/templates/ios_template/ios_template/BridgingHeader.h +14 -0
  398. pythonnative/templates/ios_template/ios_template/Info.plist +28 -0
  399. pythonnative/templates/ios_template/ios_template/PythonRuntime.swift +390 -0
  400. pythonnative/templates/ios_template/ios_template/SceneDelegate.swift +61 -0
  401. pythonnative/templates/ios_template/ios_template/ViewController.swift +23 -0
  402. pythonnative/templates/ios_template/ios_template.xcodeproj/project.pbxproj +745 -0
  403. pythonnative/templates/ios_template/ios_template.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  404. pythonnative/templates/ios_template/ios_templateTests/ios_templateTests.swift +36 -0
  405. pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITests.swift +41 -0
  406. pythonnative/templates/ios_template/ios_templateUITests/ios_templateUITestsLaunchTests.swift +32 -0
  407. pythonnative/testing/__init__.py +53 -0
  408. pythonnative/testing/backend.py +276 -0
  409. pythonnative/testing/harness.py +369 -0
  410. pythonnative/utils.py +145 -0
  411. pythonnative-0.40.0.dist-info/DELVEWHEEL +2 -0
  412. pythonnative-0.40.0.dist-info/METADATA +150 -0
  413. pythonnative-0.40.0.dist-info/RECORD +418 -0
  414. pythonnative-0.40.0.dist-info/WHEEL +5 -0
  415. pythonnative-0.40.0.dist-info/entry_points.txt +2 -0
  416. pythonnative-0.40.0.dist-info/licenses/LICENSE +21 -0
  417. pythonnative-0.40.0.dist-info/top_level.txt +1 -0
  418. pythonnative.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,2428 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #include <algorithm>
9
+ #include <atomic>
10
+ #include <cfloat>
11
+ #include <cmath>
12
+ #include <cstring>
13
+
14
+ #include <yoga/Yoga.h>
15
+
16
+ #include <yoga/algorithm/AbsoluteLayout.h>
17
+ #include <yoga/algorithm/Align.h>
18
+ #include <yoga/algorithm/Baseline.h>
19
+ #include <yoga/algorithm/BoundAxis.h>
20
+ #include <yoga/algorithm/Cache.h>
21
+ #include <yoga/algorithm/CalculateLayout.h>
22
+ #include <yoga/algorithm/FlexDirection.h>
23
+ #include <yoga/algorithm/FlexLine.h>
24
+ #include <yoga/algorithm/PixelGrid.h>
25
+ #include <yoga/algorithm/SizingMode.h>
26
+ #include <yoga/algorithm/TrailingPosition.h>
27
+ #include <yoga/debug/AssertFatal.h>
28
+ #include <yoga/debug/Log.h>
29
+ #include <yoga/event/event.h>
30
+ #include <yoga/node/Node.h>
31
+ #include <yoga/numeric/Comparison.h>
32
+ #include <yoga/numeric/FloatOptional.h>
33
+
34
+ namespace facebook::yoga {
35
+
36
+ std::atomic<uint32_t> gCurrentGenerationCount(0);
37
+
38
+ static void constrainMaxSizeForMode(
39
+ const yoga::Node* node,
40
+ Direction direction,
41
+ FlexDirection axis,
42
+ float ownerAxisSize,
43
+ float ownerWidth,
44
+ /*in_out*/ SizingMode* mode,
45
+ /*in_out*/ float* size) {
46
+ const FloatOptional maxSize =
47
+ node->style().resolvedMaxDimension(
48
+ direction, dimension(axis), ownerAxisSize, ownerWidth) +
49
+ FloatOptional(node->style().computeMarginForAxis(axis, ownerWidth));
50
+ switch (*mode) {
51
+ case SizingMode::StretchFit:
52
+ case SizingMode::FitContent:
53
+ *size = (maxSize.isUndefined() || *size < maxSize.unwrap())
54
+ ? *size
55
+ : maxSize.unwrap();
56
+ break;
57
+ case SizingMode::MaxContent:
58
+ if (maxSize.isDefined()) {
59
+ *mode = SizingMode::FitContent;
60
+ *size = maxSize.unwrap();
61
+ }
62
+ break;
63
+ }
64
+ }
65
+
66
+ static void computeFlexBasisForChild(
67
+ const yoga::Node* const node,
68
+ yoga::Node* const child,
69
+ const float width,
70
+ const SizingMode widthMode,
71
+ const float height,
72
+ const float ownerWidth,
73
+ const float ownerHeight,
74
+ const SizingMode heightMode,
75
+ const Direction direction,
76
+ LayoutData& layoutMarkerData,
77
+ const uint32_t depth,
78
+ const uint32_t generationCount) {
79
+ const FlexDirection mainAxis =
80
+ resolveDirection(node->style().flexDirection(), direction);
81
+ const bool isMainAxisRow = isRow(mainAxis);
82
+ const float mainAxisSize = isMainAxisRow ? width : height;
83
+ const float mainAxisOwnerSize = isMainAxisRow ? ownerWidth : ownerHeight;
84
+
85
+ float childWidth = YGUndefined;
86
+ float childHeight = YGUndefined;
87
+ SizingMode childWidthSizingMode;
88
+ SizingMode childHeightSizingMode;
89
+
90
+ const FloatOptional resolvedFlexBasis = child->resolveFlexBasis(
91
+ direction, mainAxis, mainAxisOwnerSize, ownerWidth);
92
+ const bool isRowStyleDimDefined =
93
+ child->hasDefiniteLength(Dimension::Width, ownerWidth);
94
+ const bool isColumnStyleDimDefined =
95
+ child->hasDefiniteLength(Dimension::Height, ownerHeight);
96
+
97
+ if (resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize)) {
98
+ if (child->getLayout().computedFlexBasis.isUndefined() ||
99
+ (child->getConfig()->isExperimentalFeatureEnabled(
100
+ ExperimentalFeature::WebFlexBasis) &&
101
+ child->getLayout().computedFlexBasisGeneration != generationCount)) {
102
+ const FloatOptional paddingAndBorder = FloatOptional(
103
+ paddingAndBorderForAxis(child, mainAxis, direction, ownerWidth));
104
+ child->setLayoutComputedFlexBasis(
105
+ yoga::maxOrDefined(resolvedFlexBasis, paddingAndBorder));
106
+ }
107
+ } else if (isMainAxisRow && isRowStyleDimDefined) {
108
+ // The width is definite, so use that as the flex basis.
109
+ const FloatOptional paddingAndBorder =
110
+ FloatOptional(paddingAndBorderForAxis(
111
+ child, FlexDirection::Row, direction, ownerWidth));
112
+
113
+ child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
114
+ child->getResolvedDimension(
115
+ direction, Dimension::Width, ownerWidth, ownerWidth),
116
+ paddingAndBorder));
117
+ } else if (!isMainAxisRow && isColumnStyleDimDefined) {
118
+ // The height is definite, so use that as the flex basis.
119
+ const FloatOptional paddingAndBorder =
120
+ FloatOptional(paddingAndBorderForAxis(
121
+ child, FlexDirection::Column, direction, ownerWidth));
122
+ child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
123
+ child->getResolvedDimension(
124
+ direction, Dimension::Height, ownerHeight, ownerWidth),
125
+ paddingAndBorder));
126
+ } else {
127
+ // Compute the flex basis and hypothetical main size (i.e. the clamped flex
128
+ // basis).
129
+ childWidthSizingMode = SizingMode::MaxContent;
130
+ childHeightSizingMode = SizingMode::MaxContent;
131
+
132
+ auto marginRow =
133
+ child->style().computeMarginForAxis(FlexDirection::Row, ownerWidth);
134
+ auto marginColumn =
135
+ child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
136
+
137
+ if (isRowStyleDimDefined) {
138
+ childWidth = child
139
+ ->getResolvedDimension(
140
+ direction, Dimension::Width, ownerWidth, ownerWidth)
141
+ .unwrap() +
142
+ marginRow;
143
+ childWidthSizingMode = SizingMode::StretchFit;
144
+ }
145
+ if (isColumnStyleDimDefined) {
146
+ childHeight =
147
+ child
148
+ ->getResolvedDimension(
149
+ direction, Dimension::Height, ownerHeight, ownerWidth)
150
+ .unwrap() +
151
+ marginColumn;
152
+ childHeightSizingMode = SizingMode::StretchFit;
153
+ }
154
+
155
+ // The W3C spec doesn't say anything about the 'overflow' property, but all
156
+ // major browsers appear to implement the following logic.
157
+ if ((!isMainAxisRow && node->style().overflow() == Overflow::Scroll) ||
158
+ node->style().overflow() != Overflow::Scroll) {
159
+ if (yoga::isUndefined(childWidth) && yoga::isDefined(width)) {
160
+ childWidth = width;
161
+ childWidthSizingMode = SizingMode::FitContent;
162
+ }
163
+ }
164
+
165
+ if ((isMainAxisRow && node->style().overflow() == Overflow::Scroll) ||
166
+ node->style().overflow() != Overflow::Scroll) {
167
+ if (yoga::isUndefined(childHeight) && yoga::isDefined(height)) {
168
+ childHeight = height;
169
+ childHeightSizingMode = SizingMode::FitContent;
170
+ }
171
+ }
172
+
173
+ const auto& childStyle = child->style();
174
+ if (childStyle.aspectRatio().isDefined()) {
175
+ if (!isMainAxisRow && childWidthSizingMode == SizingMode::StretchFit) {
176
+ childHeight = marginColumn +
177
+ (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
178
+ childHeightSizingMode = SizingMode::StretchFit;
179
+ } else if (
180
+ isMainAxisRow && childHeightSizingMode == SizingMode::StretchFit) {
181
+ childWidth = marginRow +
182
+ (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
183
+ childWidthSizingMode = SizingMode::StretchFit;
184
+ }
185
+ }
186
+
187
+ // If child has no defined size in the cross axis and is set to stretch, set
188
+ // the cross axis to be measured exactly with the available inner width
189
+
190
+ const bool hasExactWidth =
191
+ yoga::isDefined(width) && widthMode == SizingMode::StretchFit;
192
+ const bool childWidthStretch =
193
+ resolveChildAlignment(node, child) == Align::Stretch &&
194
+ childWidthSizingMode != SizingMode::StretchFit;
195
+ if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth &&
196
+ childWidthStretch) {
197
+ childWidth = width;
198
+ childWidthSizingMode = SizingMode::StretchFit;
199
+ if (childStyle.aspectRatio().isDefined()) {
200
+ childHeight =
201
+ (childWidth - marginRow) / childStyle.aspectRatio().unwrap();
202
+ childHeightSizingMode = SizingMode::StretchFit;
203
+ }
204
+ }
205
+
206
+ const bool hasExactHeight =
207
+ yoga::isDefined(height) && heightMode == SizingMode::StretchFit;
208
+ const bool childHeightStretch =
209
+ resolveChildAlignment(node, child) == Align::Stretch &&
210
+ childHeightSizingMode != SizingMode::StretchFit;
211
+ if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight &&
212
+ childHeightStretch) {
213
+ childHeight = height;
214
+ childHeightSizingMode = SizingMode::StretchFit;
215
+
216
+ if (childStyle.aspectRatio().isDefined()) {
217
+ childWidth =
218
+ (childHeight - marginColumn) * childStyle.aspectRatio().unwrap();
219
+ childWidthSizingMode = SizingMode::StretchFit;
220
+ }
221
+ }
222
+
223
+ constrainMaxSizeForMode(
224
+ child,
225
+ direction,
226
+ FlexDirection::Row,
227
+ ownerWidth,
228
+ ownerWidth,
229
+ &childWidthSizingMode,
230
+ &childWidth);
231
+ constrainMaxSizeForMode(
232
+ child,
233
+ direction,
234
+ FlexDirection::Column,
235
+ ownerHeight,
236
+ ownerWidth,
237
+ &childHeightSizingMode,
238
+ &childHeight);
239
+
240
+ // Measure the child
241
+ calculateLayoutInternal(
242
+ child,
243
+ childWidth,
244
+ childHeight,
245
+ direction,
246
+ childWidthSizingMode,
247
+ childHeightSizingMode,
248
+ ownerWidth,
249
+ ownerHeight,
250
+ false,
251
+ LayoutPassReason::kMeasureChild,
252
+ layoutMarkerData,
253
+ depth,
254
+ generationCount);
255
+
256
+ child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined(
257
+ child->getLayout().measuredDimension(dimension(mainAxis)),
258
+ paddingAndBorderForAxis(child, mainAxis, direction, ownerWidth))));
259
+ }
260
+ child->setLayoutComputedFlexBasisGeneration(generationCount);
261
+ }
262
+
263
+ static void measureNodeWithMeasureFunc(
264
+ yoga::Node* const node,
265
+ const Direction direction,
266
+ float availableWidth,
267
+ float availableHeight,
268
+ const SizingMode widthSizingMode,
269
+ const SizingMode heightSizingMode,
270
+ const float ownerWidth,
271
+ const float ownerHeight,
272
+ LayoutData& layoutMarkerData,
273
+ const LayoutPassReason reason) {
274
+ yoga::assertFatalWithNode(
275
+ node,
276
+ node->hasMeasureFunc(),
277
+ "Expected node to have custom measure function");
278
+
279
+ if (widthSizingMode == SizingMode::MaxContent) {
280
+ availableWidth = YGUndefined;
281
+ }
282
+ if (heightSizingMode == SizingMode::MaxContent) {
283
+ availableHeight = YGUndefined;
284
+ }
285
+
286
+ const auto& layout = node->getLayout();
287
+ const float paddingAndBorderAxisRow = layout.padding(PhysicalEdge::Left) +
288
+ layout.padding(PhysicalEdge::Right) + layout.border(PhysicalEdge::Left) +
289
+ layout.border(PhysicalEdge::Right);
290
+ const float paddingAndBorderAxisColumn = layout.padding(PhysicalEdge::Top) +
291
+ layout.padding(PhysicalEdge::Bottom) + layout.border(PhysicalEdge::Top) +
292
+ layout.border(PhysicalEdge::Bottom);
293
+
294
+ // We want to make sure we don't call measure with negative size
295
+ const float innerWidth = yoga::isUndefined(availableWidth)
296
+ ? availableWidth
297
+ : yoga::maxOrDefined(0.0f, availableWidth - paddingAndBorderAxisRow);
298
+ const float innerHeight = yoga::isUndefined(availableHeight)
299
+ ? availableHeight
300
+ : yoga::maxOrDefined(0.0f, availableHeight - paddingAndBorderAxisColumn);
301
+
302
+ if (widthSizingMode == SizingMode::StretchFit &&
303
+ heightSizingMode == SizingMode::StretchFit) {
304
+ // Don't bother sizing the text if both dimensions are already defined.
305
+ node->setLayoutMeasuredDimension(
306
+ boundAxis(
307
+ node,
308
+ FlexDirection::Row,
309
+ direction,
310
+ availableWidth,
311
+ ownerWidth,
312
+ ownerWidth),
313
+ Dimension::Width);
314
+ node->setLayoutMeasuredDimension(
315
+ boundAxis(
316
+ node,
317
+ FlexDirection::Column,
318
+ direction,
319
+ availableHeight,
320
+ ownerHeight,
321
+ ownerWidth),
322
+ Dimension::Height);
323
+ } else {
324
+ Event::publish<Event::MeasureCallbackStart>(node);
325
+
326
+ // Measure the text under the current constraints.
327
+ const YGSize measuredSize = node->measure(
328
+ innerWidth,
329
+ measureMode(widthSizingMode),
330
+ innerHeight,
331
+ measureMode(heightSizingMode));
332
+
333
+ layoutMarkerData.measureCallbacks += 1;
334
+ layoutMarkerData.measureCallbackReasonsCount[static_cast<size_t>(reason)] +=
335
+ 1;
336
+
337
+ Event::publish<Event::MeasureCallbackEnd>(
338
+ node,
339
+ {innerWidth,
340
+ unscopedEnum(measureMode(widthSizingMode)),
341
+ innerHeight,
342
+ unscopedEnum(measureMode(heightSizingMode)),
343
+ measuredSize.width,
344
+ measuredSize.height,
345
+ reason});
346
+
347
+ node->setLayoutMeasuredDimension(
348
+ boundAxis(
349
+ node,
350
+ FlexDirection::Row,
351
+ direction,
352
+ (widthSizingMode == SizingMode::MaxContent ||
353
+ widthSizingMode == SizingMode::FitContent)
354
+ ? measuredSize.width + paddingAndBorderAxisRow
355
+ : availableWidth,
356
+ ownerWidth,
357
+ ownerWidth),
358
+ Dimension::Width);
359
+
360
+ node->setLayoutMeasuredDimension(
361
+ boundAxis(
362
+ node,
363
+ FlexDirection::Column,
364
+ direction,
365
+ (heightSizingMode == SizingMode::MaxContent ||
366
+ heightSizingMode == SizingMode::FitContent)
367
+ ? measuredSize.height + paddingAndBorderAxisColumn
368
+ : availableHeight,
369
+ ownerHeight,
370
+ ownerWidth),
371
+ Dimension::Height);
372
+ }
373
+ }
374
+
375
+ // For nodes with no children, use the available values if they were provided,
376
+ // or the minimum size as indicated by the padding and border sizes.
377
+ static void measureNodeWithoutChildren(
378
+ yoga::Node* const node,
379
+ const Direction direction,
380
+ const float availableWidth,
381
+ const float availableHeight,
382
+ const SizingMode widthSizingMode,
383
+ const SizingMode heightSizingMode,
384
+ const float ownerWidth,
385
+ const float ownerHeight) {
386
+ const auto& layout = node->getLayout();
387
+
388
+ float width = availableWidth;
389
+ if (widthSizingMode == SizingMode::MaxContent ||
390
+ widthSizingMode == SizingMode::FitContent) {
391
+ width = layout.padding(PhysicalEdge::Left) +
392
+ layout.padding(PhysicalEdge::Right) +
393
+ layout.border(PhysicalEdge::Left) + layout.border(PhysicalEdge::Right);
394
+ }
395
+ node->setLayoutMeasuredDimension(
396
+ boundAxis(
397
+ node, FlexDirection::Row, direction, width, ownerWidth, ownerWidth),
398
+ Dimension::Width);
399
+
400
+ float height = availableHeight;
401
+ if (heightSizingMode == SizingMode::MaxContent ||
402
+ heightSizingMode == SizingMode::FitContent) {
403
+ height = layout.padding(PhysicalEdge::Top) +
404
+ layout.padding(PhysicalEdge::Bottom) +
405
+ layout.border(PhysicalEdge::Top) + layout.border(PhysicalEdge::Bottom);
406
+ }
407
+ node->setLayoutMeasuredDimension(
408
+ boundAxis(
409
+ node,
410
+ FlexDirection::Column,
411
+ direction,
412
+ height,
413
+ ownerHeight,
414
+ ownerWidth),
415
+ Dimension::Height);
416
+ }
417
+
418
+ static bool measureNodeWithFixedSize(
419
+ yoga::Node* const node,
420
+ const Direction direction,
421
+ const float availableWidth,
422
+ const float availableHeight,
423
+ const SizingMode widthSizingMode,
424
+ const SizingMode heightSizingMode,
425
+ const float ownerWidth,
426
+ const float ownerHeight) {
427
+ if ((yoga::isDefined(availableWidth) &&
428
+ widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) ||
429
+ (yoga::isDefined(availableHeight) &&
430
+ heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) ||
431
+ (widthSizingMode == SizingMode::StretchFit &&
432
+ heightSizingMode == SizingMode::StretchFit)) {
433
+ node->setLayoutMeasuredDimension(
434
+ boundAxis(
435
+ node,
436
+ FlexDirection::Row,
437
+ direction,
438
+ yoga::isUndefined(availableWidth) ||
439
+ (widthSizingMode == SizingMode::FitContent &&
440
+ availableWidth < 0.0f)
441
+ ? 0.0f
442
+ : availableWidth,
443
+ ownerWidth,
444
+ ownerWidth),
445
+ Dimension::Width);
446
+
447
+ node->setLayoutMeasuredDimension(
448
+ boundAxis(
449
+ node,
450
+ FlexDirection::Column,
451
+ direction,
452
+ yoga::isUndefined(availableHeight) ||
453
+ (heightSizingMode == SizingMode::FitContent &&
454
+ availableHeight < 0.0f)
455
+ ? 0.0f
456
+ : availableHeight,
457
+ ownerHeight,
458
+ ownerWidth),
459
+ Dimension::Height);
460
+ return true;
461
+ }
462
+
463
+ return false;
464
+ }
465
+
466
+ static void zeroOutLayoutRecursively(yoga::Node* const node) {
467
+ node->getLayout() = {};
468
+ node->setLayoutDimension(0, Dimension::Width);
469
+ node->setLayoutDimension(0, Dimension::Height);
470
+ node->setHasNewLayout(true);
471
+
472
+ node->cloneChildrenIfNeeded();
473
+ for (const auto child : node->getChildren()) {
474
+ zeroOutLayoutRecursively(child);
475
+ }
476
+ }
477
+
478
+ static void cleanupContentsNodesRecursively(yoga::Node* const node) {
479
+ for (auto child : node->getChildren()) {
480
+ if (child->style().display() == Display::Contents) {
481
+ child->getLayout() = {};
482
+ child->setLayoutDimension(0, Dimension::Width);
483
+ child->setLayoutDimension(0, Dimension::Height);
484
+ child->setHasNewLayout(true);
485
+ child->setDirty(false);
486
+ child->cloneChildrenIfNeeded();
487
+
488
+ cleanupContentsNodesRecursively(child);
489
+ }
490
+ }
491
+ }
492
+
493
+ static float calculateAvailableInnerDimension(
494
+ const yoga::Node* const node,
495
+ const Direction direction,
496
+ const Dimension dimension,
497
+ const float availableDim,
498
+ const float paddingAndBorder,
499
+ const float ownerDim,
500
+ const float ownerWidth) {
501
+ float availableInnerDim = availableDim - paddingAndBorder;
502
+ // Max dimension overrides predefined dimension value; Min dimension in turn
503
+ // overrides both of the above
504
+ if (yoga::isDefined(availableInnerDim)) {
505
+ // We want to make sure our available height does not violate min and max
506
+ // constraints
507
+ const FloatOptional minDimensionOptional =
508
+ node->style().resolvedMinDimension(
509
+ direction, dimension, ownerDim, ownerWidth);
510
+ const float minInnerDim = minDimensionOptional.isUndefined()
511
+ ? 0.0f
512
+ : minDimensionOptional.unwrap() - paddingAndBorder;
513
+
514
+ const FloatOptional maxDimensionOptional =
515
+ node->style().resolvedMaxDimension(
516
+ direction, dimension, ownerDim, ownerWidth);
517
+
518
+ const float maxInnerDim = maxDimensionOptional.isUndefined()
519
+ ? FLT_MAX
520
+ : maxDimensionOptional.unwrap() - paddingAndBorder;
521
+ availableInnerDim = yoga::maxOrDefined(
522
+ yoga::minOrDefined(availableInnerDim, maxInnerDim), minInnerDim);
523
+ }
524
+
525
+ return availableInnerDim;
526
+ }
527
+
528
+ static float computeFlexBasisForChildren(
529
+ yoga::Node* const node,
530
+ const float availableInnerWidth,
531
+ const float availableInnerHeight,
532
+ SizingMode widthSizingMode,
533
+ SizingMode heightSizingMode,
534
+ Direction direction,
535
+ FlexDirection mainAxis,
536
+ bool performLayout,
537
+ LayoutData& layoutMarkerData,
538
+ const uint32_t depth,
539
+ const uint32_t generationCount) {
540
+ float totalOuterFlexBasis = 0.0f;
541
+ YGNodeRef singleFlexChild = nullptr;
542
+ auto children = node->getLayoutChildren();
543
+ SizingMode sizingModeMainDim =
544
+ isRow(mainAxis) ? widthSizingMode : heightSizingMode;
545
+ // If there is only one child with flexGrow + flexShrink it means we can set
546
+ // the computedFlexBasis to 0 instead of measuring and shrinking / flexing the
547
+ // child to exactly match the remaining space
548
+ if (sizingModeMainDim == SizingMode::StretchFit) {
549
+ for (auto child : children) {
550
+ if (child->isNodeFlexible()) {
551
+ if (singleFlexChild != nullptr ||
552
+ yoga::inexactEquals(child->resolveFlexGrow(), 0.0f) ||
553
+ yoga::inexactEquals(child->resolveFlexShrink(), 0.0f)) {
554
+ // There is already a flexible child, or this flexible child doesn't
555
+ // have flexGrow and flexShrink, abort
556
+ singleFlexChild = nullptr;
557
+ break;
558
+ } else {
559
+ singleFlexChild = child;
560
+ }
561
+ }
562
+ }
563
+ }
564
+
565
+ for (auto child : children) {
566
+ child->processDimensions();
567
+ if (child->style().display() == Display::None) {
568
+ zeroOutLayoutRecursively(child);
569
+ child->setHasNewLayout(true);
570
+ child->setDirty(false);
571
+ continue;
572
+ }
573
+ if (performLayout) {
574
+ // Set the initial position (relative to the owner).
575
+ const Direction childDirection = child->resolveDirection(direction);
576
+ child->setPosition(
577
+ childDirection, availableInnerWidth, availableInnerHeight);
578
+ }
579
+
580
+ if (child->style().positionType() == PositionType::Absolute) {
581
+ continue;
582
+ }
583
+ if (child == singleFlexChild) {
584
+ child->setLayoutComputedFlexBasisGeneration(generationCount);
585
+ child->setLayoutComputedFlexBasis(FloatOptional(0));
586
+ } else {
587
+ computeFlexBasisForChild(
588
+ node,
589
+ child,
590
+ availableInnerWidth,
591
+ widthSizingMode,
592
+ availableInnerHeight,
593
+ availableInnerWidth,
594
+ availableInnerHeight,
595
+ heightSizingMode,
596
+ direction,
597
+ layoutMarkerData,
598
+ depth,
599
+ generationCount);
600
+ }
601
+
602
+ totalOuterFlexBasis +=
603
+ (child->getLayout().computedFlexBasis.unwrap() +
604
+ child->style().computeMarginForAxis(mainAxis, availableInnerWidth));
605
+ }
606
+
607
+ return totalOuterFlexBasis;
608
+ }
609
+
610
+ // It distributes the free space to the flexible items and ensures that the size
611
+ // of the flex items abide the min and max constraints. At the end of this
612
+ // function the child nodes would have proper size. Prior using this function
613
+ // please ensure that distributeFreeSpaceFirstPass is called.
614
+ static float distributeFreeSpaceSecondPass(
615
+ FlexLine& flexLine,
616
+ yoga::Node* const node,
617
+ const FlexDirection mainAxis,
618
+ const FlexDirection crossAxis,
619
+ const Direction direction,
620
+ const float ownerWidth,
621
+ const float mainAxisOwnerSize,
622
+ const float availableInnerMainDim,
623
+ const float availableInnerCrossDim,
624
+ const float availableInnerWidth,
625
+ const float availableInnerHeight,
626
+ const bool mainAxisOverflows,
627
+ const SizingMode sizingModeCrossDim,
628
+ const bool performLayout,
629
+ LayoutData& layoutMarkerData,
630
+ const uint32_t depth,
631
+ const uint32_t generationCount) {
632
+ float childFlexBasis = 0;
633
+ float flexShrinkScaledFactor = 0;
634
+ float flexGrowFactor = 0;
635
+ float deltaFreeSpace = 0;
636
+ const bool isMainAxisRow = isRow(mainAxis);
637
+ const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap;
638
+
639
+ for (auto currentLineChild : flexLine.itemsInFlow) {
640
+ childFlexBasis = boundAxisWithinMinAndMax(
641
+ currentLineChild,
642
+ direction,
643
+ mainAxis,
644
+ currentLineChild->getLayout().computedFlexBasis,
645
+ mainAxisOwnerSize,
646
+ ownerWidth)
647
+ .unwrap();
648
+ float updatedMainSize = childFlexBasis;
649
+
650
+ if (yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
651
+ flexLine.layout.remainingFreeSpace < 0) {
652
+ flexShrinkScaledFactor =
653
+ -currentLineChild->resolveFlexShrink() * childFlexBasis;
654
+ // Is this child able to shrink?
655
+ if (flexShrinkScaledFactor != 0) {
656
+ float childSize = YGUndefined;
657
+
658
+ if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
659
+ flexLine.layout.totalFlexShrinkScaledFactors == 0) {
660
+ childSize = childFlexBasis + flexShrinkScaledFactor;
661
+ } else {
662
+ childSize = childFlexBasis +
663
+ (flexLine.layout.remainingFreeSpace /
664
+ flexLine.layout.totalFlexShrinkScaledFactors) *
665
+ flexShrinkScaledFactor;
666
+ }
667
+
668
+ updatedMainSize = boundAxis(
669
+ currentLineChild,
670
+ mainAxis,
671
+ direction,
672
+ childSize,
673
+ availableInnerMainDim,
674
+ availableInnerWidth);
675
+ }
676
+ } else if (
677
+ yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
678
+ flexLine.layout.remainingFreeSpace > 0) {
679
+ flexGrowFactor = currentLineChild->resolveFlexGrow();
680
+
681
+ // Is this child able to grow?
682
+ if (!std::isnan(flexGrowFactor) && flexGrowFactor != 0) {
683
+ updatedMainSize = boundAxis(
684
+ currentLineChild,
685
+ mainAxis,
686
+ direction,
687
+ childFlexBasis +
688
+ flexLine.layout.remainingFreeSpace /
689
+ flexLine.layout.totalFlexGrowFactors * flexGrowFactor,
690
+ availableInnerMainDim,
691
+ availableInnerWidth);
692
+ }
693
+ }
694
+
695
+ deltaFreeSpace += updatedMainSize - childFlexBasis;
696
+
697
+ const float marginMain = currentLineChild->style().computeMarginForAxis(
698
+ mainAxis, availableInnerWidth);
699
+ const float marginCross = currentLineChild->style().computeMarginForAxis(
700
+ crossAxis, availableInnerWidth);
701
+
702
+ float childCrossSize = YGUndefined;
703
+ float childMainSize = updatedMainSize + marginMain;
704
+ SizingMode childCrossSizingMode;
705
+ SizingMode childMainSizingMode = SizingMode::StretchFit;
706
+
707
+ const auto& childStyle = currentLineChild->style();
708
+ if (childStyle.aspectRatio().isDefined()) {
709
+ childCrossSize = isMainAxisRow
710
+ ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap()
711
+ : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap();
712
+ childCrossSizingMode = SizingMode::StretchFit;
713
+
714
+ childCrossSize += marginCross;
715
+ } else if (
716
+ !std::isnan(availableInnerCrossDim) &&
717
+ !currentLineChild->hasDefiniteLength(
718
+ dimension(crossAxis), availableInnerCrossDim) &&
719
+ sizingModeCrossDim == SizingMode::StretchFit &&
720
+ !(isNodeFlexWrap && mainAxisOverflows) &&
721
+ resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
722
+ !currentLineChild->style().flexStartMarginIsAuto(
723
+ crossAxis, direction) &&
724
+ !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction)) {
725
+ childCrossSize = availableInnerCrossDim;
726
+ childCrossSizingMode = SizingMode::StretchFit;
727
+ } else if (!currentLineChild->hasDefiniteLength(
728
+ dimension(crossAxis), availableInnerCrossDim)) {
729
+ childCrossSize = availableInnerCrossDim;
730
+ childCrossSizingMode = yoga::isUndefined(childCrossSize)
731
+ ? SizingMode::MaxContent
732
+ : SizingMode::FitContent;
733
+ } else {
734
+ childCrossSize = currentLineChild
735
+ ->getResolvedDimension(
736
+ direction,
737
+ dimension(crossAxis),
738
+ availableInnerCrossDim,
739
+ availableInnerWidth)
740
+ .unwrap() +
741
+ marginCross;
742
+ const bool isLoosePercentageMeasurement =
743
+ currentLineChild->getProcessedDimension(dimension(crossAxis))
744
+ .unit() == Unit::Percent &&
745
+ sizingModeCrossDim != SizingMode::StretchFit;
746
+ childCrossSizingMode =
747
+ yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
748
+ ? SizingMode::MaxContent
749
+ : SizingMode::StretchFit;
750
+ }
751
+
752
+ constrainMaxSizeForMode(
753
+ currentLineChild,
754
+ direction,
755
+ mainAxis,
756
+ availableInnerMainDim,
757
+ availableInnerWidth,
758
+ &childMainSizingMode,
759
+ &childMainSize);
760
+ constrainMaxSizeForMode(
761
+ currentLineChild,
762
+ direction,
763
+ crossAxis,
764
+ availableInnerCrossDim,
765
+ availableInnerWidth,
766
+ &childCrossSizingMode,
767
+ &childCrossSize);
768
+
769
+ const bool requiresStretchLayout =
770
+ !currentLineChild->hasDefiniteLength(
771
+ dimension(crossAxis), availableInnerCrossDim) &&
772
+ resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
773
+ !currentLineChild->style().flexStartMarginIsAuto(
774
+ crossAxis, direction) &&
775
+ !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction);
776
+
777
+ const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
778
+ const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
779
+
780
+ const SizingMode childWidthSizingMode =
781
+ isMainAxisRow ? childMainSizingMode : childCrossSizingMode;
782
+ const SizingMode childHeightSizingMode =
783
+ !isMainAxisRow ? childMainSizingMode : childCrossSizingMode;
784
+
785
+ const bool isLayoutPass = performLayout && !requiresStretchLayout;
786
+ // Recursively call the layout algorithm for this child with the updated
787
+ // main size.
788
+ calculateLayoutInternal(
789
+ currentLineChild,
790
+ childWidth,
791
+ childHeight,
792
+ node->getLayout().direction(),
793
+ childWidthSizingMode,
794
+ childHeightSizingMode,
795
+ availableInnerWidth,
796
+ availableInnerHeight,
797
+ isLayoutPass,
798
+ isLayoutPass ? LayoutPassReason::kFlexLayout
799
+ : LayoutPassReason::kFlexMeasure,
800
+ layoutMarkerData,
801
+ depth,
802
+ generationCount);
803
+ node->setLayoutHadOverflow(
804
+ node->getLayout().hadOverflow() ||
805
+ currentLineChild->getLayout().hadOverflow());
806
+ }
807
+ return deltaFreeSpace;
808
+ }
809
+
810
+ // It distributes the free space to the flexible items.For those flexible items
811
+ // whose min and max constraints are triggered, those flex item's clamped size
812
+ // is removed from the remaingfreespace.
813
+ static void distributeFreeSpaceFirstPass(
814
+ FlexLine& flexLine,
815
+ const Direction direction,
816
+ const FlexDirection mainAxis,
817
+ const float ownerWidth,
818
+ const float mainAxisOwnerSize,
819
+ const float availableInnerMainDim,
820
+ const float availableInnerWidth) {
821
+ float flexShrinkScaledFactor = 0;
822
+ float flexGrowFactor = 0;
823
+ float baseMainSize = 0;
824
+ float boundMainSize = 0;
825
+ float deltaFreeSpace = 0;
826
+
827
+ for (auto currentLineChild : flexLine.itemsInFlow) {
828
+ float childFlexBasis = boundAxisWithinMinAndMax(
829
+ currentLineChild,
830
+ direction,
831
+ mainAxis,
832
+ currentLineChild->getLayout().computedFlexBasis,
833
+ mainAxisOwnerSize,
834
+ ownerWidth)
835
+ .unwrap();
836
+
837
+ if (flexLine.layout.remainingFreeSpace < 0) {
838
+ flexShrinkScaledFactor =
839
+ -currentLineChild->resolveFlexShrink() * childFlexBasis;
840
+
841
+ // Is this child able to shrink?
842
+ if (yoga::isDefined(flexShrinkScaledFactor) &&
843
+ flexShrinkScaledFactor != 0) {
844
+ baseMainSize = childFlexBasis +
845
+ flexLine.layout.remainingFreeSpace /
846
+ flexLine.layout.totalFlexShrinkScaledFactors *
847
+ flexShrinkScaledFactor;
848
+ boundMainSize = boundAxis(
849
+ currentLineChild,
850
+ mainAxis,
851
+ direction,
852
+ baseMainSize,
853
+ availableInnerMainDim,
854
+ availableInnerWidth);
855
+ if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) &&
856
+ baseMainSize != boundMainSize) {
857
+ // By excluding this item's size and flex factor from remaining, this
858
+ // item's min/max constraints should also trigger in the second pass
859
+ // resulting in the item's size calculation being identical in the
860
+ // first and second passes.
861
+ deltaFreeSpace += boundMainSize - childFlexBasis;
862
+ flexLine.layout.totalFlexShrinkScaledFactors -=
863
+ (-currentLineChild->resolveFlexShrink() *
864
+ currentLineChild->getLayout().computedFlexBasis.unwrap());
865
+ }
866
+ }
867
+ } else if (
868
+ yoga::isDefined(flexLine.layout.remainingFreeSpace) &&
869
+ flexLine.layout.remainingFreeSpace > 0) {
870
+ flexGrowFactor = currentLineChild->resolveFlexGrow();
871
+
872
+ // Is this child able to grow?
873
+ if (yoga::isDefined(flexGrowFactor) && flexGrowFactor != 0) {
874
+ baseMainSize = childFlexBasis +
875
+ flexLine.layout.remainingFreeSpace /
876
+ flexLine.layout.totalFlexGrowFactors * flexGrowFactor;
877
+ boundMainSize = boundAxis(
878
+ currentLineChild,
879
+ mainAxis,
880
+ direction,
881
+ baseMainSize,
882
+ availableInnerMainDim,
883
+ availableInnerWidth);
884
+
885
+ if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) &&
886
+ baseMainSize != boundMainSize) {
887
+ // By excluding this item's size and flex factor from remaining, this
888
+ // item's min/max constraints should also trigger in the second pass
889
+ // resulting in the item's size calculation being identical in the
890
+ // first and second passes.
891
+ deltaFreeSpace += boundMainSize - childFlexBasis;
892
+ flexLine.layout.totalFlexGrowFactors -= flexGrowFactor;
893
+ }
894
+ }
895
+ }
896
+ }
897
+ flexLine.layout.remainingFreeSpace -= deltaFreeSpace;
898
+ }
899
+
900
+ // Do two passes over the flex items to figure out how to distribute the
901
+ // remaining space.
902
+ //
903
+ // The first pass finds the items whose min/max constraints trigger, freezes
904
+ // them at those sizes, and excludes those sizes from the remaining space.
905
+ //
906
+ // The second pass sets the size of each flexible item. It distributes the
907
+ // remaining space amongst the items whose min/max constraints didn't trigger in
908
+ // the first pass. For the other items, it sets their sizes by forcing their
909
+ // min/max constraints to trigger again.
910
+ //
911
+ // This two pass approach for resolving min/max constraints deviates from the
912
+ // spec. The spec
913
+ // (https://www.w3.org/TR/CSS-flexbox-1/#resolve-flexible-lengths) describes a
914
+ // process that needs to be repeated a variable number of times. The algorithm
915
+ // implemented here won't handle all cases but it was simpler to implement and
916
+ // it mitigates performance concerns because we know exactly how many passes
917
+ // it'll do.
918
+ //
919
+ // At the end of this function the child nodes would have the proper size
920
+ // assigned to them.
921
+ //
922
+ static void resolveFlexibleLength(
923
+ yoga::Node* const node,
924
+ FlexLine& flexLine,
925
+ const FlexDirection mainAxis,
926
+ const FlexDirection crossAxis,
927
+ const Direction direction,
928
+ const float ownerWidth,
929
+ const float mainAxisOwnerSize,
930
+ const float availableInnerMainDim,
931
+ const float availableInnerCrossDim,
932
+ const float availableInnerWidth,
933
+ const float availableInnerHeight,
934
+ const bool mainAxisOverflows,
935
+ const SizingMode sizingModeCrossDim,
936
+ const bool performLayout,
937
+ LayoutData& layoutMarkerData,
938
+ const uint32_t depth,
939
+ const uint32_t generationCount) {
940
+ const float originalFreeSpace = flexLine.layout.remainingFreeSpace;
941
+ // First pass: detect the flex items whose min/max constraints trigger
942
+ distributeFreeSpaceFirstPass(
943
+ flexLine,
944
+ direction,
945
+ mainAxis,
946
+ ownerWidth,
947
+ mainAxisOwnerSize,
948
+ availableInnerMainDim,
949
+ availableInnerWidth);
950
+
951
+ // Second pass: resolve the sizes of the flexible items
952
+ const float distributedFreeSpace = distributeFreeSpaceSecondPass(
953
+ flexLine,
954
+ node,
955
+ mainAxis,
956
+ crossAxis,
957
+ direction,
958
+ ownerWidth,
959
+ mainAxisOwnerSize,
960
+ availableInnerMainDim,
961
+ availableInnerCrossDim,
962
+ availableInnerWidth,
963
+ availableInnerHeight,
964
+ mainAxisOverflows,
965
+ sizingModeCrossDim,
966
+ performLayout,
967
+ layoutMarkerData,
968
+ depth,
969
+ generationCount);
970
+
971
+ flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace;
972
+ }
973
+
974
+ static void justifyMainAxis(
975
+ yoga::Node* const node,
976
+ FlexLine& flexLine,
977
+ const FlexDirection mainAxis,
978
+ const FlexDirection crossAxis,
979
+ const Direction direction,
980
+ const SizingMode sizingModeMainDim,
981
+ const SizingMode sizingModeCrossDim,
982
+ const float mainAxisOwnerSize,
983
+ const float ownerWidth,
984
+ const float availableInnerMainDim,
985
+ const float availableInnerCrossDim,
986
+ const float availableInnerWidth,
987
+ const bool performLayout) {
988
+ const auto& style = node->style();
989
+
990
+ const float leadingPaddingAndBorderMain =
991
+ node->style().computeFlexStartPaddingAndBorder(
992
+ mainAxis, direction, ownerWidth);
993
+ const float trailingPaddingAndBorderMain =
994
+ node->style().computeFlexEndPaddingAndBorder(
995
+ mainAxis, direction, ownerWidth);
996
+
997
+ const float gap =
998
+ node->style().computeGapForAxis(mainAxis, availableInnerMainDim);
999
+ // If we are using "at most" rules in the main axis, make sure that
1000
+ // remainingFreeSpace is 0 when min main dimension is not given
1001
+ if (sizingModeMainDim == SizingMode::FitContent &&
1002
+ flexLine.layout.remainingFreeSpace > 0) {
1003
+ if (style.minDimension(dimension(mainAxis)).isDefined() &&
1004
+ style
1005
+ .resolvedMinDimension(
1006
+ direction, dimension(mainAxis), mainAxisOwnerSize, ownerWidth)
1007
+ .isDefined()) {
1008
+ // This condition makes sure that if the size of main dimension(after
1009
+ // considering child nodes main dim, leading and trailing padding etc)
1010
+ // falls below min dimension, then the remainingFreeSpace is reassigned
1011
+ // considering the min dimension
1012
+
1013
+ // `minAvailableMainDim` denotes minimum available space in which child
1014
+ // can be laid out, it will exclude space consumed by padding and border.
1015
+ const float minAvailableMainDim =
1016
+ style
1017
+ .resolvedMinDimension(
1018
+ direction, dimension(mainAxis), mainAxisOwnerSize, ownerWidth)
1019
+ .unwrap() -
1020
+ leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
1021
+ const float occupiedSpaceByChildNodes =
1022
+ availableInnerMainDim - flexLine.layout.remainingFreeSpace;
1023
+ flexLine.layout.remainingFreeSpace = yoga::maxOrDefined(
1024
+ 0.0f, minAvailableMainDim - occupiedSpaceByChildNodes);
1025
+ } else {
1026
+ flexLine.layout.remainingFreeSpace = 0;
1027
+ }
1028
+ }
1029
+
1030
+ // In order to position the elements in the main axis, we have two controls.
1031
+ // The space between the beginning and the first element and the space between
1032
+ // each two elements.
1033
+ float leadingMainDim = 0;
1034
+ float betweenMainDim = gap;
1035
+ const Justify justifyContent = flexLine.layout.remainingFreeSpace >= 0
1036
+ ? node->style().justifyContent()
1037
+ : fallbackAlignment(node->style().justifyContent());
1038
+
1039
+ if (flexLine.numberOfAutoMargins == 0) {
1040
+ switch (justifyContent) {
1041
+ case Justify::Center:
1042
+ leadingMainDim = flexLine.layout.remainingFreeSpace / 2;
1043
+ break;
1044
+ case Justify::FlexEnd:
1045
+ leadingMainDim = flexLine.layout.remainingFreeSpace;
1046
+ break;
1047
+ case Justify::SpaceBetween:
1048
+ if (flexLine.itemsInFlow.size() > 1) {
1049
+ betweenMainDim += flexLine.layout.remainingFreeSpace /
1050
+ static_cast<float>(flexLine.itemsInFlow.size() - 1);
1051
+ }
1052
+ break;
1053
+ case Justify::SpaceEvenly:
1054
+ // Space is distributed evenly across all elements
1055
+ leadingMainDim = flexLine.layout.remainingFreeSpace /
1056
+ static_cast<float>(flexLine.itemsInFlow.size() + 1);
1057
+ betweenMainDim += leadingMainDim;
1058
+ break;
1059
+ case Justify::SpaceAround:
1060
+ // Space on the edges is half of the space between elements
1061
+ leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace /
1062
+ static_cast<float>(flexLine.itemsInFlow.size());
1063
+ betweenMainDim += leadingMainDim * 2;
1064
+ break;
1065
+ case Justify::FlexStart:
1066
+ break;
1067
+ }
1068
+ }
1069
+
1070
+ flexLine.layout.mainDim = leadingPaddingAndBorderMain + leadingMainDim;
1071
+ flexLine.layout.crossDim = 0;
1072
+
1073
+ float maxAscentForCurrentLine = 0;
1074
+ float maxDescentForCurrentLine = 0;
1075
+ bool isNodeBaselineLayout = isBaselineLayout(node);
1076
+ for (auto child : flexLine.itemsInFlow) {
1077
+ const LayoutResults& childLayout = child->getLayout();
1078
+ if (child->style().flexStartMarginIsAuto(mainAxis, direction) &&
1079
+ flexLine.layout.remainingFreeSpace > 0.0f) {
1080
+ flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
1081
+ static_cast<float>(flexLine.numberOfAutoMargins);
1082
+ }
1083
+
1084
+ if (performLayout) {
1085
+ child->setLayoutPosition(
1086
+ childLayout.position(flexStartEdge(mainAxis)) +
1087
+ flexLine.layout.mainDim,
1088
+ flexStartEdge(mainAxis));
1089
+ }
1090
+
1091
+ if (child != flexLine.itemsInFlow.back()) {
1092
+ flexLine.layout.mainDim += betweenMainDim;
1093
+ }
1094
+
1095
+ if (child->style().flexEndMarginIsAuto(mainAxis, direction) &&
1096
+ flexLine.layout.remainingFreeSpace > 0.0f) {
1097
+ flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace /
1098
+ static_cast<float>(flexLine.numberOfAutoMargins);
1099
+ }
1100
+ bool canSkipFlex =
1101
+ !performLayout && sizingModeCrossDim == SizingMode::StretchFit;
1102
+ if (canSkipFlex) {
1103
+ // If we skipped the flex step, then we can't rely on the measuredDims
1104
+ // because they weren't computed. This means we can't call
1105
+ // dimensionWithMargin.
1106
+ flexLine.layout.mainDim +=
1107
+ child->style().computeMarginForAxis(mainAxis, availableInnerWidth) +
1108
+ childLayout.computedFlexBasis.unwrap();
1109
+ flexLine.layout.crossDim = availableInnerCrossDim;
1110
+ } else {
1111
+ // The main dimension is the sum of all the elements dimension plus
1112
+ // the spacing.
1113
+ flexLine.layout.mainDim +=
1114
+ child->dimensionWithMargin(mainAxis, availableInnerWidth);
1115
+
1116
+ if (isNodeBaselineLayout) {
1117
+ // If the child is baseline aligned then the cross dimension is
1118
+ // calculated by adding maxAscent and maxDescent from the baseline.
1119
+ const float ascent = calculateBaseline(child) +
1120
+ child->style().computeFlexStartMargin(
1121
+ FlexDirection::Column, direction, availableInnerWidth);
1122
+ const float descent =
1123
+ child->getLayout().measuredDimension(Dimension::Height) +
1124
+ child->style().computeMarginForAxis(
1125
+ FlexDirection::Column, availableInnerWidth) -
1126
+ ascent;
1127
+
1128
+ maxAscentForCurrentLine =
1129
+ yoga::maxOrDefined(maxAscentForCurrentLine, ascent);
1130
+ maxDescentForCurrentLine =
1131
+ yoga::maxOrDefined(maxDescentForCurrentLine, descent);
1132
+ } else {
1133
+ // The cross dimension is the max of the elements dimension since
1134
+ // there can only be one element in that cross dimension in the case
1135
+ // when the items are not baseline aligned
1136
+ flexLine.layout.crossDim = yoga::maxOrDefined(
1137
+ flexLine.layout.crossDim,
1138
+ child->dimensionWithMargin(crossAxis, availableInnerWidth));
1139
+ }
1140
+ }
1141
+ }
1142
+ flexLine.layout.mainDim += trailingPaddingAndBorderMain;
1143
+
1144
+ if (isNodeBaselineLayout) {
1145
+ flexLine.layout.crossDim =
1146
+ maxAscentForCurrentLine + maxDescentForCurrentLine;
1147
+ }
1148
+ }
1149
+
1150
+ //
1151
+ // This is the main routine that implements a subset of the flexbox layout
1152
+ // algorithm described in the W3C CSS documentation:
1153
+ // https://www.w3.org/TR/CSS3-flexbox/.
1154
+ //
1155
+ // Limitations of this algorithm, compared to the full standard:
1156
+ // * Display property is always assumed to be 'flex' except for Text nodes,
1157
+ // which are assumed to be 'inline-flex'.
1158
+ // * The 'zIndex' property (or any form of z ordering) is not supported. Nodes
1159
+ // are stacked in document order.
1160
+ // * The 'order' property is not supported. The order of flex items is always
1161
+ // defined by document order.
1162
+ // * The 'visibility' property is always assumed to be 'visible'. Values of
1163
+ // 'collapse' and 'hidden' are not supported.
1164
+ // * There is no support for forced breaks.
1165
+ // * It does not support vertical inline directions (top-to-bottom or
1166
+ // bottom-to-top text).
1167
+ //
1168
+ // Deviations from standard:
1169
+ // * Section 4.5 of the spec indicates that all flex items have a default
1170
+ // minimum main size. For text blocks, for example, this is the width of the
1171
+ // widest word. Calculating the minimum width is expensive, so we forego it
1172
+ // and assume a default minimum main size of 0.
1173
+ // * Min/Max sizes in the main axis are not honored when resolving flexible
1174
+ // lengths.
1175
+ // * The spec indicates that the default value for 'flexDirection' is 'row',
1176
+ // but the algorithm below assumes a default of 'column'.
1177
+ //
1178
+ // Input parameters:
1179
+ // - node: current node to be sized and laid out
1180
+ // - availableWidth & availableHeight: available size to be used for sizing
1181
+ // the node or YGUndefined if the size is not available; interpretation
1182
+ // depends on layout flags
1183
+ // - ownerDirection: the inline (text) direction within the owner
1184
+ // (left-to-right or right-to-left)
1185
+ // - widthSizingMode: indicates the sizing rules for the width (see below
1186
+ // for explanation)
1187
+ // - heightSizingMode: indicates the sizing rules for the height (see below
1188
+ // for explanation)
1189
+ // - performLayout: specifies whether the caller is interested in just the
1190
+ // dimensions of the node or it requires the entire node and its subtree to
1191
+ // be laid out (with final positions)
1192
+ //
1193
+ // Details:
1194
+ // This routine is called recursively to lay out subtrees of flexbox
1195
+ // elements. It uses the information in node.style, which is treated as a
1196
+ // read-only input. It is responsible for setting the layout.direction and
1197
+ // layout.measuredDimensions fields for the input node as well as the
1198
+ // layout.position and layout.lineIndex fields for its child nodes. The
1199
+ // layout.measuredDimensions field includes any border or padding for the
1200
+ // node but does not include margins.
1201
+ //
1202
+ // When calling calculateLayoutImpl and calculateLayoutInternal, if the
1203
+ // caller passes an available size of undefined then it must also pass a
1204
+ // measure mode of SizingMode::MaxContent in that dimension.
1205
+ //
1206
+ static void calculateLayoutImpl(
1207
+ yoga::Node* const node,
1208
+ const float availableWidth,
1209
+ const float availableHeight,
1210
+ const Direction ownerDirection,
1211
+ const SizingMode widthSizingMode,
1212
+ const SizingMode heightSizingMode,
1213
+ const float ownerWidth,
1214
+ const float ownerHeight,
1215
+ const bool performLayout,
1216
+ LayoutData& layoutMarkerData,
1217
+ const uint32_t depth,
1218
+ const uint32_t generationCount,
1219
+ const LayoutPassReason reason) {
1220
+ yoga::assertFatalWithNode(
1221
+ node,
1222
+ yoga::isUndefined(availableWidth)
1223
+ ? widthSizingMode == SizingMode::MaxContent
1224
+ : true,
1225
+ "availableWidth is indefinite so widthSizingMode must be "
1226
+ "SizingMode::MaxContent");
1227
+ yoga::assertFatalWithNode(
1228
+ node,
1229
+ yoga::isUndefined(availableHeight)
1230
+ ? heightSizingMode == SizingMode::MaxContent
1231
+ : true,
1232
+ "availableHeight is indefinite so heightSizingMode must be "
1233
+ "SizingMode::MaxContent");
1234
+
1235
+ (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1;
1236
+
1237
+ // Set the resolved resolution in the node's layout.
1238
+ const Direction direction = node->resolveDirection(ownerDirection);
1239
+ node->setLayoutDirection(direction);
1240
+
1241
+ const FlexDirection flexRowDirection =
1242
+ resolveDirection(FlexDirection::Row, direction);
1243
+ const FlexDirection flexColumnDirection =
1244
+ resolveDirection(FlexDirection::Column, direction);
1245
+
1246
+ const auto startEdge =
1247
+ direction == Direction::LTR ? PhysicalEdge::Left : PhysicalEdge::Right;
1248
+ const auto endEdge =
1249
+ direction == Direction::LTR ? PhysicalEdge::Right : PhysicalEdge::Left;
1250
+
1251
+ const float marginRowLeading = node->style().computeInlineStartMargin(
1252
+ flexRowDirection, direction, ownerWidth);
1253
+ node->setLayoutMargin(marginRowLeading, startEdge);
1254
+ const float marginRowTrailing = node->style().computeInlineEndMargin(
1255
+ flexRowDirection, direction, ownerWidth);
1256
+ node->setLayoutMargin(marginRowTrailing, endEdge);
1257
+ const float marginColumnLeading = node->style().computeInlineStartMargin(
1258
+ flexColumnDirection, direction, ownerWidth);
1259
+ node->setLayoutMargin(marginColumnLeading, PhysicalEdge::Top);
1260
+ const float marginColumnTrailing = node->style().computeInlineEndMargin(
1261
+ flexColumnDirection, direction, ownerWidth);
1262
+ node->setLayoutMargin(marginColumnTrailing, PhysicalEdge::Bottom);
1263
+
1264
+ const float marginAxisRow = marginRowLeading + marginRowTrailing;
1265
+ const float marginAxisColumn = marginColumnLeading + marginColumnTrailing;
1266
+
1267
+ node->setLayoutBorder(
1268
+ node->style().computeInlineStartBorder(flexRowDirection, direction),
1269
+ startEdge);
1270
+ node->setLayoutBorder(
1271
+ node->style().computeInlineEndBorder(flexRowDirection, direction),
1272
+ endEdge);
1273
+ node->setLayoutBorder(
1274
+ node->style().computeInlineStartBorder(flexColumnDirection, direction),
1275
+ PhysicalEdge::Top);
1276
+ node->setLayoutBorder(
1277
+ node->style().computeInlineEndBorder(flexColumnDirection, direction),
1278
+ PhysicalEdge::Bottom);
1279
+
1280
+ node->setLayoutPadding(
1281
+ node->style().computeInlineStartPadding(
1282
+ flexRowDirection, direction, ownerWidth),
1283
+ startEdge);
1284
+ node->setLayoutPadding(
1285
+ node->style().computeInlineEndPadding(
1286
+ flexRowDirection, direction, ownerWidth),
1287
+ endEdge);
1288
+ node->setLayoutPadding(
1289
+ node->style().computeInlineStartPadding(
1290
+ flexColumnDirection, direction, ownerWidth),
1291
+ PhysicalEdge::Top);
1292
+ node->setLayoutPadding(
1293
+ node->style().computeInlineEndPadding(
1294
+ flexColumnDirection, direction, ownerWidth),
1295
+ PhysicalEdge::Bottom);
1296
+
1297
+ if (node->hasMeasureFunc()) {
1298
+ measureNodeWithMeasureFunc(
1299
+ node,
1300
+ direction,
1301
+ availableWidth - marginAxisRow,
1302
+ availableHeight - marginAxisColumn,
1303
+ widthSizingMode,
1304
+ heightSizingMode,
1305
+ ownerWidth,
1306
+ ownerHeight,
1307
+ layoutMarkerData,
1308
+ reason);
1309
+
1310
+ // Clean and update all display: contents nodes with a direct path to the
1311
+ // current node as they will not be traversed
1312
+ cleanupContentsNodesRecursively(node);
1313
+ return;
1314
+ }
1315
+
1316
+ const auto childCount = node->getLayoutChildCount();
1317
+ if (childCount == 0) {
1318
+ measureNodeWithoutChildren(
1319
+ node,
1320
+ direction,
1321
+ availableWidth - marginAxisRow,
1322
+ availableHeight - marginAxisColumn,
1323
+ widthSizingMode,
1324
+ heightSizingMode,
1325
+ ownerWidth,
1326
+ ownerHeight);
1327
+
1328
+ // Clean and update all display: contents nodes with a direct path to the
1329
+ // current node as they will not be traversed
1330
+ cleanupContentsNodesRecursively(node);
1331
+ return;
1332
+ }
1333
+
1334
+ // If we're not being asked to perform a full layout we can skip the algorithm
1335
+ // if we already know the size
1336
+ if (!performLayout &&
1337
+ measureNodeWithFixedSize(
1338
+ node,
1339
+ direction,
1340
+ availableWidth - marginAxisRow,
1341
+ availableHeight - marginAxisColumn,
1342
+ widthSizingMode,
1343
+ heightSizingMode,
1344
+ ownerWidth,
1345
+ ownerHeight)) {
1346
+ // Clean and update all display: contents nodes with a direct path to the
1347
+ // current node as they will not be traversed
1348
+ cleanupContentsNodesRecursively(node);
1349
+ return;
1350
+ }
1351
+
1352
+ // At this point we know we're going to perform work. Ensure that each child
1353
+ // has a mutable copy.
1354
+ node->cloneChildrenIfNeeded();
1355
+ // Reset layout flags, as they could have changed.
1356
+ node->setLayoutHadOverflow(false);
1357
+
1358
+ // Clean and update all display: contents nodes with a direct path to the
1359
+ // current node as they will not be traversed
1360
+ cleanupContentsNodesRecursively(node);
1361
+
1362
+ // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM
1363
+ const FlexDirection mainAxis =
1364
+ resolveDirection(node->style().flexDirection(), direction);
1365
+ const FlexDirection crossAxis = resolveCrossDirection(mainAxis, direction);
1366
+ const bool isMainAxisRow = isRow(mainAxis);
1367
+ const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap;
1368
+
1369
+ const float mainAxisOwnerSize = isMainAxisRow ? ownerWidth : ownerHeight;
1370
+ const float crossAxisOwnerSize = isMainAxisRow ? ownerHeight : ownerWidth;
1371
+
1372
+ const float paddingAndBorderAxisMain =
1373
+ paddingAndBorderForAxis(node, mainAxis, direction, ownerWidth);
1374
+ const float paddingAndBorderAxisCross =
1375
+ paddingAndBorderForAxis(node, crossAxis, direction, ownerWidth);
1376
+ const float leadingPaddingAndBorderCross =
1377
+ node->style().computeFlexStartPaddingAndBorder(
1378
+ crossAxis, direction, ownerWidth);
1379
+
1380
+ SizingMode sizingModeMainDim =
1381
+ isMainAxisRow ? widthSizingMode : heightSizingMode;
1382
+ SizingMode sizingModeCrossDim =
1383
+ isMainAxisRow ? heightSizingMode : widthSizingMode;
1384
+
1385
+ const float paddingAndBorderAxisRow =
1386
+ isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross;
1387
+ const float paddingAndBorderAxisColumn =
1388
+ isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
1389
+
1390
+ // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
1391
+
1392
+ float availableInnerWidth = calculateAvailableInnerDimension(
1393
+ node,
1394
+ direction,
1395
+ Dimension::Width,
1396
+ availableWidth - marginAxisRow,
1397
+ paddingAndBorderAxisRow,
1398
+ ownerWidth,
1399
+ ownerWidth);
1400
+ float availableInnerHeight = calculateAvailableInnerDimension(
1401
+ node,
1402
+ direction,
1403
+ Dimension::Height,
1404
+ availableHeight - marginAxisColumn,
1405
+ paddingAndBorderAxisColumn,
1406
+ ownerHeight,
1407
+ ownerWidth);
1408
+
1409
+ float availableInnerMainDim =
1410
+ isMainAxisRow ? availableInnerWidth : availableInnerHeight;
1411
+ const float availableInnerCrossDim =
1412
+ isMainAxisRow ? availableInnerHeight : availableInnerWidth;
1413
+
1414
+ // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
1415
+
1416
+ // Computed basis + margins + gap
1417
+ float totalMainDim = 0;
1418
+ totalMainDim += computeFlexBasisForChildren(
1419
+ node,
1420
+ availableInnerWidth,
1421
+ availableInnerHeight,
1422
+ widthSizingMode,
1423
+ heightSizingMode,
1424
+ direction,
1425
+ mainAxis,
1426
+ performLayout,
1427
+ layoutMarkerData,
1428
+ depth,
1429
+ generationCount);
1430
+
1431
+ if (childCount > 1) {
1432
+ totalMainDim +=
1433
+ node->style().computeGapForAxis(mainAxis, availableInnerMainDim) *
1434
+ static_cast<float>(childCount - 1);
1435
+ }
1436
+
1437
+ const bool mainAxisOverflows =
1438
+ (sizingModeMainDim != SizingMode::MaxContent) &&
1439
+ totalMainDim > availableInnerMainDim;
1440
+
1441
+ if (isNodeFlexWrap && mainAxisOverflows &&
1442
+ sizingModeMainDim == SizingMode::FitContent) {
1443
+ sizingModeMainDim = SizingMode::StretchFit;
1444
+ }
1445
+ // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES
1446
+
1447
+ // Iterator representing the beginning of the current line
1448
+ Node::LayoutableChildren::Iterator startOfLineIterator =
1449
+ node->getLayoutChildren().begin();
1450
+
1451
+ // Number of lines.
1452
+ size_t lineCount = 0;
1453
+
1454
+ // Accumulated cross dimensions of all lines so far.
1455
+ float totalLineCrossDim = 0;
1456
+
1457
+ const float crossAxisGap =
1458
+ node->style().computeGapForAxis(crossAxis, availableInnerCrossDim);
1459
+
1460
+ // Max main dimension of all the lines.
1461
+ float maxLineMainDim = 0;
1462
+ for (; startOfLineIterator != node->getLayoutChildren().end(); lineCount++) {
1463
+ auto flexLine = calculateFlexLine(
1464
+ node,
1465
+ ownerDirection,
1466
+ ownerWidth,
1467
+ mainAxisOwnerSize,
1468
+ availableInnerWidth,
1469
+ availableInnerMainDim,
1470
+ startOfLineIterator,
1471
+ lineCount);
1472
+
1473
+ // If we don't need to measure the cross axis, we can skip the entire flex
1474
+ // step.
1475
+ const bool canSkipFlex =
1476
+ !performLayout && sizingModeCrossDim == SizingMode::StretchFit;
1477
+
1478
+ // STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS
1479
+ // Calculate the remaining available space that needs to be allocated. If
1480
+ // the main dimension size isn't known, it is computed based on the line
1481
+ // length, so there's no more space left to distribute.
1482
+
1483
+ bool sizeBasedOnContent = false;
1484
+ // If we don't measure with exact main dimension we want to ensure we don't
1485
+ // violate min and max
1486
+ if (sizingModeMainDim != SizingMode::StretchFit) {
1487
+ const auto& style = node->style();
1488
+ const float minInnerWidth =
1489
+ style
1490
+ .resolvedMinDimension(
1491
+ direction, Dimension::Width, ownerWidth, ownerWidth)
1492
+ .unwrap() -
1493
+ paddingAndBorderAxisRow;
1494
+ const float maxInnerWidth =
1495
+ style
1496
+ .resolvedMaxDimension(
1497
+ direction, Dimension::Width, ownerWidth, ownerWidth)
1498
+ .unwrap() -
1499
+ paddingAndBorderAxisRow;
1500
+ const float minInnerHeight =
1501
+ style
1502
+ .resolvedMinDimension(
1503
+ direction, Dimension::Height, ownerHeight, ownerWidth)
1504
+ .unwrap() -
1505
+ paddingAndBorderAxisColumn;
1506
+ const float maxInnerHeight =
1507
+ style
1508
+ .resolvedMaxDimension(
1509
+ direction, Dimension::Height, ownerHeight, ownerWidth)
1510
+ .unwrap() -
1511
+ paddingAndBorderAxisColumn;
1512
+
1513
+ const float minInnerMainDim =
1514
+ isMainAxisRow ? minInnerWidth : minInnerHeight;
1515
+ const float maxInnerMainDim =
1516
+ isMainAxisRow ? maxInnerWidth : maxInnerHeight;
1517
+
1518
+ if (yoga::isDefined(minInnerMainDim) &&
1519
+ flexLine.sizeConsumed < minInnerMainDim) {
1520
+ availableInnerMainDim = minInnerMainDim;
1521
+ } else if (
1522
+ yoga::isDefined(maxInnerMainDim) &&
1523
+ flexLine.sizeConsumed > maxInnerMainDim) {
1524
+ availableInnerMainDim = maxInnerMainDim;
1525
+ } else {
1526
+ bool useLegacyStretchBehaviour =
1527
+ node->hasErrata(Errata::StretchFlexBasis);
1528
+
1529
+ if (!useLegacyStretchBehaviour &&
1530
+ ((yoga::isDefined(flexLine.layout.totalFlexGrowFactors) &&
1531
+ flexLine.layout.totalFlexGrowFactors == 0) ||
1532
+ (yoga::isDefined(node->resolveFlexGrow()) &&
1533
+ node->resolveFlexGrow() == 0))) {
1534
+ // If we don't have any children to flex or we can't flex the node
1535
+ // itself, space we've used is all space we need. Root node also
1536
+ // should be shrunk to minimum
1537
+ availableInnerMainDim = flexLine.sizeConsumed;
1538
+ }
1539
+
1540
+ sizeBasedOnContent = !useLegacyStretchBehaviour;
1541
+ }
1542
+ }
1543
+
1544
+ if (!sizeBasedOnContent && yoga::isDefined(availableInnerMainDim)) {
1545
+ flexLine.layout.remainingFreeSpace =
1546
+ availableInnerMainDim - flexLine.sizeConsumed;
1547
+ } else if (flexLine.sizeConsumed < 0) {
1548
+ // availableInnerMainDim is indefinite which means the node is being sized
1549
+ // based on its content. sizeConsumed is negative which means
1550
+ // the node will allocate 0 points for its content. Consequently,
1551
+ // remainingFreeSpace is 0 - sizeConsumed.
1552
+ flexLine.layout.remainingFreeSpace = -flexLine.sizeConsumed;
1553
+ }
1554
+
1555
+ if (!canSkipFlex) {
1556
+ resolveFlexibleLength(
1557
+ node,
1558
+ flexLine,
1559
+ mainAxis,
1560
+ crossAxis,
1561
+ direction,
1562
+ ownerWidth,
1563
+ mainAxisOwnerSize,
1564
+ availableInnerMainDim,
1565
+ availableInnerCrossDim,
1566
+ availableInnerWidth,
1567
+ availableInnerHeight,
1568
+ mainAxisOverflows,
1569
+ sizingModeCrossDim,
1570
+ performLayout,
1571
+ layoutMarkerData,
1572
+ depth,
1573
+ generationCount);
1574
+ }
1575
+
1576
+ node->setLayoutHadOverflow(
1577
+ node->getLayout().hadOverflow() ||
1578
+ (flexLine.layout.remainingFreeSpace < 0));
1579
+
1580
+ // STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION
1581
+
1582
+ // At this point, all the children have their dimensions set in the main
1583
+ // axis. Their dimensions are also set in the cross axis with the exception
1584
+ // of items that are aligned "stretch". We need to compute these stretch
1585
+ // values and set the final positions.
1586
+
1587
+ justifyMainAxis(
1588
+ node,
1589
+ flexLine,
1590
+ mainAxis,
1591
+ crossAxis,
1592
+ direction,
1593
+ sizingModeMainDim,
1594
+ sizingModeCrossDim,
1595
+ mainAxisOwnerSize,
1596
+ ownerWidth,
1597
+ availableInnerMainDim,
1598
+ availableInnerCrossDim,
1599
+ availableInnerWidth,
1600
+ performLayout);
1601
+
1602
+ float containerCrossAxis = availableInnerCrossDim;
1603
+ if (sizingModeCrossDim == SizingMode::MaxContent ||
1604
+ sizingModeCrossDim == SizingMode::FitContent) {
1605
+ // Compute the cross axis from the max cross dimension of the children.
1606
+ containerCrossAxis =
1607
+ boundAxis(
1608
+ node,
1609
+ crossAxis,
1610
+ direction,
1611
+ flexLine.layout.crossDim + paddingAndBorderAxisCross,
1612
+ crossAxisOwnerSize,
1613
+ ownerWidth) -
1614
+ paddingAndBorderAxisCross;
1615
+ }
1616
+
1617
+ // If there's no flex wrap, the cross dimension is defined by the container.
1618
+ if (!isNodeFlexWrap && sizingModeCrossDim == SizingMode::StretchFit) {
1619
+ flexLine.layout.crossDim = availableInnerCrossDim;
1620
+ }
1621
+
1622
+ // As-per https://www.w3.org/TR/css-flexbox-1/#cross-sizing, the
1623
+ // cross-size of the line within a single-line container should be bound to
1624
+ // min/max constraints before alignment within the line. In a multi-line
1625
+ // container, affecting alignment between the lines.
1626
+ if (!isNodeFlexWrap) {
1627
+ flexLine.layout.crossDim =
1628
+ boundAxis(
1629
+ node,
1630
+ crossAxis,
1631
+ direction,
1632
+ flexLine.layout.crossDim + paddingAndBorderAxisCross,
1633
+ crossAxisOwnerSize,
1634
+ ownerWidth) -
1635
+ paddingAndBorderAxisCross;
1636
+ }
1637
+
1638
+ // STEP 7: CROSS-AXIS ALIGNMENT
1639
+ // We can skip child alignment if we're just measuring the container.
1640
+ if (performLayout) {
1641
+ for (auto child : flexLine.itemsInFlow) {
1642
+ float leadingCrossDim = leadingPaddingAndBorderCross;
1643
+
1644
+ // For a relative children, we're either using alignItems (owner) or
1645
+ // alignSelf (child) in order to determine the position in the cross
1646
+ // axis
1647
+ const Align alignItem = resolveChildAlignment(node, child);
1648
+
1649
+ // If the child uses align stretch, we need to lay it out one more
1650
+ // time, this time forcing the cross-axis size to be the computed
1651
+ // cross size for the current line.
1652
+ if (alignItem == Align::Stretch &&
1653
+ !child->style().flexStartMarginIsAuto(crossAxis, direction) &&
1654
+ !child->style().flexEndMarginIsAuto(crossAxis, direction)) {
1655
+ // If the child defines a definite size for its cross axis, there's
1656
+ // no need to stretch.
1657
+ if (!child->hasDefiniteLength(
1658
+ dimension(crossAxis), availableInnerCrossDim)) {
1659
+ float childMainSize =
1660
+ child->getLayout().measuredDimension(dimension(mainAxis));
1661
+ const auto& childStyle = child->style();
1662
+ float childCrossSize = childStyle.aspectRatio().isDefined()
1663
+ ? child->style().computeMarginForAxis(
1664
+ crossAxis, availableInnerWidth) +
1665
+ (isMainAxisRow
1666
+ ? childMainSize / childStyle.aspectRatio().unwrap()
1667
+ : childMainSize * childStyle.aspectRatio().unwrap())
1668
+ : flexLine.layout.crossDim;
1669
+
1670
+ childMainSize += child->style().computeMarginForAxis(
1671
+ mainAxis, availableInnerWidth);
1672
+
1673
+ SizingMode childMainSizingMode = SizingMode::StretchFit;
1674
+ SizingMode childCrossSizingMode = SizingMode::StretchFit;
1675
+ constrainMaxSizeForMode(
1676
+ child,
1677
+ direction,
1678
+ mainAxis,
1679
+ availableInnerMainDim,
1680
+ availableInnerWidth,
1681
+ &childMainSizingMode,
1682
+ &childMainSize);
1683
+ constrainMaxSizeForMode(
1684
+ child,
1685
+ direction,
1686
+ crossAxis,
1687
+ availableInnerCrossDim,
1688
+ availableInnerWidth,
1689
+ &childCrossSizingMode,
1690
+ &childCrossSize);
1691
+
1692
+ const float childWidth =
1693
+ isMainAxisRow ? childMainSize : childCrossSize;
1694
+ const float childHeight =
1695
+ !isMainAxisRow ? childMainSize : childCrossSize;
1696
+
1697
+ auto alignContent = node->style().alignContent();
1698
+ auto crossAxisDoesNotGrow =
1699
+ alignContent != Align::Stretch && isNodeFlexWrap;
1700
+ const SizingMode childWidthSizingMode =
1701
+ yoga::isUndefined(childWidth) ||
1702
+ (!isMainAxisRow && crossAxisDoesNotGrow)
1703
+ ? SizingMode::MaxContent
1704
+ : SizingMode::StretchFit;
1705
+ const SizingMode childHeightSizingMode =
1706
+ yoga::isUndefined(childHeight) ||
1707
+ (isMainAxisRow && crossAxisDoesNotGrow)
1708
+ ? SizingMode::MaxContent
1709
+ : SizingMode::StretchFit;
1710
+
1711
+ calculateLayoutInternal(
1712
+ child,
1713
+ childWidth,
1714
+ childHeight,
1715
+ direction,
1716
+ childWidthSizingMode,
1717
+ childHeightSizingMode,
1718
+ availableInnerWidth,
1719
+ availableInnerHeight,
1720
+ true,
1721
+ LayoutPassReason::kStretch,
1722
+ layoutMarkerData,
1723
+ depth,
1724
+ generationCount);
1725
+ }
1726
+ } else {
1727
+ const float remainingCrossDim = containerCrossAxis -
1728
+ child->dimensionWithMargin(crossAxis, availableInnerWidth);
1729
+
1730
+ if (child->style().flexStartMarginIsAuto(crossAxis, direction) &&
1731
+ child->style().flexEndMarginIsAuto(crossAxis, direction)) {
1732
+ leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim / 2);
1733
+ } else if (child->style().flexEndMarginIsAuto(crossAxis, direction)) {
1734
+ // No-Op
1735
+ } else if (child->style().flexStartMarginIsAuto(
1736
+ crossAxis, direction)) {
1737
+ leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim);
1738
+ } else if (alignItem == Align::FlexStart) {
1739
+ // No-Op
1740
+ } else if (alignItem == Align::Center) {
1741
+ leadingCrossDim += remainingCrossDim / 2;
1742
+ } else {
1743
+ leadingCrossDim += remainingCrossDim;
1744
+ }
1745
+ }
1746
+ // And we apply the position
1747
+ child->setLayoutPosition(
1748
+ child->getLayout().position(flexStartEdge(crossAxis)) +
1749
+ totalLineCrossDim + leadingCrossDim,
1750
+ flexStartEdge(crossAxis));
1751
+ }
1752
+ }
1753
+
1754
+ const float appliedCrossGap = lineCount != 0 ? crossAxisGap : 0.0f;
1755
+ totalLineCrossDim += flexLine.layout.crossDim + appliedCrossGap;
1756
+ maxLineMainDim =
1757
+ yoga::maxOrDefined(maxLineMainDim, flexLine.layout.mainDim);
1758
+ }
1759
+
1760
+ // STEP 8: MULTI-LINE CONTENT ALIGNMENT
1761
+ // currentLead stores the size of the cross dim
1762
+ if (performLayout && (isNodeFlexWrap || isBaselineLayout(node))) {
1763
+ float leadPerLine = 0;
1764
+ float currentLead = leadingPaddingAndBorderCross;
1765
+ float extraSpacePerLine = 0;
1766
+
1767
+ const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
1768
+ ? availableInnerCrossDim + paddingAndBorderAxisCross
1769
+ : node->hasDefiniteLength(dimension(crossAxis), crossAxisOwnerSize)
1770
+ ? node->getResolvedDimension(
1771
+ direction,
1772
+ dimension(crossAxis),
1773
+ crossAxisOwnerSize,
1774
+ ownerWidth)
1775
+ .unwrap()
1776
+ : totalLineCrossDim + paddingAndBorderAxisCross;
1777
+
1778
+ const float innerCrossDim = boundAxis(
1779
+ node,
1780
+ crossAxis,
1781
+ direction,
1782
+ unclampedCrossDim,
1783
+ ownerHeight,
1784
+ ownerWidth) -
1785
+ paddingAndBorderAxisCross;
1786
+
1787
+ const float remainingAlignContentDim = innerCrossDim - totalLineCrossDim;
1788
+
1789
+ const auto alignContent = remainingAlignContentDim >= 0
1790
+ ? node->style().alignContent()
1791
+ : fallbackAlignment(node->style().alignContent());
1792
+
1793
+ switch (alignContent) {
1794
+ case Align::FlexEnd:
1795
+ currentLead += remainingAlignContentDim;
1796
+ break;
1797
+ case Align::Center:
1798
+ currentLead += remainingAlignContentDim / 2;
1799
+ break;
1800
+ case Align::Stretch:
1801
+ extraSpacePerLine =
1802
+ remainingAlignContentDim / static_cast<float>(lineCount);
1803
+ break;
1804
+ case Align::SpaceAround:
1805
+ currentLead +=
1806
+ remainingAlignContentDim / (2 * static_cast<float>(lineCount));
1807
+ leadPerLine = remainingAlignContentDim / static_cast<float>(lineCount);
1808
+ break;
1809
+ case Align::SpaceEvenly:
1810
+ currentLead +=
1811
+ remainingAlignContentDim / static_cast<float>(lineCount + 1);
1812
+ leadPerLine =
1813
+ remainingAlignContentDim / static_cast<float>(lineCount + 1);
1814
+ break;
1815
+ case Align::SpaceBetween:
1816
+ if (lineCount > 1) {
1817
+ leadPerLine =
1818
+ remainingAlignContentDim / static_cast<float>(lineCount - 1);
1819
+ }
1820
+ break;
1821
+ case Align::Auto:
1822
+ case Align::FlexStart:
1823
+ case Align::Baseline:
1824
+ break;
1825
+ }
1826
+ Node::LayoutableChildren::Iterator endIterator =
1827
+ node->getLayoutChildren().begin();
1828
+ for (size_t i = 0; i < lineCount; i++) {
1829
+ const Node::LayoutableChildren::Iterator startIterator = endIterator;
1830
+ auto iterator = startIterator;
1831
+
1832
+ // compute the line's height and find the endIndex
1833
+ float lineHeight = 0;
1834
+ float maxAscentForCurrentLine = 0;
1835
+ float maxDescentForCurrentLine = 0;
1836
+ for (; iterator != node->getLayoutChildren().end(); iterator++) {
1837
+ const auto child = *iterator;
1838
+ if (child->style().display() == Display::None) {
1839
+ continue;
1840
+ }
1841
+ if (child->style().positionType() != PositionType::Absolute) {
1842
+ if (child->getLineIndex() != i) {
1843
+ break;
1844
+ }
1845
+ if (child->isLayoutDimensionDefined(crossAxis)) {
1846
+ lineHeight = yoga::maxOrDefined(
1847
+ lineHeight,
1848
+ child->getLayout().measuredDimension(dimension(crossAxis)) +
1849
+ child->style().computeMarginForAxis(
1850
+ crossAxis, availableInnerWidth));
1851
+ }
1852
+ if (resolveChildAlignment(node, child) == Align::Baseline) {
1853
+ const float ascent = calculateBaseline(child) +
1854
+ child->style().computeFlexStartMargin(
1855
+ FlexDirection::Column, direction, availableInnerWidth);
1856
+ const float descent =
1857
+ child->getLayout().measuredDimension(Dimension::Height) +
1858
+ child->style().computeMarginForAxis(
1859
+ FlexDirection::Column, availableInnerWidth) -
1860
+ ascent;
1861
+ maxAscentForCurrentLine =
1862
+ yoga::maxOrDefined(maxAscentForCurrentLine, ascent);
1863
+ maxDescentForCurrentLine =
1864
+ yoga::maxOrDefined(maxDescentForCurrentLine, descent);
1865
+ lineHeight = yoga::maxOrDefined(
1866
+ lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine);
1867
+ }
1868
+ }
1869
+ }
1870
+ endIterator = iterator;
1871
+ currentLead += i != 0 ? crossAxisGap : 0;
1872
+ lineHeight += extraSpacePerLine;
1873
+
1874
+ for (iterator = startIterator; iterator != endIterator; iterator++) {
1875
+ const auto child = *iterator;
1876
+ if (child->style().display() == Display::None) {
1877
+ continue;
1878
+ }
1879
+ if (child->style().positionType() != PositionType::Absolute) {
1880
+ switch (resolveChildAlignment(node, child)) {
1881
+ case Align::FlexStart: {
1882
+ child->setLayoutPosition(
1883
+ currentLead +
1884
+ child->style().computeFlexStartPosition(
1885
+ crossAxis, direction, availableInnerWidth),
1886
+ flexStartEdge(crossAxis));
1887
+ break;
1888
+ }
1889
+ case Align::FlexEnd: {
1890
+ child->setLayoutPosition(
1891
+ currentLead + lineHeight -
1892
+ child->style().computeFlexEndMargin(
1893
+ crossAxis, direction, availableInnerWidth) -
1894
+ child->getLayout().measuredDimension(
1895
+ dimension(crossAxis)),
1896
+ flexStartEdge(crossAxis));
1897
+ break;
1898
+ }
1899
+ case Align::Center: {
1900
+ float childHeight =
1901
+ child->getLayout().measuredDimension(dimension(crossAxis));
1902
+
1903
+ child->setLayoutPosition(
1904
+ currentLead + (lineHeight - childHeight) / 2,
1905
+ flexStartEdge(crossAxis));
1906
+ break;
1907
+ }
1908
+ case Align::Stretch: {
1909
+ child->setLayoutPosition(
1910
+ currentLead +
1911
+ child->style().computeFlexStartMargin(
1912
+ crossAxis, direction, availableInnerWidth),
1913
+ flexStartEdge(crossAxis));
1914
+
1915
+ // Remeasure child with the line height as it as been only
1916
+ // measured with the owners height yet.
1917
+ if (!child->hasDefiniteLength(
1918
+ dimension(crossAxis), availableInnerCrossDim)) {
1919
+ const float childWidth = isMainAxisRow
1920
+ ? (child->getLayout().measuredDimension(Dimension::Width) +
1921
+ child->style().computeMarginForAxis(
1922
+ mainAxis, availableInnerWidth))
1923
+ : leadPerLine + lineHeight;
1924
+
1925
+ const float childHeight = !isMainAxisRow
1926
+ ? (child->getLayout().measuredDimension(Dimension::Height) +
1927
+ child->style().computeMarginForAxis(
1928
+ crossAxis, availableInnerWidth))
1929
+ : leadPerLine + lineHeight;
1930
+
1931
+ if (!(yoga::inexactEquals(
1932
+ childWidth,
1933
+ child->getLayout().measuredDimension(
1934
+ Dimension::Width)) &&
1935
+ yoga::inexactEquals(
1936
+ childHeight,
1937
+ child->getLayout().measuredDimension(
1938
+ Dimension::Height)))) {
1939
+ calculateLayoutInternal(
1940
+ child,
1941
+ childWidth,
1942
+ childHeight,
1943
+ direction,
1944
+ SizingMode::StretchFit,
1945
+ SizingMode::StretchFit,
1946
+ availableInnerWidth,
1947
+ availableInnerHeight,
1948
+ true,
1949
+ LayoutPassReason::kMultilineStretch,
1950
+ layoutMarkerData,
1951
+ depth,
1952
+ generationCount);
1953
+ }
1954
+ }
1955
+ break;
1956
+ }
1957
+ case Align::Baseline: {
1958
+ child->setLayoutPosition(
1959
+ currentLead + maxAscentForCurrentLine -
1960
+ calculateBaseline(child) +
1961
+ child->style().computeFlexStartPosition(
1962
+ FlexDirection::Column,
1963
+ direction,
1964
+ availableInnerCrossDim),
1965
+ PhysicalEdge::Top);
1966
+
1967
+ break;
1968
+ }
1969
+ case Align::Auto:
1970
+ case Align::SpaceBetween:
1971
+ case Align::SpaceAround:
1972
+ case Align::SpaceEvenly:
1973
+ break;
1974
+ }
1975
+ }
1976
+ }
1977
+
1978
+ currentLead = currentLead + leadPerLine + lineHeight;
1979
+ }
1980
+ }
1981
+
1982
+ // STEP 9: COMPUTING FINAL DIMENSIONS
1983
+
1984
+ node->setLayoutMeasuredDimension(
1985
+ boundAxis(
1986
+ node,
1987
+ FlexDirection::Row,
1988
+ direction,
1989
+ availableWidth - marginAxisRow,
1990
+ ownerWidth,
1991
+ ownerWidth),
1992
+ Dimension::Width);
1993
+
1994
+ node->setLayoutMeasuredDimension(
1995
+ boundAxis(
1996
+ node,
1997
+ FlexDirection::Column,
1998
+ direction,
1999
+ availableHeight - marginAxisColumn,
2000
+ ownerHeight,
2001
+ ownerWidth),
2002
+ Dimension::Height);
2003
+
2004
+ // If the user didn't specify a width or height for the node, set the
2005
+ // dimensions based on the children.
2006
+ if (sizingModeMainDim == SizingMode::MaxContent ||
2007
+ (node->style().overflow() != Overflow::Scroll &&
2008
+ sizingModeMainDim == SizingMode::FitContent)) {
2009
+ // Clamp the size to the min/max size, if specified, and make sure it
2010
+ // doesn't go below the padding and border amount.
2011
+ node->setLayoutMeasuredDimension(
2012
+ boundAxis(
2013
+ node,
2014
+ mainAxis,
2015
+ direction,
2016
+ maxLineMainDim,
2017
+ mainAxisOwnerSize,
2018
+ ownerWidth),
2019
+ dimension(mainAxis));
2020
+
2021
+ } else if (
2022
+ sizingModeMainDim == SizingMode::FitContent &&
2023
+ node->style().overflow() == Overflow::Scroll) {
2024
+ node->setLayoutMeasuredDimension(
2025
+ yoga::maxOrDefined(
2026
+ yoga::minOrDefined(
2027
+ availableInnerMainDim + paddingAndBorderAxisMain,
2028
+ boundAxisWithinMinAndMax(
2029
+ node,
2030
+ direction,
2031
+ mainAxis,
2032
+ FloatOptional{maxLineMainDim},
2033
+ mainAxisOwnerSize,
2034
+ ownerWidth)
2035
+ .unwrap()),
2036
+ paddingAndBorderAxisMain),
2037
+ dimension(mainAxis));
2038
+ }
2039
+
2040
+ if (sizingModeCrossDim == SizingMode::MaxContent ||
2041
+ (node->style().overflow() != Overflow::Scroll &&
2042
+ sizingModeCrossDim == SizingMode::FitContent)) {
2043
+ // Clamp the size to the min/max size, if specified, and make sure it
2044
+ // doesn't go below the padding and border amount.
2045
+ node->setLayoutMeasuredDimension(
2046
+ boundAxis(
2047
+ node,
2048
+ crossAxis,
2049
+ direction,
2050
+ totalLineCrossDim + paddingAndBorderAxisCross,
2051
+ crossAxisOwnerSize,
2052
+ ownerWidth),
2053
+ dimension(crossAxis));
2054
+
2055
+ } else if (
2056
+ sizingModeCrossDim == SizingMode::FitContent &&
2057
+ node->style().overflow() == Overflow::Scroll) {
2058
+ node->setLayoutMeasuredDimension(
2059
+ yoga::maxOrDefined(
2060
+ yoga::minOrDefined(
2061
+ availableInnerCrossDim + paddingAndBorderAxisCross,
2062
+ boundAxisWithinMinAndMax(
2063
+ node,
2064
+ direction,
2065
+ crossAxis,
2066
+ FloatOptional{
2067
+ totalLineCrossDim + paddingAndBorderAxisCross},
2068
+ crossAxisOwnerSize,
2069
+ ownerWidth)
2070
+ .unwrap()),
2071
+ paddingAndBorderAxisCross),
2072
+ dimension(crossAxis));
2073
+ }
2074
+
2075
+ // As we only wrapped in normal direction yet, we need to reverse the
2076
+ // positions on wrap-reverse.
2077
+ if (performLayout && node->style().flexWrap() == Wrap::WrapReverse) {
2078
+ for (auto child : node->getLayoutChildren()) {
2079
+ if (child->style().positionType() != PositionType::Absolute) {
2080
+ child->setLayoutPosition(
2081
+ node->getLayout().measuredDimension(dimension(crossAxis)) -
2082
+ child->getLayout().position(flexStartEdge(crossAxis)) -
2083
+ child->getLayout().measuredDimension(dimension(crossAxis)),
2084
+ flexStartEdge(crossAxis));
2085
+ }
2086
+ }
2087
+ }
2088
+
2089
+ if (performLayout) {
2090
+ // STEP 10: SETTING TRAILING POSITIONS FOR CHILDREN
2091
+ const bool needsMainTrailingPos = needsTrailingPosition(mainAxis);
2092
+ const bool needsCrossTrailingPos = needsTrailingPosition(crossAxis);
2093
+
2094
+ if (needsMainTrailingPos || needsCrossTrailingPos) {
2095
+ for (auto child : node->getLayoutChildren()) {
2096
+ // Absolute children will be handled by their containing block since we
2097
+ // cannot guarantee that their positions are set when their parents are
2098
+ // done with layout.
2099
+ if (child->style().display() == Display::None ||
2100
+ child->style().positionType() == PositionType::Absolute) {
2101
+ continue;
2102
+ }
2103
+ if (needsMainTrailingPos) {
2104
+ setChildTrailingPosition(node, child, mainAxis);
2105
+ }
2106
+
2107
+ if (needsCrossTrailingPos) {
2108
+ setChildTrailingPosition(node, child, crossAxis);
2109
+ }
2110
+ }
2111
+ }
2112
+
2113
+ // STEP 11: SIZING AND POSITIONING ABSOLUTE CHILDREN
2114
+ // Let the containing block layout its absolute descendants.
2115
+ if (node->style().positionType() != PositionType::Static ||
2116
+ node->alwaysFormsContainingBlock() || depth == 1) {
2117
+ layoutAbsoluteDescendants(
2118
+ node,
2119
+ node,
2120
+ isMainAxisRow ? sizingModeMainDim : sizingModeCrossDim,
2121
+ direction,
2122
+ layoutMarkerData,
2123
+ depth,
2124
+ generationCount,
2125
+ 0.0f,
2126
+ 0.0f,
2127
+ availableInnerWidth,
2128
+ availableInnerHeight);
2129
+ }
2130
+ }
2131
+ }
2132
+
2133
+ //
2134
+ // This is a wrapper around the calculateLayoutImpl function. It determines
2135
+ // whether the layout request is redundant and can be skipped.
2136
+ //
2137
+ // Parameters:
2138
+ // Input parameters are the same as calculateLayoutImpl (see above)
2139
+ // Return parameter is true if layout was performed, false if skipped
2140
+ //
2141
+ bool calculateLayoutInternal(
2142
+ yoga::Node* const node,
2143
+ const float availableWidth,
2144
+ const float availableHeight,
2145
+ const Direction ownerDirection,
2146
+ const SizingMode widthSizingMode,
2147
+ const SizingMode heightSizingMode,
2148
+ const float ownerWidth,
2149
+ const float ownerHeight,
2150
+ const bool performLayout,
2151
+ const LayoutPassReason reason,
2152
+ LayoutData& layoutMarkerData,
2153
+ uint32_t depth,
2154
+ const uint32_t generationCount) {
2155
+ LayoutResults* layout = &node->getLayout();
2156
+
2157
+ depth++;
2158
+
2159
+ const bool needToVisitNode =
2160
+ (node->isDirty() && layout->generationCount != generationCount) ||
2161
+ layout->configVersion != node->getConfig()->getVersion() ||
2162
+ layout->lastOwnerDirection != ownerDirection;
2163
+
2164
+ if (needToVisitNode) {
2165
+ // Invalidate the cached results.
2166
+ layout->nextCachedMeasurementsIndex = 0;
2167
+ layout->cachedLayout.availableWidth = -1;
2168
+ layout->cachedLayout.availableHeight = -1;
2169
+ layout->cachedLayout.widthSizingMode = SizingMode::MaxContent;
2170
+ layout->cachedLayout.heightSizingMode = SizingMode::MaxContent;
2171
+ layout->cachedLayout.computedWidth = -1;
2172
+ layout->cachedLayout.computedHeight = -1;
2173
+ }
2174
+
2175
+ CachedMeasurement* cachedResults = nullptr;
2176
+
2177
+ // Determine whether the results are already cached. We maintain a separate
2178
+ // cache for layouts and measurements. A layout operation modifies the
2179
+ // positions and dimensions for nodes in the subtree. The algorithm assumes
2180
+ // that each node gets laid out a maximum of one time per tree layout, but
2181
+ // multiple measurements may be required to resolve all of the flex
2182
+ // dimensions. We handle nodes with measure functions specially here because
2183
+ // they are the most expensive to measure, so it's worth avoiding redundant
2184
+ // measurements if at all possible.
2185
+ if (node->hasMeasureFunc()) {
2186
+ const float marginAxisRow =
2187
+ node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth);
2188
+ const float marginAxisColumn =
2189
+ node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
2190
+
2191
+ // First, try to use the layout cache.
2192
+ if (canUseCachedMeasurement(
2193
+ widthSizingMode,
2194
+ availableWidth,
2195
+ heightSizingMode,
2196
+ availableHeight,
2197
+ layout->cachedLayout.widthSizingMode,
2198
+ layout->cachedLayout.availableWidth,
2199
+ layout->cachedLayout.heightSizingMode,
2200
+ layout->cachedLayout.availableHeight,
2201
+ layout->cachedLayout.computedWidth,
2202
+ layout->cachedLayout.computedHeight,
2203
+ marginAxisRow,
2204
+ marginAxisColumn,
2205
+ node->getConfig())) {
2206
+ cachedResults = &layout->cachedLayout;
2207
+ } else {
2208
+ // Try to use the measurement cache.
2209
+ for (size_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
2210
+ if (canUseCachedMeasurement(
2211
+ widthSizingMode,
2212
+ availableWidth,
2213
+ heightSizingMode,
2214
+ availableHeight,
2215
+ layout->cachedMeasurements[i].widthSizingMode,
2216
+ layout->cachedMeasurements[i].availableWidth,
2217
+ layout->cachedMeasurements[i].heightSizingMode,
2218
+ layout->cachedMeasurements[i].availableHeight,
2219
+ layout->cachedMeasurements[i].computedWidth,
2220
+ layout->cachedMeasurements[i].computedHeight,
2221
+ marginAxisRow,
2222
+ marginAxisColumn,
2223
+ node->getConfig())) {
2224
+ cachedResults = &layout->cachedMeasurements[i];
2225
+ break;
2226
+ }
2227
+ }
2228
+ }
2229
+ } else if (performLayout) {
2230
+ if (yoga::inexactEquals(
2231
+ layout->cachedLayout.availableWidth, availableWidth) &&
2232
+ yoga::inexactEquals(
2233
+ layout->cachedLayout.availableHeight, availableHeight) &&
2234
+ layout->cachedLayout.widthSizingMode == widthSizingMode &&
2235
+ layout->cachedLayout.heightSizingMode == heightSizingMode) {
2236
+ cachedResults = &layout->cachedLayout;
2237
+ }
2238
+ } else {
2239
+ for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
2240
+ if (yoga::inexactEquals(
2241
+ layout->cachedMeasurements[i].availableWidth, availableWidth) &&
2242
+ yoga::inexactEquals(
2243
+ layout->cachedMeasurements[i].availableHeight, availableHeight) &&
2244
+ layout->cachedMeasurements[i].widthSizingMode == widthSizingMode &&
2245
+ layout->cachedMeasurements[i].heightSizingMode == heightSizingMode) {
2246
+ cachedResults = &layout->cachedMeasurements[i];
2247
+ break;
2248
+ }
2249
+ }
2250
+ }
2251
+
2252
+ if (!needToVisitNode && cachedResults != nullptr) {
2253
+ layout->setMeasuredDimension(
2254
+ Dimension::Width, cachedResults->computedWidth);
2255
+ layout->setMeasuredDimension(
2256
+ Dimension::Height, cachedResults->computedHeight);
2257
+
2258
+ (performLayout ? layoutMarkerData.cachedLayouts
2259
+ : layoutMarkerData.cachedMeasures) += 1;
2260
+ } else {
2261
+ calculateLayoutImpl(
2262
+ node,
2263
+ availableWidth,
2264
+ availableHeight,
2265
+ ownerDirection,
2266
+ widthSizingMode,
2267
+ heightSizingMode,
2268
+ ownerWidth,
2269
+ ownerHeight,
2270
+ performLayout,
2271
+ layoutMarkerData,
2272
+ depth,
2273
+ generationCount,
2274
+ reason);
2275
+
2276
+ layout->lastOwnerDirection = ownerDirection;
2277
+ layout->configVersion = node->getConfig()->getVersion();
2278
+
2279
+ if (cachedResults == nullptr) {
2280
+ layoutMarkerData.maxMeasureCache = std::max(
2281
+ layoutMarkerData.maxMeasureCache,
2282
+ layout->nextCachedMeasurementsIndex + 1u);
2283
+
2284
+ if (layout->nextCachedMeasurementsIndex ==
2285
+ LayoutResults::MaxCachedMeasurements) {
2286
+ layout->nextCachedMeasurementsIndex = 0;
2287
+ }
2288
+
2289
+ CachedMeasurement* newCacheEntry = nullptr;
2290
+ if (performLayout) {
2291
+ // Use the single layout cache entry.
2292
+ newCacheEntry = &layout->cachedLayout;
2293
+ } else {
2294
+ // Allocate a new measurement cache entry.
2295
+ newCacheEntry =
2296
+ &layout->cachedMeasurements[layout->nextCachedMeasurementsIndex];
2297
+ layout->nextCachedMeasurementsIndex++;
2298
+ }
2299
+
2300
+ newCacheEntry->availableWidth = availableWidth;
2301
+ newCacheEntry->availableHeight = availableHeight;
2302
+ newCacheEntry->widthSizingMode = widthSizingMode;
2303
+ newCacheEntry->heightSizingMode = heightSizingMode;
2304
+ newCacheEntry->computedWidth =
2305
+ layout->measuredDimension(Dimension::Width);
2306
+ newCacheEntry->computedHeight =
2307
+ layout->measuredDimension(Dimension::Height);
2308
+ }
2309
+ }
2310
+
2311
+ if (performLayout) {
2312
+ node->setLayoutDimension(
2313
+ node->getLayout().measuredDimension(Dimension::Width),
2314
+ Dimension::Width);
2315
+ node->setLayoutDimension(
2316
+ node->getLayout().measuredDimension(Dimension::Height),
2317
+ Dimension::Height);
2318
+
2319
+ node->setHasNewLayout(true);
2320
+ node->setDirty(false);
2321
+ }
2322
+
2323
+ layout->generationCount = generationCount;
2324
+
2325
+ LayoutType layoutType;
2326
+ if (performLayout) {
2327
+ layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout
2328
+ ? LayoutType::kCachedLayout
2329
+ : LayoutType::kLayout;
2330
+ } else {
2331
+ layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure
2332
+ : LayoutType::kMeasure;
2333
+ }
2334
+ Event::publish<Event::NodeLayout>(node, {layoutType});
2335
+
2336
+ return (needToVisitNode || cachedResults == nullptr);
2337
+ }
2338
+
2339
+ void calculateLayout(
2340
+ yoga::Node* const node,
2341
+ const float ownerWidth,
2342
+ const float ownerHeight,
2343
+ const Direction ownerDirection) {
2344
+ Event::publish<Event::LayoutPassStart>(node);
2345
+ LayoutData markerData = {};
2346
+
2347
+ // Increment the generation count. This will force the recursive routine to
2348
+ // visit all dirty nodes at least once. Subsequent visits will be skipped if
2349
+ // the input parameters don't change.
2350
+ gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
2351
+ node->processDimensions();
2352
+ const Direction direction = node->resolveDirection(ownerDirection);
2353
+ float width = YGUndefined;
2354
+ SizingMode widthSizingMode = SizingMode::MaxContent;
2355
+ const auto& style = node->style();
2356
+ if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
2357
+ width =
2358
+ (node->getResolvedDimension(
2359
+ direction,
2360
+ dimension(FlexDirection::Row),
2361
+ ownerWidth,
2362
+ ownerWidth)
2363
+ .unwrap() +
2364
+ node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth));
2365
+ widthSizingMode = SizingMode::StretchFit;
2366
+ } else if (style
2367
+ .resolvedMaxDimension(
2368
+ direction, Dimension::Width, ownerWidth, ownerWidth)
2369
+ .isDefined()) {
2370
+ width = style
2371
+ .resolvedMaxDimension(
2372
+ direction, Dimension::Width, ownerWidth, ownerWidth)
2373
+ .unwrap();
2374
+ widthSizingMode = SizingMode::FitContent;
2375
+ } else {
2376
+ width = ownerWidth;
2377
+ widthSizingMode = yoga::isUndefined(width) ? SizingMode::MaxContent
2378
+ : SizingMode::StretchFit;
2379
+ }
2380
+
2381
+ float height = YGUndefined;
2382
+ SizingMode heightSizingMode = SizingMode::MaxContent;
2383
+ if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
2384
+ height =
2385
+ (node->getResolvedDimension(
2386
+ direction,
2387
+ dimension(FlexDirection::Column),
2388
+ ownerHeight,
2389
+ ownerWidth)
2390
+ .unwrap() +
2391
+ node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth));
2392
+ heightSizingMode = SizingMode::StretchFit;
2393
+ } else if (style
2394
+ .resolvedMaxDimension(
2395
+ direction, Dimension::Height, ownerHeight, ownerWidth)
2396
+ .isDefined()) {
2397
+ height = style
2398
+ .resolvedMaxDimension(
2399
+ direction, Dimension::Height, ownerHeight, ownerWidth)
2400
+ .unwrap();
2401
+ heightSizingMode = SizingMode::FitContent;
2402
+ } else {
2403
+ height = ownerHeight;
2404
+ heightSizingMode = yoga::isUndefined(height) ? SizingMode::MaxContent
2405
+ : SizingMode::StretchFit;
2406
+ }
2407
+ if (calculateLayoutInternal(
2408
+ node,
2409
+ width,
2410
+ height,
2411
+ ownerDirection,
2412
+ widthSizingMode,
2413
+ heightSizingMode,
2414
+ ownerWidth,
2415
+ ownerHeight,
2416
+ true,
2417
+ LayoutPassReason::kInitial,
2418
+ markerData,
2419
+ 0, // tree root
2420
+ gCurrentGenerationCount.load(std::memory_order_relaxed))) {
2421
+ node->setPosition(node->getLayout().direction(), ownerWidth, ownerHeight);
2422
+ roundLayoutResultsToPixelGrid(node, 0.0f, 0.0f);
2423
+ }
2424
+
2425
+ Event::publish<Event::LayoutPassEnd>(node, {&markerData});
2426
+ }
2427
+
2428
+ } // namespace facebook::yoga