diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj index eb834b8a..ca6c764f 100644 --- a/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj +++ b/Example/cocoapods/FlexLayoutSample.xcodeproj/project.pbxproj @@ -449,11 +449,13 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Yoga/yoga.framework", "${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework", "${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/yoga.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework", ); @@ -475,7 +477,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "Pods/SwiftLint/swiftlint ../FlexLayoutSample\n"; + shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --path ../FlexLayoutSample\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/Example/cocoapods/Podfile b/Example/cocoapods/Podfile deleted file mode 100644 index 038ea15f..00000000 --- a/Example/cocoapods/Podfile +++ /dev/null @@ -1,15 +0,0 @@ -source 'https://cdn.cocoapods.org/' -use_frameworks! -platform :ios, '12.0' - -workspace 'FlexLayoutSample.xcworkspace' - -target 'FlexLayoutSample' do - project 'FlexLayoutSample.xcodeproj' - - pod 'FlexLayout', path: '../..' - pod 'PinLayout' - - # Debug only - pod 'SwiftLint' -end diff --git a/Example/cocoapods/Podfile.lock b/Example/cocoapods/Podfile.lock deleted file mode 100644 index a409bac0..00000000 --- a/Example/cocoapods/Podfile.lock +++ /dev/null @@ -1,27 +0,0 @@ -PODS: - - FlexLayout (2.0.04) - - PinLayout (1.10.5) - - SwiftLint (0.54.0) - -DEPENDENCIES: - - FlexLayout (from `../..`) - - PinLayout - - SwiftLint - -SPEC REPOS: - trunk: - - PinLayout - - SwiftLint - -EXTERNAL SOURCES: - FlexLayout: - :path: "../.." - -SPEC CHECKSUMS: - FlexLayout: 222177b4cd0c7e57b662ba05314a64c122958dac - PinLayout: f6c2b63a5a5b24864064e1d15c67de41b4e74748 - SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211 - -PODFILE CHECKSUM: acd6f8f55e169593da8f5d86c0f788512ba67886 - -COCOAPODS: 1.14.3 diff --git a/FlexLayout.podspec b/FlexLayout.podspec index bcdc7872..1b7dccf3 100644 --- a/FlexLayout.podspec +++ b/FlexLayout.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.platform = :ios, "12.0" spec.source = { :git => "https://github.com/lucdion/FlexLayout.git", :tag => "#{spec.version}" } spec.source_files = "Sources/**/*.{swift,h,m,mm,cpp,c}" - spec.public_header_files = "Sources/yoga/include/yoga/*.h", "Sources/YogaKit/include/YogaKit/*.h" + spec.public_header_files = "Sources/YogaKit/include/YogaKit/*.h" spec.libraries = 'c++' # Should match yoga_defs.bzl + BUCK configuration @@ -22,4 +22,6 @@ Pod::Spec.new do |spec| '-std=c++20', '-fPIC' ] + + spec.dependency 'Yoga' end diff --git a/FlexLayout.xcodeproj/project.pbxproj b/FlexLayout.xcodeproj/project.pbxproj index 3b327f47..ea500dfd 100644 --- a/FlexLayout.xcodeproj/project.pbxproj +++ b/FlexLayout.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 1207ABCE834615F650234676 /* Pods_FlexLayoutTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */; }; 24AE973E1FEAF30A00995987 /* FlexLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE972E1FEAF30A00995987 /* FlexLayout.swift */; }; - 24AE973F1FEAF30A00995987 /* FlexLayout+Enum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97301FEAF30A00995987 /* FlexLayout+Enum.swift */; }; 24AE97401FEAF30A00995987 /* FlexLayout+Private.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97311FEAF30A00995987 /* FlexLayout+Private.swift */; }; 24AE97411FEAF30A00995987 /* UIView+FlexLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97321FEAF30A00995987 /* UIView+FlexLayout.swift */; }; 24AE97421FEAF30A00995987 /* Percent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97331FEAF30A00995987 /* Percent.swift */; }; @@ -19,85 +18,14 @@ 711F2EE92ACC727000DDDD67 /* FlexLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */; }; 711F2EEA2ACC727000DDDD67 /* MarginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE42ACC727000DDDD67 /* MarginTests.swift */; }; 711F2EEB2ACC727000DDDD67 /* JustifyContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711F2EE52ACC727000DDDD67 /* JustifyContentTests.swift */; }; - 71332C262B794826000667C9 /* FlexLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 24AE97351FEAF30A00995987 /* FlexLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 71332C272B794935000667C9 /* UIView+Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 71332C282B794935000667C9 /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 71332C292B794935000667C9 /* YGLayout+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617D2ABEE4B600D5A2E0 /* YGLayout+Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; 715C61812ABEE4B600D5A2E0 /* UIView+Yoga.mm in Sources */ = {isa = PBXBuildFile; fileRef = 715C617A2ABEE4B600D5A2E0 /* UIView+Yoga.mm */; }; 715C61852ABEE4B600D5A2E0 /* YGLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 715C61802ABEE4B600D5A2E0 /* YGLayout.mm */; }; - EF0E61302C1A811100DF30F6 /* YGConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E32C1A811100DF30F6 /* YGConfig.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61312C1A811100DF30F6 /* YGEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E42C1A811100DF30F6 /* YGEnums.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61322C1A811100DF30F6 /* YGMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E52C1A811100DF30F6 /* YGMacros.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61332C1A811100DF30F6 /* YGNode.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E62C1A811100DF30F6 /* YGNode.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61342C1A811100DF30F6 /* YGNodeLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E72C1A811100DF30F6 /* YGNodeLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61352C1A811100DF30F6 /* YGNodeStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E82C1A811100DF30F6 /* YGNodeStyle.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61362C1A811100DF30F6 /* YGPixelGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60E92C1A811100DF30F6 /* YGPixelGrid.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61372C1A811100DF30F6 /* YGValue.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60EA2C1A811100DF30F6 /* YGValue.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61382C1A811100DF30F6 /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60EB2C1A811100DF30F6 /* Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EF0E61392C1A811100DF30F6 /* Algorithm_AbsoluteLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60EE2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.cpp */; }; - EF0E613A2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60EF2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.h */; }; - EF0E613B2C1A811100DF30F6 /* Algorithm_Align.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F02C1A811100DF30F6 /* Algorithm_Align.h */; }; - EF0E613C2C1A811100DF30F6 /* Algorithm_Baseline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60F12C1A811100DF30F6 /* Algorithm_Baseline.cpp */; }; - EF0E613D2C1A811100DF30F6 /* Algorithm_Baseline.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F22C1A811100DF30F6 /* Algorithm_Baseline.h */; }; - EF0E613E2C1A811100DF30F6 /* Algorithm_BoundAxis.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F32C1A811100DF30F6 /* Algorithm_BoundAxis.h */; }; - EF0E613F2C1A811100DF30F6 /* Algorithm_Cache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60F42C1A811100DF30F6 /* Algorithm_Cache.cpp */; }; - EF0E61402C1A811100DF30F6 /* Algorithm_Cache.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F52C1A811100DF30F6 /* Algorithm_Cache.h */; }; - EF0E61412C1A811100DF30F6 /* Algorithm_CalculateLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60F62C1A811100DF30F6 /* Algorithm_CalculateLayout.cpp */; }; - EF0E61422C1A811100DF30F6 /* Algorithm_CalculateLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F72C1A811100DF30F6 /* Algorithm_CalculateLayout.h */; }; - EF0E61432C1A811100DF30F6 /* Algorithm_FlexDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60F82C1A811100DF30F6 /* Algorithm_FlexDirection.h */; }; - EF0E61442C1A811100DF30F6 /* Algorithm_FlexLine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60F92C1A811100DF30F6 /* Algorithm_FlexLine.cpp */; }; - EF0E61452C1A811100DF30F6 /* Algorithm_FlexLine.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60FA2C1A811100DF30F6 /* Algorithm_FlexLine.h */; }; - EF0E61462C1A811100DF30F6 /* Algorithm_PixelGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E60FB2C1A811100DF30F6 /* Algorithm_PixelGrid.cpp */; }; - EF0E61472C1A811100DF30F6 /* Algorithm_PixelGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60FC2C1A811100DF30F6 /* Algorithm_PixelGrid.h */; }; - EF0E61482C1A811100DF30F6 /* Algorithm_SizingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60FD2C1A811100DF30F6 /* Algorithm_SizingMode.h */; }; - EF0E61492C1A811100DF30F6 /* Algorithm_TrailingPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E60FE2C1A811100DF30F6 /* Algorithm_TrailingPosition.h */; }; - EF0E614A2C1A811100DF30F6 /* CMakeLists.txt in Resources */ = {isa = PBXBuildFile; fileRef = EF0E60FF2C1A811100DF30F6 /* CMakeLists.txt */; }; - EF0E614B2C1A811100DF30F6 /* Config_Config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61002C1A811100DF30F6 /* Config_Config.cpp */; }; - EF0E614C2C1A811100DF30F6 /* Config_Config.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61012C1A811100DF30F6 /* Config_Config.h */; }; - EF0E614D2C1A811100DF30F6 /* Debug_AssertFatal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61022C1A811100DF30F6 /* Debug_AssertFatal.cpp */; }; - EF0E614E2C1A811100DF30F6 /* Debug_AssertFatal.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61032C1A811100DF30F6 /* Debug_AssertFatal.h */; }; - EF0E614F2C1A811100DF30F6 /* Debug_Log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61042C1A811100DF30F6 /* Debug_Log.cpp */; }; - EF0E61502C1A811100DF30F6 /* Debug_Log.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61052C1A811100DF30F6 /* Debug_Log.h */; }; - EF0E61512C1A811100DF30F6 /* Enums_Align.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61062C1A811100DF30F6 /* Enums_Align.h */; }; - EF0E61522C1A811100DF30F6 /* Enums_Dimension.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61072C1A811100DF30F6 /* Enums_Dimension.h */; }; - EF0E61532C1A811100DF30F6 /* Enums_Direction.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61082C1A811100DF30F6 /* Enums_Direction.h */; }; - EF0E61542C1A811100DF30F6 /* Enums_Display.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61092C1A811100DF30F6 /* Enums_Display.h */; }; - EF0E61552C1A811100DF30F6 /* Enums_Edge.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610A2C1A811100DF30F6 /* Enums_Edge.h */; }; - EF0E61562C1A811100DF30F6 /* Enums_Errata.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610B2C1A811100DF30F6 /* Enums_Errata.h */; }; - EF0E61572C1A811100DF30F6 /* Enums_ExperimentalFeature.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610C2C1A811100DF30F6 /* Enums_ExperimentalFeature.h */; }; - EF0E61582C1A811100DF30F6 /* Enums_FlexDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610D2C1A811100DF30F6 /* Enums_FlexDirection.h */; }; - EF0E61592C1A811100DF30F6 /* Enums_Gutter.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610E2C1A811100DF30F6 /* Enums_Gutter.h */; }; - EF0E615A2C1A811100DF30F6 /* Enums_Justify.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E610F2C1A811100DF30F6 /* Enums_Justify.h */; }; - EF0E615B2C1A811100DF30F6 /* Enums_LogLevel.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61102C1A811100DF30F6 /* Enums_LogLevel.h */; }; - EF0E615C2C1A811100DF30F6 /* Enums_MeasureMode.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61112C1A811100DF30F6 /* Enums_MeasureMode.h */; }; - EF0E615D2C1A811100DF30F6 /* Enums_NodeType.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61122C1A811100DF30F6 /* Enums_NodeType.h */; }; - EF0E615E2C1A811100DF30F6 /* Enums_Overflow.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61132C1A811100DF30F6 /* Enums_Overflow.h */; }; - EF0E615F2C1A811100DF30F6 /* Enums_PhysicalEdge.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61142C1A811100DF30F6 /* Enums_PhysicalEdge.h */; }; - EF0E61602C1A811100DF30F6 /* Enums_PositionType.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61152C1A811100DF30F6 /* Enums_PositionType.h */; }; - EF0E61612C1A811100DF30F6 /* Enums_Unit.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61162C1A811100DF30F6 /* Enums_Unit.h */; }; - EF0E61622C1A811100DF30F6 /* Enums_Wrap.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61172C1A811100DF30F6 /* Enums_Wrap.h */; }; - EF0E61632C1A811100DF30F6 /* Enums_YogaEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61182C1A811100DF30F6 /* Enums_YogaEnums.h */; }; - EF0E61642C1A811100DF30F6 /* Event_event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61192C1A811100DF30F6 /* Event_event.cpp */; }; - EF0E61652C1A811100DF30F6 /* Event_event.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E611A2C1A811100DF30F6 /* Event_event.h */; }; - EF0E61662C1A811100DF30F6 /* Node_CachedMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E611C2C1A811100DF30F6 /* Node_CachedMeasurement.h */; }; - EF0E61672C1A811100DF30F6 /* Node_LayoutResults.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E611D2C1A811100DF30F6 /* Node_LayoutResults.cpp */; }; - EF0E61682C1A811100DF30F6 /* Node_LayoutResults.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E611E2C1A811100DF30F6 /* Node_LayoutResults.h */; }; - EF0E61692C1A811100DF30F6 /* Node_Node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E611F2C1A811100DF30F6 /* Node_Node.cpp */; }; - EF0E616A2C1A811100DF30F6 /* Node_Node.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61202C1A811100DF30F6 /* Node_Node.h */; }; - EF0E616B2C1A811100DF30F6 /* Numeric_Comparison.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61212C1A811100DF30F6 /* Numeric_Comparison.h */; }; - EF0E616C2C1A811100DF30F6 /* Numeric_FloatOptional.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61222C1A811100DF30F6 /* Numeric_FloatOptional.h */; }; - EF0E616D2C1A811100DF30F6 /* Style_SmallValueBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61232C1A811100DF30F6 /* Style_SmallValueBuffer.h */; }; - EF0E616E2C1A811100DF30F6 /* Style_Style.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61242C1A811100DF30F6 /* Style_Style.h */; }; - EF0E616F2C1A811100DF30F6 /* Style_StyleLength.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61252C1A811100DF30F6 /* Style_StyleLength.h */; }; - EF0E61702C1A811100DF30F6 /* Style_StyleValueHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61262C1A811100DF30F6 /* Style_StyleValueHandle.h */; }; - EF0E61712C1A811100DF30F6 /* Style_StyleValuePool.h in Headers */ = {isa = PBXBuildFile; fileRef = EF0E61272C1A811100DF30F6 /* Style_StyleValuePool.h */; }; - EF0E61722C1A811100DF30F6 /* YGConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61282C1A811100DF30F6 /* YGConfig.cpp */; }; - EF0E61732C1A811100DF30F6 /* YGEnums.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E61292C1A811100DF30F6 /* YGEnums.cpp */; }; - EF0E61742C1A811100DF30F6 /* YGNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612A2C1A811100DF30F6 /* YGNode.cpp */; }; - EF0E61752C1A811100DF30F6 /* YGNodeLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612B2C1A811100DF30F6 /* YGNodeLayout.cpp */; }; - EF0E61762C1A811100DF30F6 /* YGNodeStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612C2C1A811100DF30F6 /* YGNodeStyle.cpp */; }; - EF0E61772C1A811100DF30F6 /* YGPixelGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612D2C1A811100DF30F6 /* YGPixelGrid.cpp */; }; - EF0E61782C1A811100DF30F6 /* YGValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EF0E612E2C1A811100DF30F6 /* YGValue.cpp */; }; + 71A5522D2CEAED24005D9FBF /* FlexLayout+Enum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24AE97301FEAF30A00995987 /* FlexLayout+Enum.swift */; }; + 71A5522E2CEAED47005D9FBF /* UIView+Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A5522F2CEAED47005D9FBF /* YGLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A552302CEAED47005D9FBF /* YGLayout+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 715C617D2ABEE4B600D5A2E0 /* YGLayout+Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71A552312CEAEDC1005D9FBF /* FlexLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 24AE97351FEAF30A00995987 /* FlexLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 9421472A1695AFD38FAEBD72 /* Pods_FlexLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */; }; EF5445402C1D607100BF4A33 /* InsetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF54453F2C1D607100BF4A33 /* InsetTests.swift */; }; /* End PBXBuildFile section */ @@ -125,6 +53,7 @@ /* Begin PBXFileReference section */ 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayoutTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayout.debug.xcconfig"; path = "Target Support Files/Pods-FlexLayout/Pods-FlexLayout.debug.xcconfig"; sourceTree = ""; }; 2491CC5C1FCB931F00F3A61C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; 2491CC5E1FCB932B00F3A61C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; 24AE972E1FEAF30A00995987 /* FlexLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLayout.swift; sourceTree = ""; }; @@ -138,6 +67,8 @@ 24DA37631EF843C500D1AB2F /* FlexLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2B210ECFE9D7665DACB8E8A7 /* Pods-FlexLayoutTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.debug.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.debug.xcconfig"; sourceTree = ""; }; 38E690AA4AF8EDFC95DB6626 /* Pods-FlexLayoutTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutTests.release.xcconfig"; path = "Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests.release.xcconfig"; sourceTree = ""; }; + 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayout.release.xcconfig"; path = "Target Support Files/Pods-FlexLayout/Pods-FlexLayout.release.xcconfig"; sourceTree = ""; }; 711F2EE12ACC727000DDDD67 /* WidthSizeContentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidthSizeContentTests.swift; sourceTree = ""; }; 711F2EE22ACC727000DDDD67 /* PaddingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingTests.swift; sourceTree = ""; }; 711F2EE32ACC727000DDDD67 /* FlexLayoutTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLayoutTests.swift; sourceTree = ""; }; @@ -148,80 +79,6 @@ 715C617E2ABEE4B600D5A2E0 /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = ""; }; 715C617F2ABEE4B600D5A2E0 /* UIView+Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Yoga.h"; sourceTree = ""; }; 715C61802ABEE4B600D5A2E0 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = ""; tabWidth = 2; }; - EF0E60E32C1A811100DF30F6 /* YGConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGConfig.h; sourceTree = ""; }; - EF0E60E42C1A811100DF30F6 /* YGEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGEnums.h; sourceTree = ""; }; - EF0E60E52C1A811100DF30F6 /* YGMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGMacros.h; sourceTree = ""; }; - EF0E60E62C1A811100DF30F6 /* YGNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNode.h; sourceTree = ""; }; - EF0E60E72C1A811100DF30F6 /* YGNodeLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodeLayout.h; sourceTree = ""; }; - EF0E60E82C1A811100DF30F6 /* YGNodeStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGNodeStyle.h; sourceTree = ""; }; - EF0E60E92C1A811100DF30F6 /* YGPixelGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGPixelGrid.h; sourceTree = ""; }; - EF0E60EA2C1A811100DF30F6 /* YGValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGValue.h; sourceTree = ""; }; - EF0E60EB2C1A811100DF30F6 /* Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Yoga.h; sourceTree = ""; }; - EF0E60EE2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_AbsoluteLayout.cpp; sourceTree = ""; }; - EF0E60EF2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_AbsoluteLayout.h; sourceTree = ""; }; - EF0E60F02C1A811100DF30F6 /* Algorithm_Align.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_Align.h; sourceTree = ""; }; - EF0E60F12C1A811100DF30F6 /* Algorithm_Baseline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_Baseline.cpp; sourceTree = ""; }; - EF0E60F22C1A811100DF30F6 /* Algorithm_Baseline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_Baseline.h; sourceTree = ""; }; - EF0E60F32C1A811100DF30F6 /* Algorithm_BoundAxis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_BoundAxis.h; sourceTree = ""; }; - EF0E60F42C1A811100DF30F6 /* Algorithm_Cache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_Cache.cpp; sourceTree = ""; }; - EF0E60F52C1A811100DF30F6 /* Algorithm_Cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_Cache.h; sourceTree = ""; }; - EF0E60F62C1A811100DF30F6 /* Algorithm_CalculateLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_CalculateLayout.cpp; sourceTree = ""; }; - EF0E60F72C1A811100DF30F6 /* Algorithm_CalculateLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_CalculateLayout.h; sourceTree = ""; }; - EF0E60F82C1A811100DF30F6 /* Algorithm_FlexDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_FlexDirection.h; sourceTree = ""; }; - EF0E60F92C1A811100DF30F6 /* Algorithm_FlexLine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_FlexLine.cpp; sourceTree = ""; }; - EF0E60FA2C1A811100DF30F6 /* Algorithm_FlexLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_FlexLine.h; sourceTree = ""; }; - EF0E60FB2C1A811100DF30F6 /* Algorithm_PixelGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Algorithm_PixelGrid.cpp; sourceTree = ""; }; - EF0E60FC2C1A811100DF30F6 /* Algorithm_PixelGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_PixelGrid.h; sourceTree = ""; }; - EF0E60FD2C1A811100DF30F6 /* Algorithm_SizingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_SizingMode.h; sourceTree = ""; }; - EF0E60FE2C1A811100DF30F6 /* Algorithm_TrailingPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Algorithm_TrailingPosition.h; sourceTree = ""; }; - EF0E60FF2C1A811100DF30F6 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - EF0E61002C1A811100DF30F6 /* Config_Config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Config_Config.cpp; sourceTree = ""; }; - EF0E61012C1A811100DF30F6 /* Config_Config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Config_Config.h; sourceTree = ""; }; - EF0E61022C1A811100DF30F6 /* Debug_AssertFatal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Debug_AssertFatal.cpp; sourceTree = ""; }; - EF0E61032C1A811100DF30F6 /* Debug_AssertFatal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Debug_AssertFatal.h; sourceTree = ""; }; - EF0E61042C1A811100DF30F6 /* Debug_Log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Debug_Log.cpp; sourceTree = ""; }; - EF0E61052C1A811100DF30F6 /* Debug_Log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Debug_Log.h; sourceTree = ""; }; - EF0E61062C1A811100DF30F6 /* Enums_Align.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Align.h; sourceTree = ""; }; - EF0E61072C1A811100DF30F6 /* Enums_Dimension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Dimension.h; sourceTree = ""; }; - EF0E61082C1A811100DF30F6 /* Enums_Direction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Direction.h; sourceTree = ""; }; - EF0E61092C1A811100DF30F6 /* Enums_Display.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Display.h; sourceTree = ""; }; - EF0E610A2C1A811100DF30F6 /* Enums_Edge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Edge.h; sourceTree = ""; }; - EF0E610B2C1A811100DF30F6 /* Enums_Errata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Errata.h; sourceTree = ""; }; - EF0E610C2C1A811100DF30F6 /* Enums_ExperimentalFeature.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_ExperimentalFeature.h; sourceTree = ""; }; - EF0E610D2C1A811100DF30F6 /* Enums_FlexDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_FlexDirection.h; sourceTree = ""; }; - EF0E610E2C1A811100DF30F6 /* Enums_Gutter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Gutter.h; sourceTree = ""; }; - EF0E610F2C1A811100DF30F6 /* Enums_Justify.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Justify.h; sourceTree = ""; }; - EF0E61102C1A811100DF30F6 /* Enums_LogLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_LogLevel.h; sourceTree = ""; }; - EF0E61112C1A811100DF30F6 /* Enums_MeasureMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_MeasureMode.h; sourceTree = ""; }; - EF0E61122C1A811100DF30F6 /* Enums_NodeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_NodeType.h; sourceTree = ""; }; - EF0E61132C1A811100DF30F6 /* Enums_Overflow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Overflow.h; sourceTree = ""; }; - EF0E61142C1A811100DF30F6 /* Enums_PhysicalEdge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_PhysicalEdge.h; sourceTree = ""; }; - EF0E61152C1A811100DF30F6 /* Enums_PositionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_PositionType.h; sourceTree = ""; }; - EF0E61162C1A811100DF30F6 /* Enums_Unit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Unit.h; sourceTree = ""; }; - EF0E61172C1A811100DF30F6 /* Enums_Wrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_Wrap.h; sourceTree = ""; }; - EF0E61182C1A811100DF30F6 /* Enums_YogaEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Enums_YogaEnums.h; sourceTree = ""; }; - EF0E61192C1A811100DF30F6 /* Event_event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event_event.cpp; sourceTree = ""; }; - EF0E611A2C1A811100DF30F6 /* Event_event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Event_event.h; sourceTree = ""; }; - EF0E611B2C1A811100DF30F6 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; - EF0E611C2C1A811100DF30F6 /* Node_CachedMeasurement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Node_CachedMeasurement.h; sourceTree = ""; }; - EF0E611D2C1A811100DF30F6 /* Node_LayoutResults.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Node_LayoutResults.cpp; sourceTree = ""; }; - EF0E611E2C1A811100DF30F6 /* Node_LayoutResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Node_LayoutResults.h; sourceTree = ""; }; - EF0E611F2C1A811100DF30F6 /* Node_Node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Node_Node.cpp; sourceTree = ""; }; - EF0E61202C1A811100DF30F6 /* Node_Node.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Node_Node.h; sourceTree = ""; }; - EF0E61212C1A811100DF30F6 /* Numeric_Comparison.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Numeric_Comparison.h; sourceTree = ""; }; - EF0E61222C1A811100DF30F6 /* Numeric_FloatOptional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Numeric_FloatOptional.h; sourceTree = ""; }; - EF0E61232C1A811100DF30F6 /* Style_SmallValueBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Style_SmallValueBuffer.h; sourceTree = ""; }; - EF0E61242C1A811100DF30F6 /* Style_Style.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Style_Style.h; sourceTree = ""; }; - EF0E61252C1A811100DF30F6 /* Style_StyleLength.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Style_StyleLength.h; sourceTree = ""; }; - EF0E61262C1A811100DF30F6 /* Style_StyleValueHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Style_StyleValueHandle.h; sourceTree = ""; }; - EF0E61272C1A811100DF30F6 /* Style_StyleValuePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Style_StyleValuePool.h; sourceTree = ""; }; - EF0E61282C1A811100DF30F6 /* YGConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGConfig.cpp; sourceTree = ""; }; - EF0E61292C1A811100DF30F6 /* YGEnums.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGEnums.cpp; sourceTree = ""; }; - EF0E612A2C1A811100DF30F6 /* YGNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNode.cpp; sourceTree = ""; }; - EF0E612B2C1A811100DF30F6 /* YGNodeLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNodeLayout.cpp; sourceTree = ""; }; - EF0E612C2C1A811100DF30F6 /* YGNodeStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGNodeStyle.cpp; sourceTree = ""; }; - EF0E612D2C1A811100DF30F6 /* YGPixelGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGPixelGrid.cpp; sourceTree = ""; }; - EF0E612E2C1A811100DF30F6 /* YGValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGValue.cpp; sourceTree = ""; }; EF54453F2C1D607100BF4A33 /* InsetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -230,6 +87,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 9421472A1695AFD38FAEBD72 /* Pods_FlexLayout.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -249,6 +107,8 @@ children = ( 2B210ECFE9D7665DACB8E8A7 /* Pods-FlexLayoutTests.debug.xcconfig */, 38E690AA4AF8EDFC95DB6626 /* Pods-FlexLayoutTests.release.xcconfig */, + 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */, + 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -256,7 +116,6 @@ 24AE972D1FEAF30A00995987 /* Sources */ = { isa = PBXGroup; children = ( - EF0E612F2C1A811100DF30F6 /* yoga */, B9EAD87E238884C90058E0CB /* Swift */, 715C61792ABEE4B600D5A2E0 /* YogaKit */, ); @@ -356,6 +215,7 @@ 2491CC5E1FCB932B00F3A61C /* Quick.framework */, 2491CC5C1FCB931F00F3A61C /* Nimble.framework */, 1F69C581A2C68BBBD1B64F21 /* Pods_FlexLayoutTests.framework */, + 3F893AE16F96F495E91B6D58 /* Pods_FlexLayout.framework */, ); name = Frameworks; sourceTree = ""; @@ -372,103 +232,6 @@ path = Swift; sourceTree = ""; }; - EF0E60EC2C1A811100DF30F6 /* yoga */ = { - isa = PBXGroup; - children = ( - EF0E60E32C1A811100DF30F6 /* YGConfig.h */, - EF0E60E42C1A811100DF30F6 /* YGEnums.h */, - EF0E60E52C1A811100DF30F6 /* YGMacros.h */, - EF0E60E62C1A811100DF30F6 /* YGNode.h */, - EF0E60E72C1A811100DF30F6 /* YGNodeLayout.h */, - EF0E60E82C1A811100DF30F6 /* YGNodeStyle.h */, - EF0E60E92C1A811100DF30F6 /* YGPixelGrid.h */, - EF0E60EA2C1A811100DF30F6 /* YGValue.h */, - EF0E60EB2C1A811100DF30F6 /* Yoga.h */, - ); - path = yoga; - sourceTree = ""; - }; - EF0E60ED2C1A811100DF30F6 /* include */ = { - isa = PBXGroup; - children = ( - EF0E60EC2C1A811100DF30F6 /* yoga */, - ); - path = include; - sourceTree = ""; - }; - EF0E612F2C1A811100DF30F6 /* yoga */ = { - isa = PBXGroup; - children = ( - EF0E60ED2C1A811100DF30F6 /* include */, - EF0E60EE2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.cpp */, - EF0E60EF2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.h */, - EF0E60F02C1A811100DF30F6 /* Algorithm_Align.h */, - EF0E60F12C1A811100DF30F6 /* Algorithm_Baseline.cpp */, - EF0E60F22C1A811100DF30F6 /* Algorithm_Baseline.h */, - EF0E60F32C1A811100DF30F6 /* Algorithm_BoundAxis.h */, - EF0E60F42C1A811100DF30F6 /* Algorithm_Cache.cpp */, - EF0E60F52C1A811100DF30F6 /* Algorithm_Cache.h */, - EF0E60F62C1A811100DF30F6 /* Algorithm_CalculateLayout.cpp */, - EF0E60F72C1A811100DF30F6 /* Algorithm_CalculateLayout.h */, - EF0E60F82C1A811100DF30F6 /* Algorithm_FlexDirection.h */, - EF0E60F92C1A811100DF30F6 /* Algorithm_FlexLine.cpp */, - EF0E60FA2C1A811100DF30F6 /* Algorithm_FlexLine.h */, - EF0E60FB2C1A811100DF30F6 /* Algorithm_PixelGrid.cpp */, - EF0E60FC2C1A811100DF30F6 /* Algorithm_PixelGrid.h */, - EF0E60FD2C1A811100DF30F6 /* Algorithm_SizingMode.h */, - EF0E60FE2C1A811100DF30F6 /* Algorithm_TrailingPosition.h */, - EF0E60FF2C1A811100DF30F6 /* CMakeLists.txt */, - EF0E61002C1A811100DF30F6 /* Config_Config.cpp */, - EF0E61012C1A811100DF30F6 /* Config_Config.h */, - EF0E61022C1A811100DF30F6 /* Debug_AssertFatal.cpp */, - EF0E61032C1A811100DF30F6 /* Debug_AssertFatal.h */, - EF0E61042C1A811100DF30F6 /* Debug_Log.cpp */, - EF0E61052C1A811100DF30F6 /* Debug_Log.h */, - EF0E61062C1A811100DF30F6 /* Enums_Align.h */, - EF0E61072C1A811100DF30F6 /* Enums_Dimension.h */, - EF0E61082C1A811100DF30F6 /* Enums_Direction.h */, - EF0E61092C1A811100DF30F6 /* Enums_Display.h */, - EF0E610A2C1A811100DF30F6 /* Enums_Edge.h */, - EF0E610B2C1A811100DF30F6 /* Enums_Errata.h */, - EF0E610C2C1A811100DF30F6 /* Enums_ExperimentalFeature.h */, - EF0E610D2C1A811100DF30F6 /* Enums_FlexDirection.h */, - EF0E610E2C1A811100DF30F6 /* Enums_Gutter.h */, - EF0E610F2C1A811100DF30F6 /* Enums_Justify.h */, - EF0E61102C1A811100DF30F6 /* Enums_LogLevel.h */, - EF0E61112C1A811100DF30F6 /* Enums_MeasureMode.h */, - EF0E61122C1A811100DF30F6 /* Enums_NodeType.h */, - EF0E61132C1A811100DF30F6 /* Enums_Overflow.h */, - EF0E61142C1A811100DF30F6 /* Enums_PhysicalEdge.h */, - EF0E61152C1A811100DF30F6 /* Enums_PositionType.h */, - EF0E61162C1A811100DF30F6 /* Enums_Unit.h */, - EF0E61172C1A811100DF30F6 /* Enums_Wrap.h */, - EF0E61182C1A811100DF30F6 /* Enums_YogaEnums.h */, - EF0E61192C1A811100DF30F6 /* Event_event.cpp */, - EF0E611A2C1A811100DF30F6 /* Event_event.h */, - EF0E611B2C1A811100DF30F6 /* module.modulemap */, - EF0E611C2C1A811100DF30F6 /* Node_CachedMeasurement.h */, - EF0E611D2C1A811100DF30F6 /* Node_LayoutResults.cpp */, - EF0E611E2C1A811100DF30F6 /* Node_LayoutResults.h */, - EF0E611F2C1A811100DF30F6 /* Node_Node.cpp */, - EF0E61202C1A811100DF30F6 /* Node_Node.h */, - EF0E61212C1A811100DF30F6 /* Numeric_Comparison.h */, - EF0E61222C1A811100DF30F6 /* Numeric_FloatOptional.h */, - EF0E61232C1A811100DF30F6 /* Style_SmallValueBuffer.h */, - EF0E61242C1A811100DF30F6 /* Style_Style.h */, - EF0E61252C1A811100DF30F6 /* Style_StyleLength.h */, - EF0E61262C1A811100DF30F6 /* Style_StyleValueHandle.h */, - EF0E61272C1A811100DF30F6 /* Style_StyleValuePool.h */, - EF0E61282C1A811100DF30F6 /* YGConfig.cpp */, - EF0E61292C1A811100DF30F6 /* YGEnums.cpp */, - EF0E612A2C1A811100DF30F6 /* YGNode.cpp */, - EF0E612B2C1A811100DF30F6 /* YGNodeLayout.cpp */, - EF0E612C2C1A811100DF30F6 /* YGNodeStyle.cpp */, - EF0E612D2C1A811100DF30F6 /* YGPixelGrid.cpp */, - EF0E612E2C1A811100DF30F6 /* YGValue.cpp */, - ); - path = yoga; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -476,63 +239,10 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - EF0E61562C1A811100DF30F6 /* Enums_Errata.h in Headers */, - EF0E61382C1A811100DF30F6 /* Yoga.h in Headers */, - EF0E614E2C1A811100DF30F6 /* Debug_AssertFatal.h in Headers */, - EF0E615B2C1A811100DF30F6 /* Enums_LogLevel.h in Headers */, - EF0E61652C1A811100DF30F6 /* Event_event.h in Headers */, - 71332C262B794826000667C9 /* FlexLayout.h in Headers */, - EF0E615D2C1A811100DF30F6 /* Enums_NodeType.h in Headers */, - EF0E61632C1A811100DF30F6 /* Enums_YogaEnums.h in Headers */, - EF0E614C2C1A811100DF30F6 /* Config_Config.h in Headers */, - EF0E61522C1A811100DF30F6 /* Enums_Dimension.h in Headers */, - EF0E61602C1A811100DF30F6 /* Enums_PositionType.h in Headers */, - 71332C272B794935000667C9 /* UIView+Yoga.h in Headers */, - EF0E613D2C1A811100DF30F6 /* Algorithm_Baseline.h in Headers */, - EF0E61572C1A811100DF30F6 /* Enums_ExperimentalFeature.h in Headers */, - 71332C282B794935000667C9 /* YGLayout.h in Headers */, - 71332C292B794935000667C9 /* YGLayout+Private.h in Headers */, - EF0E61532C1A811100DF30F6 /* Enums_Direction.h in Headers */, - EF0E61352C1A811100DF30F6 /* YGNodeStyle.h in Headers */, - EF0E616E2C1A811100DF30F6 /* Style_Style.h in Headers */, - EF0E61492C1A811100DF30F6 /* Algorithm_TrailingPosition.h in Headers */, - EF0E61682C1A811100DF30F6 /* Node_LayoutResults.h in Headers */, - EF0E616F2C1A811100DF30F6 /* Style_StyleLength.h in Headers */, - EF0E61342C1A811100DF30F6 /* YGNodeLayout.h in Headers */, - EF0E61452C1A811100DF30F6 /* Algorithm_FlexLine.h in Headers */, - EF0E613A2C1A811100DF30F6 /* Algorithm_AbsoluteLayout.h in Headers */, - EF0E61512C1A811100DF30F6 /* Enums_Align.h in Headers */, - EF0E61592C1A811100DF30F6 /* Enums_Gutter.h in Headers */, - EF0E615F2C1A811100DF30F6 /* Enums_PhysicalEdge.h in Headers */, - EF0E616D2C1A811100DF30F6 /* Style_SmallValueBuffer.h in Headers */, - EF0E61432C1A811100DF30F6 /* Algorithm_FlexDirection.h in Headers */, - EF0E61472C1A811100DF30F6 /* Algorithm_PixelGrid.h in Headers */, - EF0E61612C1A811100DF30F6 /* Enums_Unit.h in Headers */, - EF0E61402C1A811100DF30F6 /* Algorithm_Cache.h in Headers */, - EF0E613E2C1A811100DF30F6 /* Algorithm_BoundAxis.h in Headers */, - EF0E61622C1A811100DF30F6 /* Enums_Wrap.h in Headers */, - EF0E61332C1A811100DF30F6 /* YGNode.h in Headers */, - EF0E61422C1A811100DF30F6 /* Algorithm_CalculateLayout.h in Headers */, - EF0E61712C1A811100DF30F6 /* Style_StyleValuePool.h in Headers */, - EF0E61662C1A811100DF30F6 /* Node_CachedMeasurement.h in Headers */, - EF0E61502C1A811100DF30F6 /* Debug_Log.h in Headers */, - EF0E61582C1A811100DF30F6 /* Enums_FlexDirection.h in Headers */, - EF0E61482C1A811100DF30F6 /* Algorithm_SizingMode.h in Headers */, - EF0E61542C1A811100DF30F6 /* Enums_Display.h in Headers */, - EF0E615C2C1A811100DF30F6 /* Enums_MeasureMode.h in Headers */, - EF0E61302C1A811100DF30F6 /* YGConfig.h in Headers */, - EF0E615A2C1A811100DF30F6 /* Enums_Justify.h in Headers */, - EF0E616B2C1A811100DF30F6 /* Numeric_Comparison.h in Headers */, - EF0E616A2C1A811100DF30F6 /* Node_Node.h in Headers */, - EF0E61372C1A811100DF30F6 /* YGValue.h in Headers */, - EF0E61702C1A811100DF30F6 /* Style_StyleValueHandle.h in Headers */, - EF0E61322C1A811100DF30F6 /* YGMacros.h in Headers */, - EF0E613B2C1A811100DF30F6 /* Algorithm_Align.h in Headers */, - EF0E61362C1A811100DF30F6 /* YGPixelGrid.h in Headers */, - EF0E615E2C1A811100DF30F6 /* Enums_Overflow.h in Headers */, - EF0E61552C1A811100DF30F6 /* Enums_Edge.h in Headers */, - EF0E61312C1A811100DF30F6 /* YGEnums.h in Headers */, - EF0E616C2C1A811100DF30F6 /* Numeric_FloatOptional.h in Headers */, + 71A5522E2CEAED47005D9FBF /* UIView+Yoga.h in Headers */, + 71A5522F2CEAED47005D9FBF /* YGLayout.h in Headers */, + 71A552302CEAED47005D9FBF /* YGLayout+Private.h in Headers */, + 71A552312CEAEDC1005D9FBF /* FlexLayout.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -543,6 +253,7 @@ isa = PBXNativeTarget; buildConfigurationList = 24DA376E1EF843C500D1AB2F /* Build configuration list for PBXNativeTarget "FlexLayout" */; buildPhases = ( + 296ABF4DC2205E5C45A6CE32 /* [CP] Check Pods Manifest.lock */, 24DA37551EF843C500D1AB2F /* Sources */, 24DA37561EF843C500D1AB2F /* Frameworks */, 24DA37571EF843C500D1AB2F /* Headers */, @@ -624,7 +335,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - EF0E614A2C1A811100DF30F6 /* CMakeLists.txt in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -638,10 +348,12 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Yoga/yoga.framework", "${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/yoga.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -649,6 +361,28 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutTests/Pods-FlexLayoutTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + 296ABF4DC2205E5C45A6CE32 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-FlexLayout-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 780CC5362B9779C60FF80C2D /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -679,31 +413,12 @@ buildActionMask = 2147483647; files = ( 24AE974A1FEAF30A00995987 /* YGLayoutExtensions.swift in Sources */, - EF0E614B2C1A811100DF30F6 /* Config_Config.cpp in Sources */, 24AE97411FEAF30A00995987 /* UIView+FlexLayout.swift in Sources */, - EF0E614F2C1A811100DF30F6 /* Debug_Log.cpp in Sources */, 24AE97421FEAF30A00995987 /* Percent.swift in Sources */, - EF0E61782C1A811100DF30F6 /* YGValue.cpp in Sources */, 715C61852ABEE4B600D5A2E0 /* YGLayout.mm in Sources */, 24AE97401FEAF30A00995987 /* FlexLayout+Private.swift in Sources */, - EF0E614D2C1A811100DF30F6 /* Debug_AssertFatal.cpp in Sources */, - EF0E61442C1A811100DF30F6 /* Algorithm_FlexLine.cpp in Sources */, - EF0E61462C1A811100DF30F6 /* Algorithm_PixelGrid.cpp in Sources */, - EF0E61772C1A811100DF30F6 /* YGPixelGrid.cpp in Sources */, - EF0E61392C1A811100DF30F6 /* Algorithm_AbsoluteLayout.cpp in Sources */, - 24AE973F1FEAF30A00995987 /* FlexLayout+Enum.swift in Sources */, 715C61812ABEE4B600D5A2E0 /* UIView+Yoga.mm in Sources */, - EF0E61752C1A811100DF30F6 /* YGNodeLayout.cpp in Sources */, - EF0E61692C1A811100DF30F6 /* Node_Node.cpp in Sources */, - EF0E61742C1A811100DF30F6 /* YGNode.cpp in Sources */, - EF0E61722C1A811100DF30F6 /* YGConfig.cpp in Sources */, - EF0E61412C1A811100DF30F6 /* Algorithm_CalculateLayout.cpp in Sources */, - EF0E61732C1A811100DF30F6 /* YGEnums.cpp in Sources */, - EF0E613F2C1A811100DF30F6 /* Algorithm_Cache.cpp in Sources */, - EF0E61642C1A811100DF30F6 /* Event_event.cpp in Sources */, - EF0E613C2C1A811100DF30F6 /* Algorithm_Baseline.cpp in Sources */, - EF0E61762C1A811100DF30F6 /* YGNodeStyle.cpp in Sources */, - EF0E61672C1A811100DF30F6 /* Node_LayoutResults.cpp in Sources */, + 71A5522D2CEAED24005D9FBF /* FlexLayout+Enum.swift in Sources */, 24AE973E1FEAF30A00995987 /* FlexLayout.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -864,6 +579,7 @@ }; 24DA376F1EF843C500D1AB2F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 224171C69665A229D0A217EF /* Pods-FlexLayout.debug.xcconfig */; buildSettings = { CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; @@ -891,6 +607,7 @@ }; 24DA37701EF843C500D1AB2F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 6B9A88E410DD5E3EA6C308DD /* Pods-FlexLayout.release.xcconfig */; buildSettings = { CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 00000000..4cc6489b --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "yoga", + "repositoryURL": "https://github.com/facebook/yoga.git", + "state": { + "branch": null, + "revision": "69b8934429702bd3ab06e8d6f709112a761b474b", + "version": "3.1.0" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift index 663bd387..ddcc190c 100644 --- a/Package.swift +++ b/Package.swift @@ -6,11 +6,14 @@ import PackageDescription let package = Package( name: "FlexLayout", platforms: [ - .iOS(.v12) + .iOS(.v12), ], products: [ .library(name: "FlexLayout", targets: ["FlexLayout"]), ], + dependencies: [ + .package(url: "https://github.com/facebook/yoga.git", from: "3.1.0"), + ], targets: [ .target( name: "FlexLayout", @@ -18,15 +21,9 @@ let package = Package( path: "Sources/Swift", publicHeadersPath: "Public" ), - .target( - name: "FlexLayoutYoga", - dependencies: [], - path: "Sources/yoga", - publicHeadersPath: "include/yoga" - ), .target( name: "FlexLayoutYogaKit", - dependencies: ["FlexLayoutYoga"], + dependencies: ["yoga"], path: "Sources/YogaKit", publicHeadersPath: "include/YogaKit" ), diff --git a/Podfile b/Podfile index fcefd2f6..5425a248 100644 --- a/Podfile +++ b/Podfile @@ -1,9 +1,13 @@ source 'https://cdn.cocoapods.org/' use_frameworks! -platform :ios, '12.0' +platform :ios, '14.0' workspace 'FlexLayout.xcworkspace' +target 'FlexLayout' do + pod 'Yoga', git: 'https://github.com/facebook/yoga.git', tag: 'v3.1.0' +end + target 'FlexLayoutTests' do project 'FlexLayout.xcodeproj' pod 'FlexLayout', path: './' diff --git a/Podfile.lock b/Podfile.lock index 5c896040..2fadbdb9 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,12 +1,15 @@ PODS: - - FlexLayout (2.0.10) + - FlexLayout (2.0.10): + - Yoga - PinLayout (1.10.5) - SwiftLint (0.55.1) + - Yoga (3.1.0) DEPENDENCIES: - FlexLayout (from `./`) - PinLayout - SwiftLint + - Yoga (from `https://github.com/facebook/yoga.git`, tag `v3.1.0`) SPEC REPOS: trunk: @@ -16,12 +19,21 @@ SPEC REPOS: EXTERNAL SOURCES: FlexLayout: :path: "./" + Yoga: + :git: https://github.com/facebook/yoga.git + :tag: v3.1.0 + +CHECKOUT OPTIONS: + Yoga: + :git: https://github.com/facebook/yoga.git + :tag: v3.1.0 SPEC CHECKSUMS: - FlexLayout: ea94491c923485f7f28891cb5b10245d22df380b + FlexLayout: aaf305c1f3203be3d8694c3835773d1e7a912b72 PinLayout: f6c2b63a5a5b24864064e1d15c67de41b4e74748 SwiftLint: 3fe909719babe5537c552ee8181c0031392be933 + Yoga: 73e3c7ca57e233ad32a1a265a8b55dcce6c4d529 -PODFILE CHECKSUM: a0f152e938c551fd661bee3ffe26ccc6175f088b +PODFILE CHECKSUM: 616cb577f11ab8498737680dedeed47c6fae4b64 COCOAPODS: 1.14.3 diff --git a/Sources/Swift/Impl/FlexLayout+Enum.swift b/Sources/Swift/Impl/FlexLayout+Enum.swift index ae2c68d6..2ba399dc 100644 --- a/Sources/Swift/Impl/FlexLayout+Enum.swift +++ b/Sources/Swift/Impl/FlexLayout+Enum.swift @@ -14,65 +14,7 @@ import UIKit -#if SWIFT_PACKAGE -import FlexLayoutYoga - -extension YGFlexDirection { - static let column = YGFlexDirectionColumn - static let columnReverse = YGFlexDirectionColumnReverse - static let row = YGFlexDirectionRow - static let rowReverse = YGFlexDirectionRowReverse -} - -extension YGJustify { - static let flexStart = YGJustifyFlexStart - static let center = YGJustifyCenter - static let flexEnd = YGJustifyFlexEnd - static let spaceBetween = YGJustifySpaceBetween - static let spaceAround = YGJustifySpaceAround - static let spaceEvenly = YGJustifySpaceEvenly -} - -extension YGAlign { - static let auto = YGAlignAuto - static let baseline = YGAlignBaseline - static let stretch = YGAlignStretch - static let flexStart = YGAlignFlexStart - static let center = YGAlignCenter - static let flexEnd = YGAlignFlexEnd - static let spaceBetween = YGAlignSpaceBetween - static let spaceAround = YGAlignSpaceAround - static let spaceEvenly = YGAlignSpaceEvenly -} - -extension YGWrap { - static let noWrap = YGWrapNoWrap - static let wrap = YGWrapWrap - static let wrapReverse = YGWrapWrapReverse -} - -extension YGPositionType { - static let relative = YGPositionTypeRelative - static let absolute = YGPositionTypeAbsolute - static let `static` = YGPositionTypeStatic -} - -extension YGDirection { - static let LTR = YGDirectionLTR - static let RTL = YGDirectionRTL - static let inherit = YGDirectionInherit -} - -extension YGDisplay { - static let flex = YGDisplayFlex - static let none = YGDisplayNone -} - -extension YGUnit { - static let percent = YGUnitPercent - static let point = YGUnitPoint -} -#endif +import yoga extension Flex.Direction { var yogaValue: YGFlexDirection { diff --git a/Sources/Swift/Impl/FlexLayout+Private.swift b/Sources/Swift/Impl/FlexLayout+Private.swift index 7436cf01..9e57ae90 100644 --- a/Sources/Swift/Impl/FlexLayout+Private.swift +++ b/Sources/Swift/Impl/FlexLayout+Private.swift @@ -8,9 +8,7 @@ import UIKit -#if SWIFT_PACKAGE -import FlexLayoutYoga -#endif +import yoga extension Flex { func valueOrUndefined(_ value: CGFloat?) -> YGValue { diff --git a/Sources/Swift/YGLayoutExtensions.swift b/Sources/Swift/YGLayoutExtensions.swift index a0e8fa8c..fea92daa 100644 --- a/Sources/Swift/YGLayoutExtensions.swift +++ b/Sources/Swift/YGLayoutExtensions.swift @@ -7,9 +7,7 @@ import CoreGraphics -#if SWIFT_PACKAGE -import FlexLayoutYoga -#endif +import yoga extension Int { public static postfix func %(value: Int) -> YGValue { diff --git a/Sources/YogaKit/include/YogaKit/YGLayout+Private.h b/Sources/YogaKit/include/YogaKit/YGLayout+Private.h index a341addb..63fd8c79 100644 --- a/Sources/YogaKit/include/YogaKit/YGLayout+Private.h +++ b/Sources/YogaKit/include/YogaKit/YGLayout+Private.h @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#import "Yoga.h" +#import #import "YGLayout.h" @interface YGLayout () diff --git a/Sources/YogaKit/include/YogaKit/YGLayout.h b/Sources/YogaKit/include/YogaKit/YGLayout.h index 5ffb00e7..337b9737 100644 --- a/Sources/YogaKit/include/YogaKit/YGLayout.h +++ b/Sources/YogaKit/include/YogaKit/YGLayout.h @@ -7,9 +7,9 @@ #import -#import "YGEnums.h" -#import "YGMacros.h" -#import "Yoga.h" +#import +#import +#import YG_EXTERN_C_BEGIN diff --git a/Sources/yoga/Algorithm_AbsoluteLayout.cpp b/Sources/yoga/Algorithm_AbsoluteLayout.cpp deleted file mode 100644 index 8da927e8..00000000 --- a/Sources/yoga/Algorithm_AbsoluteLayout.cpp +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Algorithm_AbsoluteLayout.h" -#include "Algorithm_Align.h" -#include "Algorithm_BoundAxis.h" -#include "Algorithm_CalculateLayout.h" -#include "Algorithm_TrailingPosition.h" - -namespace facebook::yoga { - -static inline void setFlexStartLayoutPosition( - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const float containingBlockWidth) { - child->setLayoutPosition( - child->style().computeFlexStartMargin( - axis, direction, containingBlockWidth) + - parent->getLayout().border(flexStartEdge(axis)) + - parent->getLayout().padding(flexStartEdge(axis)), - flexStartEdge(axis)); -} - -static inline void setFlexEndLayoutPosition( - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const float containingBlockWidth) { - child->setLayoutPosition( - getPositionOfOppositeEdge( - parent->getLayout().border(flexEndEdge(axis)) + - parent->getLayout().padding(flexEndEdge(axis)) + - child->style().computeFlexEndMargin( - axis, direction, containingBlockWidth), - axis, - parent, - child), - flexStartEdge(axis)); -} - -static inline void setCenterLayoutPosition( - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const float containingBlockWidth) { - const float parentContentBoxSize = - parent->getLayout().measuredDimension(dimension(axis)) - - parent->getLayout().border(flexStartEdge(axis)) - - parent->getLayout().border(flexEndEdge(axis)) - - parent->getLayout().padding(flexStartEdge(axis)) - - parent->getLayout().padding(flexEndEdge(axis)); - const float childOuterSize = - child->getLayout().measuredDimension(dimension(axis)) + - child->style().computeMarginForAxis(axis, containingBlockWidth); - child->setLayoutPosition( - (parentContentBoxSize - childOuterSize) / 2.0f + - parent->getLayout().border(flexStartEdge(axis)) + - parent->getLayout().padding(flexStartEdge(axis)) + - child->style().computeFlexStartMargin( - axis, direction, containingBlockWidth), - flexStartEdge(axis)); -} - -static void justifyAbsoluteChild( - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection mainAxis, - const float containingBlockWidth) { - const Justify parentJustifyContent = parent->style().justifyContent(); - switch (parentJustifyContent) { - case Justify::FlexStart: - case Justify::SpaceBetween: - setFlexStartLayoutPosition( - parent, child, direction, mainAxis, containingBlockWidth); - break; - case Justify::FlexEnd: - setFlexEndLayoutPosition( - parent, child, direction, mainAxis, containingBlockWidth); - break; - case Justify::Center: - case Justify::SpaceAround: - case Justify::SpaceEvenly: - setCenterLayoutPosition( - parent, child, direction, mainAxis, containingBlockWidth); - break; - } -} - -static void alignAbsoluteChild( - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection crossAxis, - const float containingBlockWidth) { - Align itemAlign = resolveChildAlignment(parent, child); - const Wrap parentWrap = parent->style().flexWrap(); - if (parentWrap == Wrap::WrapReverse) { - if (itemAlign == Align::FlexEnd) { - itemAlign = Align::FlexStart; - } else if (itemAlign != Align::Center) { - itemAlign = Align::FlexEnd; - } - } - - switch (itemAlign) { - case Align::Auto: - case Align::FlexStart: - case Align::Baseline: - case Align::SpaceAround: - case Align::SpaceBetween: - case Align::Stretch: - case Align::SpaceEvenly: - setFlexStartLayoutPosition( - parent, child, direction, crossAxis, containingBlockWidth); - break; - case Align::FlexEnd: - setFlexEndLayoutPosition( - parent, child, direction, crossAxis, containingBlockWidth); - break; - case Align::Center: - setCenterLayoutPosition( - parent, child, direction, crossAxis, containingBlockWidth); - break; - } -} - -// To ensure no breaking changes, we preserve the legacy way of positioning -// absolute children and determine if we should use it using an errata. -static void positionAbsoluteChildLegacy( - const yoga::Node* const containingNode, - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const bool isMainAxis, - const float containingBlockWidth, - const float containingBlockHeight) { - const bool isAxisRow = isRow(axis); - const bool shouldCenter = isMainAxis - ? parent->style().justifyContent() == Justify::Center - : resolveChildAlignment(parent, child) == Align::Center; - const bool shouldFlexEnd = isMainAxis - ? parent->style().justifyContent() == Justify::FlexEnd - : ((resolveChildAlignment(parent, child) == Align::FlexEnd) ^ - (parent->style().flexWrap() == Wrap::WrapReverse)); - - if (child->style().isFlexEndPositionDefined(axis, direction) && - !child->style().isFlexStartPositionDefined(axis, direction)) { - child->setLayoutPosition( - containingNode->getLayout().measuredDimension(dimension(axis)) - - child->getLayout().measuredDimension(dimension(axis)) - - containingNode->style().computeFlexEndBorder(axis, direction) - - child->style().computeFlexEndMargin( - axis, - direction, - isAxisRow ? containingBlockWidth : containingBlockHeight) - - child->style().computeFlexEndPosition( - axis, - direction, - isAxisRow ? containingBlockWidth : containingBlockHeight), - flexStartEdge(axis)); - } else if ( - !child->style().isFlexStartPositionDefined(axis, direction) && - shouldCenter) { - child->setLayoutPosition( - (parent->getLayout().measuredDimension(dimension(axis)) - - child->getLayout().measuredDimension(dimension(axis))) / - 2.0f, - flexStartEdge(axis)); - } else if ( - !child->style().isFlexStartPositionDefined(axis, direction) && - shouldFlexEnd) { - child->setLayoutPosition( - (parent->getLayout().measuredDimension(dimension(axis)) - - child->getLayout().measuredDimension(dimension(axis))), - flexStartEdge(axis)); - } -} - -/* - * Absolutely positioned nodes do not participate in flex layout and thus their - * positions can be determined independently from the rest of their siblings. - * For each axis there are essentially two cases: - * - * 1) The node has insets defined. In this case we can just use these to - * determine the position of the node. - * 2) The node does not have insets defined. In this case we look at the style - * of the parent to position the node. Things like justify content and - * align content will move absolute children around. If none of these - * special properties are defined, the child is positioned at the start - * (defined by flex direction) of the leading flex line. - * - * This function does that positioning for the given axis. The spec has more - * information on this topic: https://www.w3.org/TR/css-flexbox-1/#abspos-items - */ -static void positionAbsoluteChildImpl( - const yoga::Node* const containingNode, - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const bool isMainAxis, - const float containingBlockWidth, - const float containingBlockHeight) { - const bool isAxisRow = isRow(axis); - const float containingBlockSize = - isAxisRow ? containingBlockWidth : containingBlockHeight; - - // The inline-start position takes priority over the end position in the case - // that they are both set and the node has a fixed width. Thus we only have 2 - // cases here: if inline-start is defined and if inline-end is defined. - // - // Despite checking inline-start to honor prioritization of insets, we write - // to the flex-start edge because this algorithm works by positioning on the - // flex-start edge and then filling in the flex-end direction at the end if - // necessary. - if (child->style().isInlineStartPositionDefined(axis, direction)) { - const float positionRelativeToInlineStart = - child->style().computeInlineStartPosition( - axis, direction, containingBlockSize) + - containingNode->style().computeInlineStartBorder(axis, direction) + - child->style().computeInlineStartMargin( - axis, direction, containingBlockSize); - const float positionRelativeToFlexStart = - inlineStartEdge(axis, direction) != flexStartEdge(axis) - ? getPositionOfOppositeEdge( - positionRelativeToInlineStart, axis, containingNode, child) - : positionRelativeToInlineStart; - - child->setLayoutPosition(positionRelativeToFlexStart, flexStartEdge(axis)); - } else if (child->style().isInlineEndPositionDefined(axis, direction)) { - const float positionRelativeToInlineStart = - containingNode->getLayout().measuredDimension(dimension(axis)) - - child->getLayout().measuredDimension(dimension(axis)) - - containingNode->style().computeInlineEndBorder(axis, direction) - - child->style().computeInlineEndMargin( - axis, direction, containingBlockSize) - - child->style().computeInlineEndPosition( - axis, direction, containingBlockSize); - const float positionRelativeToFlexStart = - inlineStartEdge(axis, direction) != flexStartEdge(axis) - ? getPositionOfOppositeEdge( - positionRelativeToInlineStart, axis, containingNode, child) - : positionRelativeToInlineStart; - - child->setLayoutPosition(positionRelativeToFlexStart, flexStartEdge(axis)); - } else { - isMainAxis ? justifyAbsoluteChild( - parent, child, direction, axis, containingBlockWidth) - : alignAbsoluteChild( - parent, child, direction, axis, containingBlockWidth); - } -} - -static void positionAbsoluteChild( - const yoga::Node* const containingNode, - const yoga::Node* const parent, - yoga::Node* child, - const Direction direction, - const FlexDirection axis, - const bool isMainAxis, - const float containingBlockWidth, - const float containingBlockHeight) { - child->hasErrata(Errata::AbsolutePositioningIncorrect) - ? positionAbsoluteChildLegacy( - containingNode, - parent, - child, - direction, - axis, - isMainAxis, - containingBlockWidth, - containingBlockHeight) - : positionAbsoluteChildImpl( - containingNode, - parent, - child, - direction, - axis, - isMainAxis, - containingBlockWidth, - containingBlockHeight); -} - -void layoutAbsoluteChild( - const yoga::Node* const containingNode, - const yoga::Node* const node, - yoga::Node* const child, - const float containingBlockWidth, - const float containingBlockHeight, - const SizingMode widthMode, - const Direction direction, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount) { - const FlexDirection mainAxis = - resolveDirection(node->style().flexDirection(), direction); - const FlexDirection crossAxis = resolveCrossDirection(mainAxis, direction); - const bool isMainAxisRow = isRow(mainAxis); - - float childWidth = YGUndefined; - float childHeight = YGUndefined; - SizingMode childWidthSizingMode = SizingMode::MaxContent; - SizingMode childHeightSizingMode = SizingMode::MaxContent; - - auto marginRow = child->style().computeMarginForAxis( - FlexDirection::Row, containingBlockWidth); - auto marginColumn = child->style().computeMarginForAxis( - FlexDirection::Column, containingBlockWidth); - - if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) { - childWidth = child->getResolvedDimension(Dimension::Width) - .resolve(containingBlockWidth) - .unwrap() + - marginRow; - } else { - // If the child doesn't have a specified width, compute the width based on - // the left/right offsets if they're defined. - if (child->style().isFlexStartPositionDefined( - FlexDirection::Row, direction) && - child->style().isFlexEndPositionDefined( - FlexDirection::Row, direction)) { - childWidth = - containingNode->getLayout().measuredDimension(Dimension::Width) - - (containingNode->style().computeFlexStartBorder( - FlexDirection::Row, direction) + - containingNode->style().computeFlexEndBorder( - FlexDirection::Row, direction)) - - (child->style().computeFlexStartPosition( - FlexDirection::Row, direction, containingBlockWidth) + - child->style().computeFlexEndPosition( - FlexDirection::Row, direction, containingBlockWidth)); - childWidth = boundAxis( - child, - FlexDirection::Row, - childWidth, - containingBlockWidth, - containingBlockWidth); - } - } - - if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) { - childHeight = child->getResolvedDimension(Dimension::Height) - .resolve(containingBlockHeight) - .unwrap() + - marginColumn; - } else { - // If the child doesn't have a specified height, compute the height based - // on the top/bottom offsets if they're defined. - if (child->style().isFlexStartPositionDefined( - FlexDirection::Column, direction) && - child->style().isFlexEndPositionDefined( - FlexDirection::Column, direction)) { - childHeight = - containingNode->getLayout().measuredDimension(Dimension::Height) - - (containingNode->style().computeFlexStartBorder( - FlexDirection::Column, direction) + - containingNode->style().computeFlexEndBorder( - FlexDirection::Column, direction)) - - (child->style().computeFlexStartPosition( - FlexDirection::Column, direction, containingBlockHeight) + - child->style().computeFlexEndPosition( - FlexDirection::Column, direction, containingBlockHeight)); - childHeight = boundAxis( - child, - FlexDirection::Column, - childHeight, - containingBlockHeight, - containingBlockWidth); - } - } - - // Exactly one dimension needs to be defined for us to be able to do aspect - // ratio calculation. One dimension being the anchor and the other being - // flexible. - const auto& childStyle = child->style(); - if (yoga::isUndefined(childWidth) ^ yoga::isUndefined(childHeight)) { - if (childStyle.aspectRatio().isDefined()) { - if (yoga::isUndefined(childWidth)) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - } else if (yoga::isUndefined(childHeight)) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - } - } - } - - // If we're still missing one or the other dimension, measure the content. - if (yoga::isUndefined(childWidth) || yoga::isUndefined(childHeight)) { - childWidthSizingMode = yoga::isUndefined(childWidth) - ? SizingMode::MaxContent - : SizingMode::StretchFit; - childHeightSizingMode = yoga::isUndefined(childHeight) - ? SizingMode::MaxContent - : SizingMode::StretchFit; - - // If the size of the owner is defined then try to constrain the absolute - // child to that size as well. This allows text within the absolute child - // to wrap to the size of its owner. This is the same behavior as many - // browsers implement. - if (!isMainAxisRow && yoga::isUndefined(childWidth) && - widthMode != SizingMode::MaxContent && - yoga::isDefined(containingBlockWidth) && containingBlockWidth > 0) { - childWidth = containingBlockWidth; - childWidthSizingMode = SizingMode::FitContent; - } - - calculateLayoutInternal( - child, - childWidth, - childHeight, - direction, - childWidthSizingMode, - childHeightSizingMode, - containingBlockWidth, - containingBlockHeight, - false, - LayoutPassReason::kAbsMeasureChild, - layoutMarkerData, - depth, - generationCount); - childWidth = child->getLayout().measuredDimension(Dimension::Width) + - child->style().computeMarginForAxis( - FlexDirection::Row, containingBlockWidth); - childHeight = child->getLayout().measuredDimension(Dimension::Height) + - child->style().computeMarginForAxis( - FlexDirection::Column, containingBlockWidth); - } - - calculateLayoutInternal( - child, - childWidth, - childHeight, - direction, - SizingMode::StretchFit, - SizingMode::StretchFit, - containingBlockWidth, - containingBlockHeight, - true, - LayoutPassReason::kAbsLayout, - layoutMarkerData, - depth, - generationCount); - - positionAbsoluteChild( - containingNode, - node, - child, - direction, - mainAxis, - true /*isMainAxis*/, - containingBlockWidth, - containingBlockHeight); - positionAbsoluteChild( - containingNode, - node, - child, - direction, - crossAxis, - false /*isMainAxis*/, - containingBlockWidth, - containingBlockHeight); -} - -void layoutAbsoluteDescendants( - yoga::Node* containingNode, - yoga::Node* currentNode, - SizingMode widthSizingMode, - Direction currentNodeDirection, - LayoutData& layoutMarkerData, - uint32_t currentDepth, - uint32_t generationCount, - float currentNodeLeftOffsetFromContainingBlock, - float currentNodeTopOffsetFromContainingBlock, - float containingNodeAvailableInnerWidth, - float containingNodeAvailableInnerHeight) { - for (auto child : currentNode->getChildren()) { - if (child->style().display() == Display::None) { - continue; - } else if (child->style().positionType() == PositionType::Absolute) { - const bool absoluteErrata = - currentNode->hasErrata(Errata::AbsolutePercentAgainstInnerSize); - const float containingBlockWidth = absoluteErrata - ? containingNodeAvailableInnerWidth - : containingNode->getLayout().measuredDimension(Dimension::Width) - - containingNode->style().computeBorderForAxis(FlexDirection::Row); - const float containingBlockHeight = absoluteErrata - ? containingNodeAvailableInnerHeight - : containingNode->getLayout().measuredDimension(Dimension::Height) - - containingNode->style().computeBorderForAxis( - FlexDirection::Column); - - layoutAbsoluteChild( - containingNode, - currentNode, - child, - containingBlockWidth, - containingBlockHeight, - widthSizingMode, - currentNodeDirection, - layoutMarkerData, - currentDepth, - generationCount); - - /* - * At this point the child has its position set but only on its the - * parent's flexStart edge. Additionally, this position should be - * interpreted relative to the containing block of the child if it had - * insets defined. So we need to adjust the position by subtracting the - * the parents offset from the containing block. However, getting that - * offset is complicated since the two nodes can have different main/cross - * axes. - */ - const FlexDirection parentMainAxis = resolveDirection( - currentNode->style().flexDirection(), currentNodeDirection); - const FlexDirection parentCrossAxis = - resolveCrossDirection(parentMainAxis, currentNodeDirection); - - if (needsTrailingPosition(parentMainAxis)) { - const bool mainInsetsDefined = isRow(parentMainAxis) - ? child->style().horizontalInsetsDefined() - : child->style().verticalInsetsDefined(); - setChildTrailingPosition( - mainInsetsDefined ? containingNode : currentNode, - child, - parentMainAxis); - } - if (needsTrailingPosition(parentCrossAxis)) { - const bool crossInsetsDefined = isRow(parentCrossAxis) - ? child->style().horizontalInsetsDefined() - : child->style().verticalInsetsDefined(); - setChildTrailingPosition( - crossInsetsDefined ? containingNode : currentNode, - child, - parentCrossAxis); - } - - /* - * At this point we know the left and top physical edges of the child are - * set with positions that are relative to the containing block if insets - * are defined - */ - const float childLeftPosition = - child->getLayout().position(PhysicalEdge::Left); - const float childTopPosition = - child->getLayout().position(PhysicalEdge::Top); - - const float childLeftOffsetFromParent = - child->style().horizontalInsetsDefined() - ? (childLeftPosition - currentNodeLeftOffsetFromContainingBlock) - : childLeftPosition; - const float childTopOffsetFromParent = - child->style().verticalInsetsDefined() - ? (childTopPosition - currentNodeTopOffsetFromContainingBlock) - : childTopPosition; - - child->setLayoutPosition(childLeftOffsetFromParent, PhysicalEdge::Left); - child->setLayoutPosition(childTopOffsetFromParent, PhysicalEdge::Top); - } else if ( - child->style().positionType() == PositionType::Static && - !child->alwaysFormsContainingBlock()) { - const Direction childDirection = - child->resolveDirection(currentNodeDirection); - // By now all descendants of the containing block that are not absolute - // will have their positions set for left and top. - const float childLeftOffsetFromContainingBlock = - currentNodeLeftOffsetFromContainingBlock + - child->getLayout().position(PhysicalEdge::Left); - const float childTopOffsetFromContainingBlock = - currentNodeTopOffsetFromContainingBlock + - child->getLayout().position(PhysicalEdge::Top); - - layoutAbsoluteDescendants( - containingNode, - child, - widthSizingMode, - childDirection, - layoutMarkerData, - currentDepth + 1, - generationCount, - childLeftOffsetFromContainingBlock, - childTopOffsetFromContainingBlock, - containingNodeAvailableInnerWidth, - containingNodeAvailableInnerHeight); - } - } -} -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_AbsoluteLayout.h b/Sources/yoga/Algorithm_AbsoluteLayout.h deleted file mode 100644 index abbebc03..00000000 --- a/Sources/yoga/Algorithm_AbsoluteLayout.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Event_event.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -void layoutAbsoluteChild( - const yoga::Node* const containingNode, - const yoga::Node* const node, - yoga::Node* const child, - const float containingBlockWidth, - const float containingBlockHeight, - const SizingMode widthMode, - const Direction direction, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount); - -void layoutAbsoluteDescendants( - yoga::Node* containingNode, - yoga::Node* currentNode, - SizingMode widthSizingMode, - Direction currentNodeDirection, - LayoutData& layoutMarkerData, - uint32_t currentDepth, - uint32_t generationCount, - float currentNodeMainOffsetFromContainingBlock, - float currentNodeCrossOffsetFromContainingBlock, - float containingNodeAvailableInnerWidth, - float containingNodeAvailableInnerHeight); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_Align.h b/Sources/yoga/Algorithm_Align.h deleted file mode 100644 index a5573e7c..00000000 --- a/Sources/yoga/Algorithm_Align.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" - -#include "Algorithm_FlexDirection.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -inline Align resolveChildAlignment( - const yoga::Node* node, - const yoga::Node* child) { - const Align align = child->style().alignSelf() == Align::Auto - ? node->style().alignItems() - : child->style().alignSelf(); - if (align == Align::Baseline && isColumn(node->style().flexDirection())) { - return Align::FlexStart; - } - return align; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_Baseline.cpp b/Sources/yoga/Algorithm_Baseline.cpp deleted file mode 100644 index c54a400a..00000000 --- a/Sources/yoga/Algorithm_Baseline.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" - -#include "Algorithm_Align.h" -#include "Algorithm_Baseline.h" -#include "Debug_AssertFatal.h" -#include "Event_event.h" - -namespace facebook::yoga { - -float calculateBaseline(const yoga::Node* node) { - if (node->hasBaselineFunc()) { - Event::publish(node); - - const float baseline = node->baseline( - node->getLayout().measuredDimension(Dimension::Width), - node->getLayout().measuredDimension(Dimension::Height)); - - Event::publish(node); - - yoga::assertFatalWithNode( - node, - !std::isnan(baseline), - "Expect custom baseline function to not return NaN"); - return baseline; - } - - yoga::Node* baselineChild = nullptr; - const size_t childCount = node->getChildCount(); - for (size_t i = 0; i < childCount; i++) { - auto child = node->getChild(i); - if (child->getLineIndex() > 0) { - break; - } - if (child->style().positionType() == PositionType::Absolute) { - continue; - } - if (resolveChildAlignment(node, child) == Align::Baseline || - child->isReferenceBaseline()) { - baselineChild = child; - break; - } - - if (baselineChild == nullptr) { - baselineChild = child; - } - } - - if (baselineChild == nullptr) { - return node->getLayout().measuredDimension(Dimension::Height); - } - - const float baseline = calculateBaseline(baselineChild); - return baseline + baselineChild->getLayout().position(PhysicalEdge::Top); -} - -bool isBaselineLayout(const yoga::Node* node) { - if (isColumn(node->style().flexDirection())) { - return false; - } - if (node->style().alignItems() == Align::Baseline) { - return true; - } - const auto childCount = node->getChildCount(); - for (size_t i = 0; i < childCount; i++) { - auto child = node->getChild(i); - if (child->style().positionType() != PositionType::Absolute && - child->style().alignSelf() == Align::Baseline) { - return true; - } - } - - return false; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_Baseline.h b/Sources/yoga/Algorithm_Baseline.h deleted file mode 100644 index 481df1ba..00000000 --- a/Sources/yoga/Algorithm_Baseline.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -// Calculate baseline represented as an offset from the top edge of the node. -float calculateBaseline(const yoga::Node* node); - -// Whether any of the children of this node participate in baseline alignment -bool isBaselineLayout(const yoga::Node* node); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_BoundAxis.h b/Sources/yoga/Algorithm_BoundAxis.h deleted file mode 100644 index 7fe3f98a..00000000 --- a/Sources/yoga/Algorithm_BoundAxis.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Algorithm_FlexDirection.h" -#include "Enums_Dimension.h" -#include "Enums_FlexDirection.h" -#include "Node_Node.h" -#include "Numeric_Comparison.h" -#include "Numeric_FloatOptional.h" - -namespace facebook::yoga { - -inline float paddingAndBorderForAxis( - const yoga::Node* const node, - const FlexDirection axis, - const float widthSize) { - // The total padding/border for a given axis does not depend on the direction - // so hardcoding LTR here to avoid piping direction to this function - return node->style().computeInlineStartPaddingAndBorder( - axis, Direction::LTR, widthSize) + - node->style().computeInlineEndPaddingAndBorder( - axis, Direction::LTR, widthSize); -} - -inline FloatOptional boundAxisWithinMinAndMax( - const yoga::Node* const node, - const FlexDirection axis, - const FloatOptional value, - const float axisSize) { - FloatOptional min; - FloatOptional max; - - if (isColumn(axis)) { - min = node->style().minDimension(Dimension::Height).resolve(axisSize); - max = node->style().maxDimension(Dimension::Height).resolve(axisSize); - } else if (isRow(axis)) { - min = node->style().minDimension(Dimension::Width).resolve(axisSize); - max = node->style().maxDimension(Dimension::Width).resolve(axisSize); - } - - if (max >= FloatOptional{0} && value > max) { - return max; - } - - if (min >= FloatOptional{0} && value < min) { - return min; - } - - return value; -} - -// Like boundAxisWithinMinAndMax but also ensures that the value doesn't -// go below the padding and border amount. -inline float boundAxis( - const yoga::Node* const node, - const FlexDirection axis, - const float value, - const float axisSize, - const float widthSize) { - return yoga::maxOrDefined( - boundAxisWithinMinAndMax(node, axis, FloatOptional{value}, axisSize) - .unwrap(), - paddingAndBorderForAxis(node, axis, widthSize)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_Cache.cpp b/Sources/yoga/Algorithm_Cache.cpp deleted file mode 100644 index c0d826a8..00000000 --- a/Sources/yoga/Algorithm_Cache.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Algorithm_Cache.h" -#include "Algorithm_PixelGrid.h" -#include "Numeric_Comparison.h" - -namespace facebook::yoga { - -static inline bool sizeIsExactAndMatchesOldMeasuredSize( - SizingMode sizeMode, - float size, - float lastComputedSize) { - return sizeMode == SizingMode::StretchFit && - yoga::inexactEquals(size, lastComputedSize); -} - -static inline bool oldSizeIsMaxContentAndStillFits( - SizingMode sizeMode, - float size, - SizingMode lastSizeMode, - float lastComputedSize) { - return sizeMode == SizingMode::FitContent && - lastSizeMode == SizingMode::MaxContent && - (size >= lastComputedSize || yoga::inexactEquals(size, lastComputedSize)); -} - -static inline bool newSizeIsStricterAndStillValid( - SizingMode sizeMode, - float size, - SizingMode lastSizeMode, - float lastSize, - float lastComputedSize) { - return lastSizeMode == SizingMode::FitContent && - sizeMode == SizingMode::FitContent && yoga::isDefined(lastSize) && - yoga::isDefined(size) && yoga::isDefined(lastComputedSize) && - lastSize > size && - (lastComputedSize <= size || yoga::inexactEquals(size, lastComputedSize)); -} - -bool canUseCachedMeasurement( - const SizingMode widthMode, - const float availableWidth, - const SizingMode heightMode, - const float availableHeight, - const SizingMode lastWidthMode, - const float lastAvailableWidth, - const SizingMode lastHeightMode, - const float lastAvailableHeight, - const float lastComputedWidth, - const float lastComputedHeight, - const float marginRow, - const float marginColumn, - const yoga::Config* const config) { - if ((yoga::isDefined(lastComputedHeight) && lastComputedHeight < 0) || - ((yoga::isDefined(lastComputedWidth)) && lastComputedWidth < 0)) { - return false; - } - - const float pointScaleFactor = config->getPointScaleFactor(); - - bool useRoundedComparison = config != nullptr && pointScaleFactor != 0; - const float effectiveWidth = useRoundedComparison - ? roundValueToPixelGrid(availableWidth, pointScaleFactor, false, false) - : availableWidth; - const float effectiveHeight = useRoundedComparison - ? roundValueToPixelGrid(availableHeight, pointScaleFactor, false, false) - : availableHeight; - const float effectiveLastWidth = useRoundedComparison - ? roundValueToPixelGrid( - lastAvailableWidth, pointScaleFactor, false, false) - : lastAvailableWidth; - const float effectiveLastHeight = useRoundedComparison - ? roundValueToPixelGrid( - lastAvailableHeight, pointScaleFactor, false, false) - : lastAvailableHeight; - - const bool hasSameWidthSpec = lastWidthMode == widthMode && - yoga::inexactEquals(effectiveLastWidth, effectiveWidth); - const bool hasSameHeightSpec = lastHeightMode == heightMode && - yoga::inexactEquals(effectiveLastHeight, effectiveHeight); - - const bool widthIsCompatible = - hasSameWidthSpec || - sizeIsExactAndMatchesOldMeasuredSize( - widthMode, availableWidth - marginRow, lastComputedWidth) || - oldSizeIsMaxContentAndStillFits( - widthMode, - availableWidth - marginRow, - lastWidthMode, - lastComputedWidth) || - newSizeIsStricterAndStillValid( - widthMode, - availableWidth - marginRow, - lastWidthMode, - lastAvailableWidth, - lastComputedWidth); - - const bool heightIsCompatible = hasSameHeightSpec || - sizeIsExactAndMatchesOldMeasuredSize( - heightMode, - availableHeight - marginColumn, - lastComputedHeight) || - oldSizeIsMaxContentAndStillFits(heightMode, - availableHeight - marginColumn, - lastHeightMode, - lastComputedHeight) || - newSizeIsStricterAndStillValid(heightMode, - availableHeight - marginColumn, - lastHeightMode, - lastAvailableHeight, - lastComputedHeight); - - return widthIsCompatible && heightIsCompatible; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_Cache.h b/Sources/yoga/Algorithm_Cache.h deleted file mode 100644 index 11f97ca1..00000000 --- a/Sources/yoga/Algorithm_Cache.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Algorithm_SizingMode.h" -#include "Config_Config.h" - -namespace facebook::yoga { - -bool canUseCachedMeasurement( - SizingMode widthMode, - float availableWidth, - SizingMode heightMode, - float availableHeight, - SizingMode lastWidthMode, - float lastAvailableWidth, - SizingMode lastHeightMode, - float lastAvailableHeight, - float lastComputedWidth, - float lastComputedHeight, - float marginRow, - float marginColumn, - const yoga::Config* config); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_CalculateLayout.cpp b/Sources/yoga/Algorithm_CalculateLayout.cpp deleted file mode 100644 index 31816cbf..00000000 --- a/Sources/yoga/Algorithm_CalculateLayout.cpp +++ /dev/null @@ -1,2372 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include -#include -#include - -#include "Yoga.h" - -#include "Algorithm_AbsoluteLayout.h" -#include "Algorithm_Align.h" -#include "Algorithm_Baseline.h" -#include "Algorithm_BoundAxis.h" -#include "Algorithm_Cache.h" -#include "Algorithm_CalculateLayout.h" -#include "Algorithm_FlexDirection.h" -#include "Algorithm_FlexLine.h" -#include "Algorithm_PixelGrid.h" -#include "Algorithm_SizingMode.h" -#include "Algorithm_TrailingPosition.h" -#include "Debug_AssertFatal.h" -#include "Debug_Log.h" -#include "Event_event.h" -#include "Node_Node.h" -#include "Numeric_Comparison.h" -#include "Numeric_FloatOptional.h" - -namespace facebook::yoga { - -std::atomic gCurrentGenerationCount(0); - -static void constrainMaxSizeForMode( - const yoga::Node* node, - FlexDirection axis, - float ownerAxisSize, - float ownerWidth, - /*in_out*/ SizingMode* mode, - /*in_out*/ float* size) { - const FloatOptional maxSize = - node->style().maxDimension(dimension(axis)).resolve(ownerAxisSize) + - FloatOptional(node->style().computeMarginForAxis(axis, ownerWidth)); - switch (*mode) { - case SizingMode::StretchFit: - case SizingMode::FitContent: - *size = (maxSize.isUndefined() || *size < maxSize.unwrap()) - ? *size - : maxSize.unwrap(); - break; - case SizingMode::MaxContent: - if (maxSize.isDefined()) { - *mode = SizingMode::FitContent; - *size = maxSize.unwrap(); - } - break; - } -} - -static void computeFlexBasisForChild( - const yoga::Node* const node, - yoga::Node* const child, - const float width, - const SizingMode widthMode, - const float height, - const float ownerWidth, - const float ownerHeight, - const SizingMode heightMode, - const Direction direction, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount) { - const FlexDirection mainAxis = - resolveDirection(node->style().flexDirection(), direction); - const bool isMainAxisRow = isRow(mainAxis); - const float mainAxisSize = isMainAxisRow ? width : height; - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - - float childWidth; - float childHeight; - SizingMode childWidthSizingMode; - SizingMode childHeightSizingMode; - - const FloatOptional resolvedFlexBasis = - child->resolveFlexBasisPtr().resolve(mainAxisownerSize); - const bool isRowStyleDimDefined = - child->hasDefiniteLength(Dimension::Width, ownerWidth); - const bool isColumnStyleDimDefined = - child->hasDefiniteLength(Dimension::Height, ownerHeight); - - if (resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize)) { - if (child->getLayout().computedFlexBasis.isUndefined() || - (child->getConfig()->isExperimentalFeatureEnabled( - ExperimentalFeature::WebFlexBasis) && - child->getLayout().computedFlexBasisGeneration != generationCount)) { - const FloatOptional paddingAndBorder = - FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth)); - child->setLayoutComputedFlexBasis( - yoga::maxOrDefined(resolvedFlexBasis, paddingAndBorder)); - } - } else if (isMainAxisRow && isRowStyleDimDefined) { - // The width is definite, so use that as the flex basis. - const FloatOptional paddingAndBorder = FloatOptional( - paddingAndBorderForAxis(child, FlexDirection::Row, ownerWidth)); - - child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getResolvedDimension(Dimension::Width).resolve(ownerWidth), - paddingAndBorder)); - } else if (!isMainAxisRow && isColumnStyleDimDefined) { - // The height is definite, so use that as the flex basis. - const FloatOptional paddingAndBorder = FloatOptional( - paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth)); - child->setLayoutComputedFlexBasis(yoga::maxOrDefined( - child->getResolvedDimension(Dimension::Height).resolve(ownerHeight), - paddingAndBorder)); - } else { - // Compute the flex basis and hypothetical main size (i.e. the clamped flex - // basis). - childWidth = YGUndefined; - childHeight = YGUndefined; - childWidthSizingMode = SizingMode::MaxContent; - childHeightSizingMode = SizingMode::MaxContent; - - auto marginRow = - child->style().computeMarginForAxis(FlexDirection::Row, ownerWidth); - auto marginColumn = - child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth); - - if (isRowStyleDimDefined) { - childWidth = child->getResolvedDimension(Dimension::Width) - .resolve(ownerWidth) - .unwrap() + - marginRow; - childWidthSizingMode = SizingMode::StretchFit; - } - if (isColumnStyleDimDefined) { - childHeight = child->getResolvedDimension(Dimension::Height) - .resolve(ownerHeight) - .unwrap() + - marginColumn; - childHeightSizingMode = SizingMode::StretchFit; - } - - // The W3C spec doesn't say anything about the 'overflow' property, but all - // major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->style().overflow() == Overflow::Scroll) || - node->style().overflow() != Overflow::Scroll) { - if (yoga::isUndefined(childWidth) && yoga::isDefined(width)) { - childWidth = width; - childWidthSizingMode = SizingMode::FitContent; - } - } - - if ((isMainAxisRow && node->style().overflow() == Overflow::Scroll) || - node->style().overflow() != Overflow::Scroll) { - if (yoga::isUndefined(childHeight) && yoga::isDefined(height)) { - childHeight = height; - childHeightSizingMode = SizingMode::FitContent; - } - } - - const auto& childStyle = child->style(); - if (childStyle.aspectRatio().isDefined()) { - if (!isMainAxisRow && childWidthSizingMode == SizingMode::StretchFit) { - childHeight = marginColumn + - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightSizingMode = SizingMode::StretchFit; - } else if ( - isMainAxisRow && childHeightSizingMode == SizingMode::StretchFit) { - childWidth = marginRow + - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthSizingMode = SizingMode::StretchFit; - } - } - - // If child has no defined size in the cross axis and is set to stretch, set - // the cross axis to be measured exactly with the available inner width - - const bool hasExactWidth = - yoga::isDefined(width) && widthMode == SizingMode::StretchFit; - const bool childWidthStretch = - resolveChildAlignment(node, child) == Align::Stretch && - childWidthSizingMode != SizingMode::StretchFit; - if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && - childWidthStretch) { - childWidth = width; - childWidthSizingMode = SizingMode::StretchFit; - if (childStyle.aspectRatio().isDefined()) { - childHeight = - (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightSizingMode = SizingMode::StretchFit; - } - } - - const bool hasExactHeight = - yoga::isDefined(height) && heightMode == SizingMode::StretchFit; - const bool childHeightStretch = - resolveChildAlignment(node, child) == Align::Stretch && - childHeightSizingMode != SizingMode::StretchFit; - if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && - childHeightStretch) { - childHeight = height; - childHeightSizingMode = SizingMode::StretchFit; - - if (childStyle.aspectRatio().isDefined()) { - childWidth = - (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthSizingMode = SizingMode::StretchFit; - } - } - - constrainMaxSizeForMode( - child, - FlexDirection::Row, - ownerWidth, - ownerWidth, - &childWidthSizingMode, - &childWidth); - constrainMaxSizeForMode( - child, - FlexDirection::Column, - ownerHeight, - ownerWidth, - &childHeightSizingMode, - &childHeight); - - // Measure the child - calculateLayoutInternal( - child, - childWidth, - childHeight, - direction, - childWidthSizingMode, - childHeightSizingMode, - ownerWidth, - ownerHeight, - false, - LayoutPassReason::kMeasureChild, - layoutMarkerData, - depth, - generationCount); - - child->setLayoutComputedFlexBasis(FloatOptional(yoga::maxOrDefined( - child->getLayout().measuredDimension(dimension(mainAxis)), - paddingAndBorderForAxis(child, mainAxis, ownerWidth)))); - } - child->setLayoutComputedFlexBasisGeneration(generationCount); -} - -static void measureNodeWithMeasureFunc( - yoga::Node* const node, - float availableWidth, - float availableHeight, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight, - LayoutData& layoutMarkerData, - const LayoutPassReason reason) { - yoga::assertFatalWithNode( - node, - node->hasMeasureFunc(), - "Expected node to have custom measure function"); - - if (widthSizingMode == SizingMode::MaxContent) { - availableWidth = YGUndefined; - } - if (heightSizingMode == SizingMode::MaxContent) { - availableHeight = YGUndefined; - } - - const auto& layout = node->getLayout(); - const float paddingAndBorderAxisRow = layout.padding(PhysicalEdge::Left) + - layout.padding(PhysicalEdge::Right) + layout.border(PhysicalEdge::Left) + - layout.border(PhysicalEdge::Right); - const float paddingAndBorderAxisColumn = layout.padding(PhysicalEdge::Top) + - layout.padding(PhysicalEdge::Bottom) + layout.border(PhysicalEdge::Top) + - layout.border(PhysicalEdge::Bottom); - - // We want to make sure we don't call measure with negative size - const float innerWidth = yoga::isUndefined(availableWidth) - ? availableWidth - : yoga::maxOrDefined(0.0f, availableWidth - paddingAndBorderAxisRow); - const float innerHeight = yoga::isUndefined(availableHeight) - ? availableHeight - : yoga::maxOrDefined(0.0f, availableHeight - paddingAndBorderAxisColumn); - - if (widthSizingMode == SizingMode::StretchFit && - heightSizingMode == SizingMode::StretchFit) { - // Don't bother sizing the text if both dimensions are already defined. - node->setLayoutMeasuredDimension( - boundAxis( - node, FlexDirection::Row, availableWidth, ownerWidth, ownerWidth), - Dimension::Width); - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Column, - availableHeight, - ownerHeight, - ownerWidth), - Dimension::Height); - } else { - Event::publish(node); - - // Measure the text under the current constraints. - const YGSize measuredSize = node->measure( - innerWidth, - measureMode(widthSizingMode), - innerHeight, - measureMode(heightSizingMode)); - - layoutMarkerData.measureCallbacks += 1; - layoutMarkerData.measureCallbackReasonsCount[static_cast(reason)] += - 1; - - Event::publish( - node, - {innerWidth, - unscopedEnum(measureMode(widthSizingMode)), - innerHeight, - unscopedEnum(measureMode(heightSizingMode)), - measuredSize.width, - measuredSize.height, - reason}); - - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Row, - (widthSizingMode == SizingMode::MaxContent || - widthSizingMode == SizingMode::FitContent) - ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth, - ownerWidth, - ownerWidth), - Dimension::Width); - - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Column, - (heightSizingMode == SizingMode::MaxContent || - heightSizingMode == SizingMode::FitContent) - ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight, - ownerHeight, - ownerWidth), - Dimension::Height); - } -} - -// For nodes with no children, use the available values if they were provided, -// or the minimum size as indicated by the padding and border sizes. -static void measureNodeWithoutChildren( - yoga::Node* const node, - const float availableWidth, - const float availableHeight, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight) { - const auto& layout = node->getLayout(); - - float width = availableWidth; - if (widthSizingMode == SizingMode::MaxContent || - widthSizingMode == SizingMode::FitContent) { - width = layout.padding(PhysicalEdge::Left) + - layout.padding(PhysicalEdge::Right) + - layout.border(PhysicalEdge::Left) + layout.border(PhysicalEdge::Right); - } - node->setLayoutMeasuredDimension( - boundAxis(node, FlexDirection::Row, width, ownerWidth, ownerWidth), - Dimension::Width); - - float height = availableHeight; - if (heightSizingMode == SizingMode::MaxContent || - heightSizingMode == SizingMode::FitContent) { - height = layout.padding(PhysicalEdge::Top) + - layout.padding(PhysicalEdge::Bottom) + - layout.border(PhysicalEdge::Top) + layout.border(PhysicalEdge::Bottom); - } - node->setLayoutMeasuredDimension( - boundAxis(node, FlexDirection::Column, height, ownerHeight, ownerWidth), - Dimension::Height); -} - -static bool measureNodeWithFixedSize( - yoga::Node* const node, - const float availableWidth, - const float availableHeight, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight) { - if ((yoga::isDefined(availableWidth) && - widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) || - (yoga::isDefined(availableHeight) && - heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) || - (widthSizingMode == SizingMode::StretchFit && - heightSizingMode == SizingMode::StretchFit)) { - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Row, - yoga::isUndefined(availableWidth) || - (widthSizingMode == SizingMode::FitContent && - availableWidth < 0.0f) - ? 0.0f - : availableWidth, - ownerWidth, - ownerWidth), - Dimension::Width); - - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Column, - yoga::isUndefined(availableHeight) || - (heightSizingMode == SizingMode::FitContent && - availableHeight < 0.0f) - ? 0.0f - : availableHeight, - ownerHeight, - ownerWidth), - Dimension::Height); - return true; - } - - return false; -} - -static void zeroOutLayoutRecursively(yoga::Node* const node) { - node->getLayout() = {}; - node->setLayoutDimension(0, Dimension::Width); - node->setLayoutDimension(0, Dimension::Height); - node->setHasNewLayout(true); - - node->cloneChildrenIfNeeded(); - for (const auto child : node->getChildren()) { - zeroOutLayoutRecursively(child); - } -} - -static float calculateAvailableInnerDimension( - const yoga::Node* const node, - const Dimension dimension, - const float availableDim, - const float paddingAndBorder, - const float ownerDim) { - float availableInnerDim = availableDim - paddingAndBorder; - // Max dimension overrides predefined dimension value; Min dimension in turn - // overrides both of the above - if (yoga::isDefined(availableInnerDim)) { - // We want to make sure our available height does not violate min and max - // constraints - const FloatOptional minDimensionOptional = - node->style().minDimension(dimension).resolve(ownerDim); - const float minInnerDim = minDimensionOptional.isUndefined() - ? 0.0f - : minDimensionOptional.unwrap() - paddingAndBorder; - - const FloatOptional maxDimensionOptional = - node->style().maxDimension(dimension).resolve(ownerDim); - - const float maxInnerDim = maxDimensionOptional.isUndefined() - ? FLT_MAX - : maxDimensionOptional.unwrap() - paddingAndBorder; - availableInnerDim = yoga::maxOrDefined( - yoga::minOrDefined(availableInnerDim, maxInnerDim), minInnerDim); - } - - return availableInnerDim; -} - -static float computeFlexBasisForChildren( - yoga::Node* const node, - const float availableInnerWidth, - const float availableInnerHeight, - SizingMode widthSizingMode, - SizingMode heightSizingMode, - Direction direction, - FlexDirection mainAxis, - bool performLayout, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount) { - float totalOuterFlexBasis = 0.0f; - YGNodeRef singleFlexChild = nullptr; - const auto& children = node->getChildren(); - SizingMode sizingModeMainDim = - isRow(mainAxis) ? widthSizingMode : heightSizingMode; - // If there is only one child with flexGrow + flexShrink it means we can set - // the computedFlexBasis to 0 instead of measuring and shrinking / flexing the - // child to exactly match the remaining space - if (sizingModeMainDim == SizingMode::StretchFit) { - for (auto child : children) { - if (child->isNodeFlexible()) { - if (singleFlexChild != nullptr || - yoga::inexactEquals(child->resolveFlexGrow(), 0.0f) || - yoga::inexactEquals(child->resolveFlexShrink(), 0.0f)) { - // There is already a flexible child, or this flexible child doesn't - // have flexGrow and flexShrink, abort - singleFlexChild = nullptr; - break; - } else { - singleFlexChild = child; - } - } - } - } - - for (auto child : children) { - child->resolveDimension(); - if (child->style().display() == Display::None) { - zeroOutLayoutRecursively(child); - child->setHasNewLayout(true); - child->setDirty(false); - continue; - } - if (performLayout) { - // Set the initial position (relative to the owner). - const Direction childDirection = child->resolveDirection(direction); - const float mainDim = - isRow(mainAxis) ? availableInnerWidth : availableInnerHeight; - const float crossDim = - isRow(mainAxis) ? availableInnerHeight : availableInnerWidth; - child->setPosition( - childDirection, mainDim, crossDim, availableInnerWidth); - } - - if (child->style().positionType() == PositionType::Absolute) { - continue; - } - if (child == singleFlexChild) { - child->setLayoutComputedFlexBasisGeneration(generationCount); - child->setLayoutComputedFlexBasis(FloatOptional(0)); - } else { - computeFlexBasisForChild( - node, - child, - availableInnerWidth, - widthSizingMode, - availableInnerHeight, - availableInnerWidth, - availableInnerHeight, - heightSizingMode, - direction, - layoutMarkerData, - depth, - generationCount); - } - - totalOuterFlexBasis += - (child->getLayout().computedFlexBasis.unwrap() + - child->style().computeMarginForAxis(mainAxis, availableInnerWidth)); - } - - return totalOuterFlexBasis; -} - -// It distributes the free space to the flexible items and ensures that the size -// of the flex items abide the min and max constraints. At the end of this -// function the child nodes would have proper size. Prior using this function -// please ensure that distributeFreeSpaceFirstPass is called. -static float distributeFreeSpaceSecondPass( - FlexLine& flexLine, - yoga::Node* const node, - const FlexDirection mainAxis, - const FlexDirection crossAxis, - const Direction direction, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool mainAxisOverflows, - const SizingMode sizingModeCrossDim, - const bool performLayout, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount) { - float childFlexBasis = 0; - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float deltaFreeSpace = 0; - const bool isMainAxisRow = isRow(mainAxis); - const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap; - - for (auto currentLineChild : flexLine.itemsInFlow) { - childFlexBasis = boundAxisWithinMinAndMax( - currentLineChild, - mainAxis, - currentLineChild->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - float updatedMainSize = childFlexBasis; - - if (yoga::isDefined(flexLine.layout.remainingFreeSpace) && - flexLine.layout.remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -currentLineChild->resolveFlexShrink() * childFlexBasis; - // Is this child able to shrink? - if (flexShrinkScaledFactor != 0) { - float childSize; - - if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) && - flexLine.layout.totalFlexShrinkScaledFactors == 0) { - childSize = childFlexBasis + flexShrinkScaledFactor; - } else { - childSize = childFlexBasis + - (flexLine.layout.remainingFreeSpace / - flexLine.layout.totalFlexShrinkScaledFactors) * - flexShrinkScaledFactor; - } - - updatedMainSize = boundAxis( - currentLineChild, - mainAxis, - childSize, - availableInnerMainDim, - availableInnerWidth); - } - } else if ( - yoga::isDefined(flexLine.layout.remainingFreeSpace) && - flexLine.layout.remainingFreeSpace > 0) { - flexGrowFactor = currentLineChild->resolveFlexGrow(); - - // Is this child able to grow? - if (!std::isnan(flexGrowFactor) && flexGrowFactor != 0) { - updatedMainSize = boundAxis( - currentLineChild, - mainAxis, - childFlexBasis + - flexLine.layout.remainingFreeSpace / - flexLine.layout.totalFlexGrowFactors * flexGrowFactor, - availableInnerMainDim, - availableInnerWidth); - } - } - - deltaFreeSpace += updatedMainSize - childFlexBasis; - - const float marginMain = currentLineChild->style().computeMarginForAxis( - mainAxis, availableInnerWidth); - const float marginCross = currentLineChild->style().computeMarginForAxis( - crossAxis, availableInnerWidth); - - float childCrossSize; - float childMainSize = updatedMainSize + marginMain; - SizingMode childCrossSizingMode; - SizingMode childMainSizingMode = SizingMode::StretchFit; - - const auto& childStyle = currentLineChild->style(); - if (childStyle.aspectRatio().isDefined()) { - childCrossSize = isMainAxisRow - ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() - : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); - childCrossSizingMode = SizingMode::StretchFit; - - childCrossSize += marginCross; - } else if ( - !std::isnan(availableInnerCrossDim) && - !currentLineChild->hasDefiniteLength( - dimension(crossAxis), availableInnerCrossDim) && - sizingModeCrossDim == SizingMode::StretchFit && - !(isNodeFlexWrap && mainAxisOverflows) && - resolveChildAlignment(node, currentLineChild) == Align::Stretch && - !currentLineChild->style().flexStartMarginIsAuto( - crossAxis, direction) && - !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction)) { - childCrossSize = availableInnerCrossDim; - childCrossSizingMode = SizingMode::StretchFit; - } else if (!currentLineChild->hasDefiniteLength( - dimension(crossAxis), availableInnerCrossDim)) { - childCrossSize = availableInnerCrossDim; - childCrossSizingMode = yoga::isUndefined(childCrossSize) - ? SizingMode::MaxContent - : SizingMode::FitContent; - } else { - childCrossSize = - currentLineChild->getResolvedDimension(dimension(crossAxis)) - .resolve(availableInnerCrossDim) - .unwrap() + - marginCross; - const bool isLoosePercentageMeasurement = - currentLineChild->getResolvedDimension(dimension(crossAxis)).unit() == - Unit::Percent && - sizingModeCrossDim != SizingMode::StretchFit; - childCrossSizingMode = - yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement - ? SizingMode::MaxContent - : SizingMode::StretchFit; - } - - constrainMaxSizeForMode( - currentLineChild, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainSizingMode, - &childMainSize); - constrainMaxSizeForMode( - currentLineChild, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossSizingMode, - &childCrossSize); - - const bool requiresStretchLayout = - !currentLineChild->hasDefiniteLength( - dimension(crossAxis), availableInnerCrossDim) && - resolveChildAlignment(node, currentLineChild) == Align::Stretch && - !currentLineChild->style().flexStartMarginIsAuto( - crossAxis, direction) && - !currentLineChild->style().flexEndMarginIsAuto(crossAxis, direction); - - const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; - - const SizingMode childWidthSizingMode = - isMainAxisRow ? childMainSizingMode : childCrossSizingMode; - const SizingMode childHeightSizingMode = - !isMainAxisRow ? childMainSizingMode : childCrossSizingMode; - - const bool isLayoutPass = performLayout && !requiresStretchLayout; - // Recursively call the layout algorithm for this child with the updated - // main size. - calculateLayoutInternal( - currentLineChild, - childWidth, - childHeight, - node->getLayout().direction(), - childWidthSizingMode, - childHeightSizingMode, - availableInnerWidth, - availableInnerHeight, - isLayoutPass, - isLayoutPass ? LayoutPassReason::kFlexLayout - : LayoutPassReason::kFlexMeasure, - layoutMarkerData, - depth, - generationCount); - node->setLayoutHadOverflow( - node->getLayout().hadOverflow() || - currentLineChild->getLayout().hadOverflow()); - } - return deltaFreeSpace; -} - -// It distributes the free space to the flexible items.For those flexible items -// whose min and max constraints are triggered, those flex item's clamped size -// is removed from the remaingfreespace. -static void distributeFreeSpaceFirstPass( - FlexLine& flexLine, - const FlexDirection mainAxis, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerWidth) { - float flexShrinkScaledFactor = 0; - float flexGrowFactor = 0; - float baseMainSize = 0; - float boundMainSize = 0; - float deltaFreeSpace = 0; - - for (auto currentLineChild : flexLine.itemsInFlow) { - float childFlexBasis = boundAxisWithinMinAndMax( - currentLineChild, - mainAxis, - currentLineChild->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - - if (flexLine.layout.remainingFreeSpace < 0) { - flexShrinkScaledFactor = - -currentLineChild->resolveFlexShrink() * childFlexBasis; - - // Is this child able to shrink? - if (yoga::isDefined(flexShrinkScaledFactor) && - flexShrinkScaledFactor != 0) { - baseMainSize = childFlexBasis + - flexLine.layout.remainingFreeSpace / - flexLine.layout.totalFlexShrinkScaledFactors * - flexShrinkScaledFactor; - boundMainSize = boundAxis( - currentLineChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); - if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) && - baseMainSize != boundMainSize) { - // By excluding this item's size and flex factor from remaining, this - // item's min/max constraints should also trigger in the second pass - // resulting in the item's size calculation being identical in the - // first and second passes. - deltaFreeSpace += boundMainSize - childFlexBasis; - flexLine.layout.totalFlexShrinkScaledFactors -= - (-currentLineChild->resolveFlexShrink() * - currentLineChild->getLayout().computedFlexBasis.unwrap()); - } - } - } else if ( - yoga::isDefined(flexLine.layout.remainingFreeSpace) && - flexLine.layout.remainingFreeSpace > 0) { - flexGrowFactor = currentLineChild->resolveFlexGrow(); - - // Is this child able to grow? - if (yoga::isDefined(flexGrowFactor) && flexGrowFactor != 0) { - baseMainSize = childFlexBasis + - flexLine.layout.remainingFreeSpace / - flexLine.layout.totalFlexGrowFactors * flexGrowFactor; - boundMainSize = boundAxis( - currentLineChild, - mainAxis, - baseMainSize, - availableInnerMainDim, - availableInnerWidth); - - if (yoga::isDefined(baseMainSize) && yoga::isDefined(boundMainSize) && - baseMainSize != boundMainSize) { - // By excluding this item's size and flex factor from remaining, this - // item's min/max constraints should also trigger in the second pass - // resulting in the item's size calculation being identical in the - // first and second passes. - deltaFreeSpace += boundMainSize - childFlexBasis; - flexLine.layout.totalFlexGrowFactors -= flexGrowFactor; - } - } - } - } - flexLine.layout.remainingFreeSpace -= deltaFreeSpace; -} - -// Do two passes over the flex items to figure out how to distribute the -// remaining space. -// -// The first pass finds the items whose min/max constraints trigger, freezes -// them at those sizes, and excludes those sizes from the remaining space. -// -// The second pass sets the size of each flexible item. It distributes the -// remaining space amongst the items whose min/max constraints didn't trigger in -// the first pass. For the other items, it sets their sizes by forcing their -// min/max constraints to trigger again. -// -// This two pass approach for resolving min/max constraints deviates from the -// spec. The spec -// (https://www.w3.org/TR/CSS-flexbox-1/#resolve-flexible-lengths) describes a -// process that needs to be repeated a variable number of times. The algorithm -// implemented here won't handle all cases but it was simpler to implement and -// it mitigates performance concerns because we know exactly how many passes -// it'll do. -// -// At the end of this function the child nodes would have the proper size -// assigned to them. -// -static void resolveFlexibleLength( - yoga::Node* const node, - FlexLine& flexLine, - const FlexDirection mainAxis, - const FlexDirection crossAxis, - const Direction direction, - const float mainAxisownerSize, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const float availableInnerHeight, - const bool mainAxisOverflows, - const SizingMode sizingModeCrossDim, - const bool performLayout, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount) { - const float originalFreeSpace = flexLine.layout.remainingFreeSpace; - // First pass: detect the flex items whose min/max constraints trigger - distributeFreeSpaceFirstPass( - flexLine, - mainAxis, - mainAxisownerSize, - availableInnerMainDim, - availableInnerWidth); - - // Second pass: resolve the sizes of the flexible items - const float distributedFreeSpace = distributeFreeSpaceSecondPass( - flexLine, - node, - mainAxis, - crossAxis, - direction, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - mainAxisOverflows, - sizingModeCrossDim, - performLayout, - layoutMarkerData, - depth, - generationCount); - - flexLine.layout.remainingFreeSpace = originalFreeSpace - distributedFreeSpace; -} - -static void justifyMainAxis( - yoga::Node* const node, - FlexLine& flexLine, - const size_t startOfLineIndex, - const FlexDirection mainAxis, - const FlexDirection crossAxis, - const Direction direction, - const SizingMode sizingModeMainDim, - const SizingMode sizingModeCrossDim, - const float mainAxisownerSize, - const float ownerWidth, - const float availableInnerMainDim, - const float availableInnerCrossDim, - const float availableInnerWidth, - const bool performLayout) { - const auto& style = node->style(); - - const float leadingPaddingAndBorderMain = - node->style().computeFlexStartPaddingAndBorder( - mainAxis, direction, ownerWidth); - const float trailingPaddingAndBorderMain = - node->style().computeFlexEndPaddingAndBorder( - mainAxis, direction, ownerWidth); - - const float gap = node->style().computeGapForAxis(mainAxis); - // If we are using "at most" rules in the main axis, make sure that - // remainingFreeSpace is 0 when min main dimension is not given - if (sizingModeMainDim == SizingMode::FitContent && - flexLine.layout.remainingFreeSpace > 0) { - if (style.minDimension(dimension(mainAxis)).isDefined() && - style.minDimension(dimension(mainAxis)) - .resolve(mainAxisownerSize) - .isDefined()) { - // This condition makes sure that if the size of main dimension(after - // considering child nodes main dim, leading and trailing padding etc) - // falls below min dimension, then the remainingFreeSpace is reassigned - // considering the min dimension - - // `minAvailableMainDim` denotes minimum available space in which child - // can be laid out, it will exclude space consumed by padding and border. - const float minAvailableMainDim = style.minDimension(dimension(mainAxis)) - .resolve(mainAxisownerSize) - .unwrap() - - leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; - const float occupiedSpaceByChildNodes = - availableInnerMainDim - flexLine.layout.remainingFreeSpace; - flexLine.layout.remainingFreeSpace = yoga::maxOrDefined( - 0.0f, minAvailableMainDim - occupiedSpaceByChildNodes); - } else { - flexLine.layout.remainingFreeSpace = 0; - } - } - - int numberOfAutoMarginsOnCurrentLine = 0; - for (size_t i = startOfLineIndex; i < flexLine.endOfLineIndex; i++) { - auto child = node->getChild(i); - if (child->style().positionType() != PositionType::Absolute) { - if (child->style().flexStartMarginIsAuto(mainAxis, direction)) { - numberOfAutoMarginsOnCurrentLine++; - } - if (child->style().flexEndMarginIsAuto(mainAxis, direction)) { - numberOfAutoMarginsOnCurrentLine++; - } - } - } - - // In order to position the elements in the main axis, we have two controls. - // The space between the beginning and the first element and the space between - // each two elements. - float leadingMainDim = 0; - float betweenMainDim = gap; - const Justify justifyContent = node->style().justifyContent(); - - if (numberOfAutoMarginsOnCurrentLine == 0) { - switch (justifyContent) { - case Justify::Center: - leadingMainDim = flexLine.layout.remainingFreeSpace / 2; - break; - case Justify::FlexEnd: - leadingMainDim = flexLine.layout.remainingFreeSpace; - break; - case Justify::SpaceBetween: - if (flexLine.itemsInFlow.size() > 1) { - betweenMainDim += - yoga::maxOrDefined(flexLine.layout.remainingFreeSpace, 0.0f) / - static_cast(flexLine.itemsInFlow.size() - 1); - } - break; - case Justify::SpaceEvenly: - // Space is distributed evenly across all elements - leadingMainDim = flexLine.layout.remainingFreeSpace / - static_cast(flexLine.itemsInFlow.size() + 1); - betweenMainDim += leadingMainDim; - break; - case Justify::SpaceAround: - // Space on the edges is half of the space between elements - leadingMainDim = 0.5f * flexLine.layout.remainingFreeSpace / - static_cast(flexLine.itemsInFlow.size()); - betweenMainDim += leadingMainDim * 2; - break; - case Justify::FlexStart: - break; - } - } - - flexLine.layout.mainDim = leadingPaddingAndBorderMain + leadingMainDim; - flexLine.layout.crossDim = 0; - - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; - bool isNodeBaselineLayout = isBaselineLayout(node); - for (size_t i = startOfLineIndex; i < flexLine.endOfLineIndex; i++) { - const auto child = node->getChild(i); - const Style& childStyle = child->style(); - const LayoutResults& childLayout = child->getLayout(); - if (childStyle.display() == Display::None) { - continue; - } - if (childStyle.positionType() == PositionType::Absolute && - child->style().isFlexStartPositionDefined(mainAxis, direction)) { - if (performLayout) { - // In case the child is position absolute and has left/top being - // defined, we override the position to whatever the user said (and - // margin/border). - child->setLayoutPosition( - child->style().computeFlexStartPosition( - mainAxis, direction, availableInnerMainDim) + - node->style().computeFlexStartBorder(mainAxis, direction) + - child->style().computeFlexStartMargin( - mainAxis, direction, availableInnerWidth), - flexStartEdge(mainAxis)); - } - } else { - // Now that we placed the element, we need to update the variables. - // We need to do that only for relative elements. Absolute elements do not - // take part in that phase. - if (childStyle.positionType() != PositionType::Absolute) { - if (child->style().flexStartMarginIsAuto(mainAxis, direction)) { - flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace / - static_cast(numberOfAutoMarginsOnCurrentLine); - } - - if (performLayout) { - child->setLayoutPosition( - childLayout.position(flexStartEdge(mainAxis)) + - flexLine.layout.mainDim, - flexStartEdge(mainAxis)); - } - - if (child != flexLine.itemsInFlow.back()) { - flexLine.layout.mainDim += betweenMainDim; - } - - if (child->style().flexEndMarginIsAuto(mainAxis, direction)) { - flexLine.layout.mainDim += flexLine.layout.remainingFreeSpace / - static_cast(numberOfAutoMarginsOnCurrentLine); - } - bool canSkipFlex = - !performLayout && sizingModeCrossDim == SizingMode::StretchFit; - if (canSkipFlex) { - // If we skipped the flex step, then we can't rely on the measuredDims - // because they weren't computed. This means we can't call - // dimensionWithMargin. - flexLine.layout.mainDim += child->style().computeMarginForAxis( - mainAxis, availableInnerWidth) + - childLayout.computedFlexBasis.unwrap(); - flexLine.layout.crossDim = availableInnerCrossDim; - } else { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - flexLine.layout.mainDim += - child->dimensionWithMargin(mainAxis, availableInnerWidth); - - if (isNodeBaselineLayout) { - // If the child is baseline aligned then the cross dimension is - // calculated by adding maxAscent and maxDescent from the baseline. - const float ascent = calculateBaseline(child) + - child->style().computeFlexStartMargin( - FlexDirection::Column, direction, availableInnerWidth); - const float descent = - child->getLayout().measuredDimension(Dimension::Height) + - child->style().computeMarginForAxis( - FlexDirection::Column, availableInnerWidth) - - ascent; - - maxAscentForCurrentLine = - yoga::maxOrDefined(maxAscentForCurrentLine, ascent); - maxDescentForCurrentLine = - yoga::maxOrDefined(maxDescentForCurrentLine, descent); - } else { - // The cross dimension is the max of the elements dimension since - // there can only be one element in that cross dimension in the case - // when the items are not baseline aligned - flexLine.layout.crossDim = yoga::maxOrDefined( - flexLine.layout.crossDim, - child->dimensionWithMargin(crossAxis, availableInnerWidth)); - } - } - } else if (performLayout) { - child->setLayoutPosition( - childLayout.position(flexStartEdge(mainAxis)) + - node->style().computeFlexStartBorder(mainAxis, direction) + - leadingMainDim, - flexStartEdge(mainAxis)); - } - } - } - flexLine.layout.mainDim += trailingPaddingAndBorderMain; - - if (isNodeBaselineLayout) { - flexLine.layout.crossDim = - maxAscentForCurrentLine + maxDescentForCurrentLine; - } -} - -// -// This is the main routine that implements a subset of the flexbox layout -// algorithm described in the W3C CSS documentation: -// https://www.w3.org/TR/CSS3-flexbox/. -// -// Limitations of this algorithm, compared to the full standard: -// * Display property is always assumed to be 'flex' except for Text nodes, -// which are assumed to be 'inline-flex'. -// * The 'zIndex' property (or any form of z ordering) is not supported. Nodes -// are stacked in document order. -// * The 'order' property is not supported. The order of flex items is always -// defined by document order. -// * The 'visibility' property is always assumed to be 'visible'. Values of -// 'collapse' and 'hidden' are not supported. -// * There is no support for forced breaks. -// * It does not support vertical inline directions (top-to-bottom or -// bottom-to-top text). -// -// Deviations from standard: -// * Section 4.5 of the spec indicates that all flex items have a default -// minimum main size. For text blocks, for example, this is the width of the -// widest word. Calculating the minimum width is expensive, so we forego it -// and assume a default minimum main size of 0. -// * Min/Max sizes in the main axis are not honored when resolving flexible -// lengths. -// * The spec indicates that the default value for 'flexDirection' is 'row', -// but the algorithm below assumes a default of 'column'. -// -// Input parameters: -// - node: current node to be sized and laid out -// - availableWidth & availableHeight: available size to be used for sizing -// the node or YGUndefined if the size is not available; interpretation -// depends on layout flags -// - ownerDirection: the inline (text) direction within the owner -// (left-to-right or right-to-left) -// - widthSizingMode: indicates the sizing rules for the width (see below -// for explanation) -// - heightSizingMode: indicates the sizing rules for the height (see below -// for explanation) -// - performLayout: specifies whether the caller is interested in just the -// dimensions of the node or it requires the entire node and its subtree to -// be laid out (with final positions) -// -// Details: -// This routine is called recursively to lay out subtrees of flexbox -// elements. It uses the information in node.style, which is treated as a -// read-only input. It is responsible for setting the layout.direction and -// layout.measuredDimensions fields for the input node as well as the -// layout.position and layout.lineIndex fields for its child nodes. The -// layout.measuredDimensions field includes any border or padding for the -// node but does not include margins. -// -// When calling calculateLayoutImpl and calculateLayoutInternal, if the -// caller passes an available size of undefined then it must also pass a -// measure mode of SizingMode::MaxContent in that dimension. -// -static void calculateLayoutImpl( - yoga::Node* const node, - const float availableWidth, - const float availableHeight, - const Direction ownerDirection, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount, - const LayoutPassReason reason) { - yoga::assertFatalWithNode( - node, - yoga::isUndefined(availableWidth) - ? widthSizingMode == SizingMode::MaxContent - : true, - "availableWidth is indefinite so widthSizingMode must be " - "SizingMode::MaxContent"); - yoga::assertFatalWithNode( - node, - yoga::isUndefined(availableHeight) - ? heightSizingMode == SizingMode::MaxContent - : true, - "availableHeight is indefinite so heightSizingMode must be " - "SizingMode::MaxContent"); - - (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; - - // Set the resolved resolution in the node's layout. - const Direction direction = node->resolveDirection(ownerDirection); - node->setLayoutDirection(direction); - - const FlexDirection flexRowDirection = - resolveDirection(FlexDirection::Row, direction); - const FlexDirection flexColumnDirection = - resolveDirection(FlexDirection::Column, direction); - - const auto startEdge = - direction == Direction::LTR ? PhysicalEdge::Left : PhysicalEdge::Right; - const auto endEdge = - direction == Direction::LTR ? PhysicalEdge::Right : PhysicalEdge::Left; - - const float marginRowLeading = node->style().computeInlineStartMargin( - flexRowDirection, direction, ownerWidth); - node->setLayoutMargin(marginRowLeading, startEdge); - const float marginRowTrailing = node->style().computeInlineEndMargin( - flexRowDirection, direction, ownerWidth); - node->setLayoutMargin(marginRowTrailing, endEdge); - const float marginColumnLeading = node->style().computeInlineStartMargin( - flexColumnDirection, direction, ownerWidth); - node->setLayoutMargin(marginColumnLeading, PhysicalEdge::Top); - const float marginColumnTrailing = node->style().computeInlineEndMargin( - flexColumnDirection, direction, ownerWidth); - node->setLayoutMargin(marginColumnTrailing, PhysicalEdge::Bottom); - - const float marginAxisRow = marginRowLeading + marginRowTrailing; - const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; - - node->setLayoutBorder( - node->style().computeInlineStartBorder(flexRowDirection, direction), - startEdge); - node->setLayoutBorder( - node->style().computeInlineEndBorder(flexRowDirection, direction), - endEdge); - node->setLayoutBorder( - node->style().computeInlineStartBorder(flexColumnDirection, direction), - PhysicalEdge::Top); - node->setLayoutBorder( - node->style().computeInlineEndBorder(flexColumnDirection, direction), - PhysicalEdge::Bottom); - - node->setLayoutPadding( - node->style().computeInlineStartPadding( - flexRowDirection, direction, ownerWidth), - startEdge); - node->setLayoutPadding( - node->style().computeInlineEndPadding( - flexRowDirection, direction, ownerWidth), - endEdge); - node->setLayoutPadding( - node->style().computeInlineStartPadding( - flexColumnDirection, direction, ownerWidth), - PhysicalEdge::Top); - node->setLayoutPadding( - node->style().computeInlineEndPadding( - flexColumnDirection, direction, ownerWidth), - PhysicalEdge::Bottom); - - if (node->hasMeasureFunc()) { - measureNodeWithMeasureFunc( - node, - availableWidth - marginAxisRow, - availableHeight - marginAxisColumn, - widthSizingMode, - heightSizingMode, - ownerWidth, - ownerHeight, - layoutMarkerData, - reason); - return; - } - - const auto childCount = node->getChildCount(); - if (childCount == 0) { - measureNodeWithoutChildren( - node, - availableWidth - marginAxisRow, - availableHeight - marginAxisColumn, - widthSizingMode, - heightSizingMode, - ownerWidth, - ownerHeight); - return; - } - - // If we're not being asked to perform a full layout we can skip the algorithm - // if we already know the size - if (!performLayout && - measureNodeWithFixedSize( - node, - availableWidth - marginAxisRow, - availableHeight - marginAxisColumn, - widthSizingMode, - heightSizingMode, - ownerWidth, - ownerHeight)) { - return; - } - - // At this point we know we're going to perform work. Ensure that each child - // has a mutable copy. - node->cloneChildrenIfNeeded(); - // Reset layout flags, as they could have changed. - node->setLayoutHadOverflow(false); - - // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const FlexDirection mainAxis = - resolveDirection(node->style().flexDirection(), direction); - const FlexDirection crossAxis = resolveCrossDirection(mainAxis, direction); - const bool isMainAxisRow = isRow(mainAxis); - const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap; - - const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; - const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - - const float paddingAndBorderAxisMain = - paddingAndBorderForAxis(node, mainAxis, ownerWidth); - const float paddingAndBorderAxisCross = - paddingAndBorderForAxis(node, crossAxis, ownerWidth); - const float leadingPaddingAndBorderCross = - node->style().computeFlexStartPaddingAndBorder( - crossAxis, direction, ownerWidth); - - SizingMode sizingModeMainDim = - isMainAxisRow ? widthSizingMode : heightSizingMode; - SizingMode sizingModeCrossDim = - isMainAxisRow ? heightSizingMode : widthSizingMode; - - const float paddingAndBorderAxisRow = - isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross; - const float paddingAndBorderAxisColumn = - isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS - - float availableInnerWidth = calculateAvailableInnerDimension( - node, - Dimension::Width, - availableWidth - marginAxisRow, - paddingAndBorderAxisRow, - ownerWidth); - float availableInnerHeight = calculateAvailableInnerDimension( - node, - Dimension::Height, - availableHeight - marginAxisColumn, - paddingAndBorderAxisColumn, - ownerHeight); - - float availableInnerMainDim = - isMainAxisRow ? availableInnerWidth : availableInnerHeight; - const float availableInnerCrossDim = - isMainAxisRow ? availableInnerHeight : availableInnerWidth; - - // STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM - - // Computed basis + margins + gap - float totalMainDim = 0; - totalMainDim += computeFlexBasisForChildren( - node, - availableInnerWidth, - availableInnerHeight, - widthSizingMode, - heightSizingMode, - direction, - mainAxis, - performLayout, - layoutMarkerData, - depth, - generationCount); - - if (childCount > 1) { - totalMainDim += node->style().computeGapForAxis(mainAxis) * - static_cast(childCount - 1); - } - - const bool mainAxisOverflows = - (sizingModeMainDim != SizingMode::MaxContent) && - totalMainDim > availableInnerMainDim; - - if (isNodeFlexWrap && mainAxisOverflows && - sizingModeMainDim == SizingMode::FitContent) { - sizingModeMainDim = SizingMode::StretchFit; - } - // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES - - // Indexes of children that represent the first and last items in the line. - size_t startOfLineIndex = 0; - size_t endOfLineIndex = 0; - - // Number of lines. - size_t lineCount = 0; - - // Accumulated cross dimensions of all lines so far. - float totalLineCrossDim = 0; - - const float crossAxisGap = node->style().computeGapForAxis(crossAxis); - - // Max main dimension of all the lines. - float maxLineMainDim = 0; - for (; endOfLineIndex < childCount; - lineCount++, startOfLineIndex = endOfLineIndex) { - auto flexLine = calculateFlexLine( - node, - ownerDirection, - mainAxisownerSize, - availableInnerWidth, - availableInnerMainDim, - startOfLineIndex, - lineCount); - - endOfLineIndex = flexLine.endOfLineIndex; - - // If we don't need to measure the cross axis, we can skip the entire flex - // step. - const bool canSkipFlex = - !performLayout && sizingModeCrossDim == SizingMode::StretchFit; - - // STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS - // Calculate the remaining available space that needs to be allocated. If - // the main dimension size isn't known, it is computed based on the line - // length, so there's no more space left to distribute. - - bool sizeBasedOnContent = false; - // If we don't measure with exact main dimension we want to ensure we don't - // violate min and max - if (sizingModeMainDim != SizingMode::StretchFit) { - const auto& style = node->style(); - const float minInnerWidth = - style.minDimension(Dimension::Width).resolve(ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float maxInnerWidth = - style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float minInnerHeight = - style.minDimension(Dimension::Height).resolve(ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - const float maxInnerHeight = - style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - - const float minInnerMainDim = - isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = - isMainAxisRow ? maxInnerWidth : maxInnerHeight; - - if (yoga::isDefined(minInnerMainDim) && - flexLine.sizeConsumed < minInnerMainDim) { - availableInnerMainDim = minInnerMainDim; - } else if ( - yoga::isDefined(maxInnerMainDim) && - flexLine.sizeConsumed > maxInnerMainDim) { - availableInnerMainDim = maxInnerMainDim; - } else { - bool useLegacyStretchBehaviour = - node->hasErrata(Errata::StretchFlexBasis); - - if (!useLegacyStretchBehaviour && - ((yoga::isDefined(flexLine.layout.totalFlexGrowFactors) && - flexLine.layout.totalFlexGrowFactors == 0) || - (yoga::isDefined(node->resolveFlexGrow()) && - node->resolveFlexGrow() == 0))) { - // If we don't have any children to flex or we can't flex the node - // itself, space we've used is all space we need. Root node also - // should be shrunk to minimum - availableInnerMainDim = flexLine.sizeConsumed; - } - - sizeBasedOnContent = !useLegacyStretchBehaviour; - } - } - - if (!sizeBasedOnContent && yoga::isDefined(availableInnerMainDim)) { - flexLine.layout.remainingFreeSpace = - availableInnerMainDim - flexLine.sizeConsumed; - } else if (flexLine.sizeConsumed < 0) { - // availableInnerMainDim is indefinite which means the node is being sized - // based on its content. sizeConsumed is negative which means - // the node will allocate 0 points for its content. Consequently, - // remainingFreeSpace is 0 - sizeConsumed. - flexLine.layout.remainingFreeSpace = -flexLine.sizeConsumed; - } - - if (!canSkipFlex) { - resolveFlexibleLength( - node, - flexLine, - mainAxis, - crossAxis, - direction, - mainAxisownerSize, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - availableInnerHeight, - mainAxisOverflows, - sizingModeCrossDim, - performLayout, - layoutMarkerData, - depth, - generationCount); - } - - node->setLayoutHadOverflow( - node->getLayout().hadOverflow() || - (flexLine.layout.remainingFreeSpace < 0)); - - // STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION - - // At this point, all the children have their dimensions set in the main - // axis. Their dimensions are also set in the cross axis with the exception - // of items that are aligned "stretch". We need to compute these stretch - // values and set the final positions. - - justifyMainAxis( - node, - flexLine, - startOfLineIndex, - mainAxis, - crossAxis, - direction, - sizingModeMainDim, - sizingModeCrossDim, - mainAxisownerSize, - ownerWidth, - availableInnerMainDim, - availableInnerCrossDim, - availableInnerWidth, - performLayout); - - float containerCrossAxis = availableInnerCrossDim; - if (sizingModeCrossDim == SizingMode::MaxContent || - sizingModeCrossDim == SizingMode::FitContent) { - // Compute the cross axis from the max cross dimension of the children. - containerCrossAxis = - boundAxis( - node, - crossAxis, - flexLine.layout.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - - paddingAndBorderAxisCross; - } - - // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && sizingModeCrossDim == SizingMode::StretchFit) { - flexLine.layout.crossDim = availableInnerCrossDim; - } - - // As-per https://www.w3.org/TR/css-flexbox-1/#cross-sizing, the - // cross-size of the line within a single-line container should be bound to - // min/max constraints before alignment within the line. In a multi-line - // container, affecting alignment between the lines. - if (!isNodeFlexWrap) { - flexLine.layout.crossDim = - boundAxis( - node, - crossAxis, - flexLine.layout.crossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth) - - paddingAndBorderAxisCross; - } - - // STEP 7: CROSS-AXIS ALIGNMENT - // We can skip child alignment if we're just measuring the container. - if (performLayout) { - for (size_t i = startOfLineIndex; i < endOfLineIndex; i++) { - const auto child = node->getChild(i); - if (child->style().display() == Display::None) { - continue; - } - if (child->style().positionType() == PositionType::Absolute) { - // If the child is absolutely positioned and has a - // top/left/bottom/right set, override all the previously computed - // positions to set it correctly. - const bool isChildLeadingPosDefined = - child->style().isFlexStartPositionDefined(crossAxis, direction); - if (isChildLeadingPosDefined) { - child->setLayoutPosition( - child->style().computeFlexStartPosition( - crossAxis, direction, availableInnerCrossDim) + - node->style().computeFlexStartBorder(crossAxis, direction) + - child->style().computeFlexStartMargin( - crossAxis, direction, availableInnerWidth), - flexStartEdge(crossAxis)); - } - // If leading position is not defined or calculations result in Nan, - // default to border + margin - if (!isChildLeadingPosDefined || - yoga::isUndefined( - child->getLayout().position(flexStartEdge(crossAxis)))) { - child->setLayoutPosition( - node->style().computeFlexStartBorder(crossAxis, direction) + - child->style().computeFlexStartMargin( - crossAxis, direction, availableInnerWidth), - flexStartEdge(crossAxis)); - } - } else { - float leadingCrossDim = leadingPaddingAndBorderCross; - - // For a relative children, we're either using alignItems (owner) or - // alignSelf (child) in order to determine the position in the cross - // axis - const Align alignItem = resolveChildAlignment(node, child); - - // If the child uses align stretch, we need to lay it out one more - // time, this time forcing the cross-axis size to be the computed - // cross size for the current line. - if (alignItem == Align::Stretch && - !child->style().flexStartMarginIsAuto(crossAxis, direction) && - !child->style().flexEndMarginIsAuto(crossAxis, direction)) { - // If the child defines a definite size for its cross axis, there's - // no need to stretch. - if (!child->hasDefiniteLength( - dimension(crossAxis), availableInnerCrossDim)) { - float childMainSize = - child->getLayout().measuredDimension(dimension(mainAxis)); - const auto& childStyle = child->style(); - float childCrossSize = childStyle.aspectRatio().isDefined() - ? child->style().computeMarginForAxis( - crossAxis, availableInnerWidth) + - (isMainAxisRow - ? childMainSize / childStyle.aspectRatio().unwrap() - : childMainSize * childStyle.aspectRatio().unwrap()) - : flexLine.layout.crossDim; - - childMainSize += child->style().computeMarginForAxis( - mainAxis, availableInnerWidth); - - SizingMode childMainSizingMode = SizingMode::StretchFit; - SizingMode childCrossSizingMode = SizingMode::StretchFit; - constrainMaxSizeForMode( - child, - mainAxis, - availableInnerMainDim, - availableInnerWidth, - &childMainSizingMode, - &childMainSize); - constrainMaxSizeForMode( - child, - crossAxis, - availableInnerCrossDim, - availableInnerWidth, - &childCrossSizingMode, - &childCrossSize); - - const float childWidth = - isMainAxisRow ? childMainSize : childCrossSize; - const float childHeight = - !isMainAxisRow ? childMainSize : childCrossSize; - - auto alignContent = node->style().alignContent(); - auto crossAxisDoesNotGrow = - alignContent != Align::Stretch && isNodeFlexWrap; - const SizingMode childWidthSizingMode = - yoga::isUndefined(childWidth) || - (!isMainAxisRow && crossAxisDoesNotGrow) - ? SizingMode::MaxContent - : SizingMode::StretchFit; - const SizingMode childHeightSizingMode = - yoga::isUndefined(childHeight) || - (isMainAxisRow && crossAxisDoesNotGrow) - ? SizingMode::MaxContent - : SizingMode::StretchFit; - - calculateLayoutInternal( - child, - childWidth, - childHeight, - direction, - childWidthSizingMode, - childHeightSizingMode, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kStretch, - layoutMarkerData, - depth, - generationCount); - } - } else { - const float remainingCrossDim = containerCrossAxis - - child->dimensionWithMargin(crossAxis, availableInnerWidth); - - if (child->style().flexStartMarginIsAuto(crossAxis, direction) && - child->style().flexEndMarginIsAuto(crossAxis, direction)) { - leadingCrossDim += - yoga::maxOrDefined(0.0f, remainingCrossDim / 2); - } else if (child->style().flexEndMarginIsAuto( - crossAxis, direction)) { - // No-Op - } else if (child->style().flexStartMarginIsAuto( - crossAxis, direction)) { - leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim); - } else if (alignItem == Align::FlexStart) { - // No-Op - } else if (alignItem == Align::Center) { - leadingCrossDim += remainingCrossDim / 2; - } else { - leadingCrossDim += remainingCrossDim; - } - } - // And we apply the position - child->setLayoutPosition( - child->getLayout().position(flexStartEdge(crossAxis)) + - totalLineCrossDim + leadingCrossDim, - flexStartEdge(crossAxis)); - } - } - } - - const float appliedCrossGap = lineCount != 0 ? crossAxisGap : 0.0f; - totalLineCrossDim += flexLine.layout.crossDim + appliedCrossGap; - maxLineMainDim = - yoga::maxOrDefined(maxLineMainDim, flexLine.layout.mainDim); - } - - // STEP 8: MULTI-LINE CONTENT ALIGNMENT - // currentLead stores the size of the cross dim - if (performLayout && (isNodeFlexWrap || isBaselineLayout(node))) { - float leadPerLine = 0; - float currentLead = leadingPaddingAndBorderCross; - - const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit - ? availableInnerCrossDim + paddingAndBorderAxisCross - : node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize) - ? node->getResolvedDimension(dimension(crossAxis)) - .resolve(crossAxisownerSize) - .unwrap() - : totalLineCrossDim + paddingAndBorderAxisCross; - - const float innerCrossDim = - boundAxis(node, crossAxis, unclampedCrossDim, ownerHeight, ownerWidth) - - paddingAndBorderAxisCross; - - const float remainingAlignContentDim = innerCrossDim - totalLineCrossDim; - switch (node->style().alignContent()) { - case Align::FlexEnd: - currentLead += remainingAlignContentDim; - break; - case Align::Center: - currentLead += remainingAlignContentDim / 2; - break; - case Align::Stretch: - if (innerCrossDim > totalLineCrossDim) { - leadPerLine = - remainingAlignContentDim / static_cast(lineCount); - } - break; - case Align::SpaceAround: - if (innerCrossDim > totalLineCrossDim) { - currentLead += - remainingAlignContentDim / (2 * static_cast(lineCount)); - leadPerLine = - remainingAlignContentDim / static_cast(lineCount); - } else { - currentLead += remainingAlignContentDim / 2; - } - break; - case Align::SpaceEvenly: - if (innerCrossDim > totalLineCrossDim) { - currentLead += - remainingAlignContentDim / static_cast(lineCount + 1); - leadPerLine = - remainingAlignContentDim / static_cast(lineCount + 1); - } else { - currentLead += remainingAlignContentDim / 2; - } - break; - case Align::SpaceBetween: - if (innerCrossDim > totalLineCrossDim && lineCount > 1) { - leadPerLine = - remainingAlignContentDim / static_cast(lineCount - 1); - } - break; - case Align::Auto: - case Align::FlexStart: - case Align::Baseline: - break; - } - size_t endIndex = 0; - for (size_t i = 0; i < lineCount; i++) { - const size_t startIndex = endIndex; - size_t ii; - - // compute the line's height and find the endIndex - float lineHeight = 0; - float maxAscentForCurrentLine = 0; - float maxDescentForCurrentLine = 0; - for (ii = startIndex; ii < childCount; ii++) { - const auto child = node->getChild(ii); - if (child->style().display() == Display::None) { - continue; - } - if (child->style().positionType() != PositionType::Absolute) { - if (child->getLineIndex() != i) { - break; - } - if (child->isLayoutDimensionDefined(crossAxis)) { - lineHeight = yoga::maxOrDefined( - lineHeight, - child->getLayout().measuredDimension(dimension(crossAxis)) + - child->style().computeMarginForAxis( - crossAxis, availableInnerWidth)); - } - if (resolveChildAlignment(node, child) == Align::Baseline) { - const float ascent = calculateBaseline(child) + - child->style().computeFlexStartMargin( - FlexDirection::Column, direction, availableInnerWidth); - const float descent = - child->getLayout().measuredDimension(Dimension::Height) + - child->style().computeMarginForAxis( - FlexDirection::Column, availableInnerWidth) - - ascent; - maxAscentForCurrentLine = - yoga::maxOrDefined(maxAscentForCurrentLine, ascent); - maxDescentForCurrentLine = - yoga::maxOrDefined(maxDescentForCurrentLine, descent); - lineHeight = yoga::maxOrDefined( - lineHeight, maxAscentForCurrentLine + maxDescentForCurrentLine); - } - } - } - endIndex = ii; - currentLead += i != 0 ? crossAxisGap : 0; - - if (performLayout) { - for (ii = startIndex; ii < endIndex; ii++) { - const auto child = node->getChild(ii); - if (child->style().display() == Display::None) { - continue; - } - if (child->style().positionType() != PositionType::Absolute) { - switch (resolveChildAlignment(node, child)) { - case Align::FlexStart: { - child->setLayoutPosition( - currentLead + - child->style().computeFlexStartPosition( - crossAxis, direction, availableInnerWidth), - flexStartEdge(crossAxis)); - break; - } - case Align::FlexEnd: { - child->setLayoutPosition( - currentLead + lineHeight - - child->style().computeFlexEndMargin( - crossAxis, direction, availableInnerWidth) - - child->getLayout().measuredDimension( - dimension(crossAxis)), - flexStartEdge(crossAxis)); - break; - } - case Align::Center: { - float childHeight = - child->getLayout().measuredDimension(dimension(crossAxis)); - - child->setLayoutPosition( - currentLead + (lineHeight - childHeight) / 2, - flexStartEdge(crossAxis)); - break; - } - case Align::Stretch: { - child->setLayoutPosition( - currentLead + - child->style().computeFlexStartMargin( - crossAxis, direction, availableInnerWidth), - flexStartEdge(crossAxis)); - - // Remeasure child with the line height as it as been only - // measured with the owners height yet. - if (!child->hasDefiniteLength( - dimension(crossAxis), availableInnerCrossDim)) { - const float childWidth = isMainAxisRow - ? (child->getLayout().measuredDimension( - Dimension::Width) + - child->style().computeMarginForAxis( - mainAxis, availableInnerWidth)) - : leadPerLine + lineHeight; - - const float childHeight = !isMainAxisRow - ? (child->getLayout().measuredDimension( - Dimension::Height) + - child->style().computeMarginForAxis( - crossAxis, availableInnerWidth)) - : leadPerLine + lineHeight; - - if (!(yoga::inexactEquals( - childWidth, - child->getLayout().measuredDimension( - Dimension::Width)) && - yoga::inexactEquals( - childHeight, - child->getLayout().measuredDimension( - Dimension::Height)))) { - calculateLayoutInternal( - child, - childWidth, - childHeight, - direction, - SizingMode::StretchFit, - SizingMode::StretchFit, - availableInnerWidth, - availableInnerHeight, - true, - LayoutPassReason::kMultilineStretch, - layoutMarkerData, - depth, - generationCount); - } - } - break; - } - case Align::Baseline: { - child->setLayoutPosition( - currentLead + maxAscentForCurrentLine - - calculateBaseline(child) + - child->style().computeFlexStartPosition( - FlexDirection::Column, - direction, - availableInnerCrossDim), - PhysicalEdge::Top); - - break; - } - case Align::Auto: - case Align::SpaceBetween: - case Align::SpaceAround: - case Align::SpaceEvenly: - break; - } - } - } - } - currentLead = currentLead + leadPerLine + lineHeight; - } - } - - // STEP 9: COMPUTING FINAL DIMENSIONS - - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Row, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), - Dimension::Width); - - node->setLayoutMeasuredDimension( - boundAxis( - node, - FlexDirection::Column, - availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), - Dimension::Height); - - // If the user didn't specify a width or height for the node, set the - // dimensions based on the children. - if (sizingModeMainDim == SizingMode::MaxContent || - (node->style().overflow() != Overflow::Scroll && - sizingModeMainDim == SizingMode::FitContent)) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->setLayoutMeasuredDimension( - boundAxis( - node, mainAxis, maxLineMainDim, mainAxisownerSize, ownerWidth), - dimension(mainAxis)); - - } else if ( - sizingModeMainDim == SizingMode::FitContent && - node->style().overflow() == Overflow::Scroll) { - node->setLayoutMeasuredDimension( - yoga::maxOrDefined( - yoga::minOrDefined( - availableInnerMainDim + paddingAndBorderAxisMain, - boundAxisWithinMinAndMax( - node, - mainAxis, - FloatOptional{maxLineMainDim}, - mainAxisownerSize) - .unwrap()), - paddingAndBorderAxisMain), - dimension(mainAxis)); - } - - if (sizingModeCrossDim == SizingMode::MaxContent || - (node->style().overflow() != Overflow::Scroll && - sizingModeCrossDim == SizingMode::FitContent)) { - // Clamp the size to the min/max size, if specified, and make sure it - // doesn't go below the padding and border amount. - node->setLayoutMeasuredDimension( - boundAxis( - node, - crossAxis, - totalLineCrossDim + paddingAndBorderAxisCross, - crossAxisownerSize, - ownerWidth), - dimension(crossAxis)); - - } else if ( - sizingModeCrossDim == SizingMode::FitContent && - node->style().overflow() == Overflow::Scroll) { - node->setLayoutMeasuredDimension( - yoga::maxOrDefined( - yoga::minOrDefined( - availableInnerCrossDim + paddingAndBorderAxisCross, - boundAxisWithinMinAndMax( - node, - crossAxis, - FloatOptional{ - totalLineCrossDim + paddingAndBorderAxisCross}, - crossAxisownerSize) - .unwrap()), - paddingAndBorderAxisCross), - dimension(crossAxis)); - } - - // As we only wrapped in normal direction yet, we need to reverse the - // positions on wrap-reverse. - if (performLayout && node->style().flexWrap() == Wrap::WrapReverse) { - for (size_t i = 0; i < childCount; i++) { - const auto child = node->getChild(i); - if (child->style().positionType() != PositionType::Absolute) { - child->setLayoutPosition( - node->getLayout().measuredDimension(dimension(crossAxis)) - - child->getLayout().position(flexStartEdge(crossAxis)) - - child->getLayout().measuredDimension(dimension(crossAxis)), - flexStartEdge(crossAxis)); - } - } - } - - if (performLayout) { - // STEP 10: SETTING TRAILING POSITIONS FOR CHILDREN - const bool needsMainTrailingPos = needsTrailingPosition(mainAxis); - const bool needsCrossTrailingPos = needsTrailingPosition(crossAxis); - - if (needsMainTrailingPos || needsCrossTrailingPos) { - for (size_t i = 0; i < childCount; i++) { - const auto child = node->getChild(i); - // Absolute children will be handled by their containing block since we - // cannot guarantee that their positions are set when their parents are - // done with layout. - if (child->style().display() == Display::None || - child->style().positionType() == PositionType::Absolute) { - continue; - } - if (needsMainTrailingPos) { - setChildTrailingPosition(node, child, mainAxis); - } - - if (needsCrossTrailingPos) { - setChildTrailingPosition(node, child, crossAxis); - } - } - } - - // STEP 11: SIZING AND POSITIONING ABSOLUTE CHILDREN - // Let the containing block layout its absolute descendants. - if (node->style().positionType() != PositionType::Static || - node->alwaysFormsContainingBlock() || depth == 1) { - layoutAbsoluteDescendants( - node, - node, - isMainAxisRow ? sizingModeMainDim : sizingModeCrossDim, - direction, - layoutMarkerData, - depth, - generationCount, - 0.0f, - 0.0f, - availableInnerWidth, - availableInnerHeight); - } - } -} - -// -// This is a wrapper around the calculateLayoutImpl function. It determines -// whether the layout request is redundant and can be skipped. -// -// Parameters: -// Input parameters are the same as calculateLayoutImpl (see above) -// Return parameter is true if layout was performed, false if skipped -// -bool calculateLayoutInternal( - yoga::Node* const node, - const float availableWidth, - const float availableHeight, - const Direction ownerDirection, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - LayoutData& layoutMarkerData, - uint32_t depth, - const uint32_t generationCount) { - LayoutResults* layout = &node->getLayout(); - - depth++; - - const bool needToVisitNode = - (node->isDirty() && layout->generationCount != generationCount) || - layout->lastOwnerDirection != ownerDirection; - - if (needToVisitNode) { - // Invalidate the cached results. - layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.availableWidth = -1; - layout->cachedLayout.availableHeight = -1; - layout->cachedLayout.widthSizingMode = SizingMode::MaxContent; - layout->cachedLayout.heightSizingMode = SizingMode::MaxContent; - layout->cachedLayout.computedWidth = -1; - layout->cachedLayout.computedHeight = -1; - } - - CachedMeasurement* cachedResults = nullptr; - - // Determine whether the results are already cached. We maintain a separate - // cache for layouts and measurements. A layout operation modifies the - // positions and dimensions for nodes in the subtree. The algorithm assumes - // that each node gets laid out a maximum of one time per tree layout, but - // multiple measurements may be required to resolve all of the flex - // dimensions. We handle nodes with measure functions specially here because - // they are the most expensive to measure, so it's worth avoiding redundant - // measurements if at all possible. - if (node->hasMeasureFunc()) { - const float marginAxisRow = - node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth); - const float marginAxisColumn = - node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth); - - // First, try to use the layout cache. - if (canUseCachedMeasurement( - widthSizingMode, - availableWidth, - heightSizingMode, - availableHeight, - layout->cachedLayout.widthSizingMode, - layout->cachedLayout.availableWidth, - layout->cachedLayout.heightSizingMode, - layout->cachedLayout.availableHeight, - layout->cachedLayout.computedWidth, - layout->cachedLayout.computedHeight, - marginAxisRow, - marginAxisColumn, - node->getConfig())) { - cachedResults = &layout->cachedLayout; - } else { - // Try to use the measurement cache. - for (size_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { - if (canUseCachedMeasurement( - widthSizingMode, - availableWidth, - heightSizingMode, - availableHeight, - layout->cachedMeasurements[i].widthSizingMode, - layout->cachedMeasurements[i].availableWidth, - layout->cachedMeasurements[i].heightSizingMode, - layout->cachedMeasurements[i].availableHeight, - layout->cachedMeasurements[i].computedWidth, - layout->cachedMeasurements[i].computedHeight, - marginAxisRow, - marginAxisColumn, - node->getConfig())) { - cachedResults = &layout->cachedMeasurements[i]; - break; - } - } - } - } else if (performLayout) { - if (yoga::inexactEquals( - layout->cachedLayout.availableWidth, availableWidth) && - yoga::inexactEquals( - layout->cachedLayout.availableHeight, availableHeight) && - layout->cachedLayout.widthSizingMode == widthSizingMode && - layout->cachedLayout.heightSizingMode == heightSizingMode) { - cachedResults = &layout->cachedLayout; - } - } else { - for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { - if (yoga::inexactEquals( - layout->cachedMeasurements[i].availableWidth, availableWidth) && - yoga::inexactEquals( - layout->cachedMeasurements[i].availableHeight, availableHeight) && - layout->cachedMeasurements[i].widthSizingMode == widthSizingMode && - layout->cachedMeasurements[i].heightSizingMode == heightSizingMode) { - cachedResults = &layout->cachedMeasurements[i]; - break; - } - } - } - - if (!needToVisitNode && cachedResults != nullptr) { - layout->setMeasuredDimension( - Dimension::Width, cachedResults->computedWidth); - layout->setMeasuredDimension( - Dimension::Height, cachedResults->computedHeight); - - (performLayout ? layoutMarkerData.cachedLayouts - : layoutMarkerData.cachedMeasures) += 1; - } else { - calculateLayoutImpl( - node, - availableWidth, - availableHeight, - ownerDirection, - widthSizingMode, - heightSizingMode, - ownerWidth, - ownerHeight, - performLayout, - layoutMarkerData, - depth, - generationCount, - reason); - - layout->lastOwnerDirection = ownerDirection; - - if (cachedResults == nullptr) { - layoutMarkerData.maxMeasureCache = std::max( - layoutMarkerData.maxMeasureCache, - layout->nextCachedMeasurementsIndex + 1u); - - if (layout->nextCachedMeasurementsIndex == - LayoutResults::MaxCachedMeasurements) { - layout->nextCachedMeasurementsIndex = 0; - } - - CachedMeasurement* newCacheEntry; - if (performLayout) { - // Use the single layout cache entry. - newCacheEntry = &layout->cachedLayout; - } else { - // Allocate a new measurement cache entry. - newCacheEntry = - &layout->cachedMeasurements[layout->nextCachedMeasurementsIndex]; - layout->nextCachedMeasurementsIndex++; - } - - newCacheEntry->availableWidth = availableWidth; - newCacheEntry->availableHeight = availableHeight; - newCacheEntry->widthSizingMode = widthSizingMode; - newCacheEntry->heightSizingMode = heightSizingMode; - newCacheEntry->computedWidth = - layout->measuredDimension(Dimension::Width); - newCacheEntry->computedHeight = - layout->measuredDimension(Dimension::Height); - } - } - - if (performLayout) { - node->setLayoutDimension( - node->getLayout().measuredDimension(Dimension::Width), - Dimension::Width); - node->setLayoutDimension( - node->getLayout().measuredDimension(Dimension::Height), - Dimension::Height); - - node->setHasNewLayout(true); - node->setDirty(false); - } - - layout->generationCount = generationCount; - - LayoutType layoutType; - if (performLayout) { - layoutType = !needToVisitNode && cachedResults == &layout->cachedLayout - ? LayoutType::kCachedLayout - : LayoutType::kLayout; - } else { - layoutType = cachedResults != nullptr ? LayoutType::kCachedMeasure - : LayoutType::kMeasure; - } - Event::publish(node, {layoutType}); - - return (needToVisitNode || cachedResults == nullptr); -} - -void calculateLayout( - yoga::Node* const node, - const float ownerWidth, - const float ownerHeight, - const Direction ownerDirection) { - Event::publish(node); - LayoutData markerData = {}; - - // Increment the generation count. This will force the recursive routine to - // visit all dirty nodes at least once. Subsequent visits will be skipped if - // the input parameters don't change. - gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); - node->resolveDimension(); - float width = YGUndefined; - SizingMode widthSizingMode = SizingMode::MaxContent; - const auto& style = node->style(); - if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) { - width = - (node->getResolvedDimension(dimension(FlexDirection::Row)) - .resolve(ownerWidth) - .unwrap() + - node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth)); - widthSizingMode = SizingMode::StretchFit; - } else if (style.maxDimension(Dimension::Width) - .resolve(ownerWidth) - .isDefined()) { - width = style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap(); - widthSizingMode = SizingMode::FitContent; - } else { - width = ownerWidth; - widthSizingMode = yoga::isUndefined(width) ? SizingMode::MaxContent - : SizingMode::StretchFit; - } - - float height = YGUndefined; - SizingMode heightSizingMode = SizingMode::MaxContent; - if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) { - height = - (node->getResolvedDimension(dimension(FlexDirection::Column)) - .resolve(ownerHeight) - .unwrap() + - node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth)); - heightSizingMode = SizingMode::StretchFit; - } else if (style.maxDimension(Dimension::Height) - .resolve(ownerHeight) - .isDefined()) { - height = - style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap(); - heightSizingMode = SizingMode::FitContent; - } else { - height = ownerHeight; - heightSizingMode = yoga::isUndefined(height) ? SizingMode::MaxContent - : SizingMode::StretchFit; - } - if (calculateLayoutInternal( - node, - width, - height, - ownerDirection, - widthSizingMode, - heightSizingMode, - ownerWidth, - ownerHeight, - true, - LayoutPassReason::kInitial, - markerData, - 0, // tree root - gCurrentGenerationCount.load(std::memory_order_relaxed))) { - node->setPosition( - node->getLayout().direction(), ownerWidth, ownerHeight, ownerWidth); - roundLayoutResultsToPixelGrid(node, 0.0f, 0.0f); - } - - Event::publish(node, {&markerData}); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_CalculateLayout.h b/Sources/yoga/Algorithm_CalculateLayout.h deleted file mode 100644 index af0ba734..00000000 --- a/Sources/yoga/Algorithm_CalculateLayout.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" -#include "Algorithm_FlexDirection.h" -#include "Event_event.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -void calculateLayout( - yoga::Node* const node, - const float ownerWidth, - const float ownerHeight, - const Direction ownerDirection); - -bool calculateLayoutInternal( - yoga::Node* const node, - const float availableWidth, - const float availableHeight, - const Direction ownerDirection, - const SizingMode widthSizingMode, - const SizingMode heightSizingMode, - const float ownerWidth, - const float ownerHeight, - const bool performLayout, - const LayoutPassReason reason, - LayoutData& layoutMarkerData, - const uint32_t depth, - const uint32_t generationCount); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_FlexDirection.h b/Sources/yoga/Algorithm_FlexDirection.h deleted file mode 100644 index cdb9ccba..00000000 --- a/Sources/yoga/Algorithm_FlexDirection.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" - -#include "Debug_AssertFatal.h" -#include "Enums_Dimension.h" -#include "Enums_Direction.h" -#include "Enums_Edge.h" -#include "Enums_FlexDirection.h" -#include "Enums_PhysicalEdge.h" - -namespace facebook::yoga { - -inline bool isRow(const FlexDirection flexDirection) { - return flexDirection == FlexDirection::Row || - flexDirection == FlexDirection::RowReverse; -} - -inline bool isColumn(const FlexDirection flexDirection) { - return flexDirection == FlexDirection::Column || - flexDirection == FlexDirection::ColumnReverse; -} - -inline FlexDirection resolveDirection( - const FlexDirection flexDirection, - const Direction direction) { - if (direction == Direction::RTL) { - if (flexDirection == FlexDirection::Row) { - return FlexDirection::RowReverse; - } else if (flexDirection == FlexDirection::RowReverse) { - return FlexDirection::Row; - } - } - - return flexDirection; -} - -inline FlexDirection resolveCrossDirection( - const FlexDirection flexDirection, - const Direction direction) { - return isColumn(flexDirection) - ? resolveDirection(FlexDirection::Row, direction) - : FlexDirection::Column; -} - -inline PhysicalEdge flexStartEdge(FlexDirection flexDirection) { - switch (flexDirection) { - case FlexDirection::Column: - return PhysicalEdge::Top; - case FlexDirection::ColumnReverse: - return PhysicalEdge::Bottom; - case FlexDirection::Row: - return PhysicalEdge::Left; - case FlexDirection::RowReverse: - return PhysicalEdge::Right; - } - - fatalWithMessage("Invalid FlexDirection"); -} - -inline PhysicalEdge flexEndEdge(FlexDirection flexDirection) { - switch (flexDirection) { - case FlexDirection::Column: - return PhysicalEdge::Bottom; - case FlexDirection::ColumnReverse: - return PhysicalEdge::Top; - case FlexDirection::Row: - return PhysicalEdge::Right; - case FlexDirection::RowReverse: - return PhysicalEdge::Left; - } - - fatalWithMessage("Invalid FlexDirection"); -} - -inline PhysicalEdge inlineStartEdge( - FlexDirection flexDirection, - Direction direction) { - if (isRow(flexDirection)) { - return direction == Direction::RTL ? PhysicalEdge::Right - : PhysicalEdge::Left; - } - - return PhysicalEdge::Top; -} - -inline PhysicalEdge inlineEndEdge( - FlexDirection flexDirection, - Direction direction) { - if (isRow(flexDirection)) { - return direction == Direction::RTL ? PhysicalEdge::Left - : PhysicalEdge::Right; - } - - return PhysicalEdge::Bottom; -} - -inline Dimension dimension(FlexDirection flexDirection) { - switch (flexDirection) { - case FlexDirection::Column: - return Dimension::Height; - case FlexDirection::ColumnReverse: - return Dimension::Height; - case FlexDirection::Row: - return Dimension::Width; - case FlexDirection::RowReverse: - return Dimension::Width; - } - - fatalWithMessage("Invalid FlexDirection"); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_FlexLine.cpp b/Sources/yoga/Algorithm_FlexLine.cpp deleted file mode 100644 index b16ba96d..00000000 --- a/Sources/yoga/Algorithm_FlexLine.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" - -#include "Algorithm_BoundAxis.h" -#include "Algorithm_FlexDirection.h" -#include "Algorithm_FlexLine.h" - -namespace facebook::yoga { - -FlexLine calculateFlexLine( - yoga::Node* const node, - const Direction ownerDirection, - const float mainAxisownerSize, - const float availableInnerWidth, - const float availableInnerMainDim, - const size_t startOfLineIndex, - const size_t lineCount) { - std::vector itemsInFlow; - itemsInFlow.reserve(node->getChildren().size()); - - float sizeConsumed = 0.0f; - float totalFlexGrowFactors = 0.0f; - float totalFlexShrinkScaledFactors = 0.0f; - size_t endOfLineIndex = startOfLineIndex; - size_t firstElementInLineIndex = startOfLineIndex; - - float sizeConsumedIncludingMinConstraint = 0; - const FlexDirection mainAxis = resolveDirection( - node->style().flexDirection(), node->resolveDirection(ownerDirection)); - const bool isNodeFlexWrap = node->style().flexWrap() != Wrap::NoWrap; - const float gap = node->style().computeGapForAxis(mainAxis); - - // Add items to the current line until it's full or we run out of items. - for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) { - auto child = node->getChild(endOfLineIndex); - if (child->style().display() == Display::None || - child->style().positionType() == PositionType::Absolute) { - if (firstElementInLineIndex == endOfLineIndex) { - // We haven't found the first contributing element in the line yet. - firstElementInLineIndex++; - } - continue; - } - - const bool isFirstElementInLine = - (endOfLineIndex - firstElementInLineIndex) == 0; - - child->setLineIndex(lineCount); - const float childMarginMainAxis = - child->style().computeMarginForAxis(mainAxis, availableInnerWidth); - const float childLeadingGapMainAxis = isFirstElementInLine ? 0.0f : gap; - const float flexBasisWithMinAndMaxConstraints = - boundAxisWithinMinAndMax( - child, - mainAxis, - child->getLayout().computedFlexBasis, - mainAxisownerSize) - .unwrap(); - - // If this is a multi-line flow and this item pushes us over the available - // size, we've hit the end of the current line. Break out of the loop and - // lay out the current line. - if (sizeConsumedIncludingMinConstraint + flexBasisWithMinAndMaxConstraints + - childMarginMainAxis + childLeadingGapMainAxis > - availableInnerMainDim && - isNodeFlexWrap && itemsInFlow.size() > 0) { - break; - } - - sizeConsumedIncludingMinConstraint += flexBasisWithMinAndMaxConstraints + - childMarginMainAxis + childLeadingGapMainAxis; - sizeConsumed += flexBasisWithMinAndMaxConstraints + childMarginMainAxis + - childLeadingGapMainAxis; - - if (child->isNodeFlexible()) { - totalFlexGrowFactors += child->resolveFlexGrow(); - - // Unlike the grow factor, the shrink factor is scaled relative to the - // child dimension. - totalFlexShrinkScaledFactors += -child->resolveFlexShrink() * - child->getLayout().computedFlexBasis.unwrap(); - } - - itemsInFlow.push_back(child); - } - - // The total flex factor needs to be floored to 1. - if (totalFlexGrowFactors > 0 && totalFlexGrowFactors < 1) { - totalFlexGrowFactors = 1; - } - - // The total flex shrink factor needs to be floored to 1. - if (totalFlexShrinkScaledFactors > 0 && totalFlexShrinkScaledFactors < 1) { - totalFlexShrinkScaledFactors = 1; - } - - return FlexLine{ - std::move(itemsInFlow), - sizeConsumed, - endOfLineIndex, - FlexLineRunningLayout{ - totalFlexGrowFactors, - totalFlexShrinkScaledFactors, - }}; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_FlexLine.h b/Sources/yoga/Algorithm_FlexLine.h deleted file mode 100644 index f589990f..00000000 --- a/Sources/yoga/Algorithm_FlexLine.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Yoga.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -struct FlexLineRunningLayout { - // Total flex grow factors of flex items which are to be laid in the current - // line. This is decremented as free space is distributed. - float totalFlexGrowFactors{0.0f}; - - // Total flex shrink factors of flex items which are to be laid in the current - // line. This is decremented as free space is distributed. - float totalFlexShrinkScaledFactors{0.0f}; - - // The amount of available space within inner dimensions of the line which may - // still be distributed. - float remainingFreeSpace{0.0f}; - - // The size of the mainDim for the row after considering size, padding, margin - // and border of flex items. This is used to calculate maxLineDim after going - // through all the rows to decide on the main axis size of owner. - float mainDim{0.0f}; - - // The size of the crossDim for the row after considering size, padding, - // margin and border of flex items. Used for calculating containers crossSize. - float crossDim{0.0f}; -}; - -struct FlexLine { - // List of children which are part of the line flow. This means they are not - // positioned absolutely, or with `display: "none"`, and do not overflow the - // available dimensions. - const std::vector itemsInFlow{}; - - // Accumulation of the dimensions and margin of all the children on the - // current line. This will be used in order to either set the dimensions of - // the node if none already exist or to compute the remaining space left for - // the flexible children. - const float sizeConsumed{0.0f}; - - // The index of the first item beyond the current line. - const size_t endOfLineIndex{0}; - - // Layout information about the line computed in steps after line-breaking - FlexLineRunningLayout layout{}; -}; - -// Calculates where a line starting at a given index should break, returning -// information about the collective children on the liune. -// -// This function assumes that all the children of node have their -// computedFlexBasis properly computed(To do this use -// computeFlexBasisForChildren function). -FlexLine calculateFlexLine( - yoga::Node* const node, - Direction ownerDirection, - float mainAxisownerSize, - float availableInnerWidth, - float availableInnerMainDim, - size_t startOfLineIndex, - size_t lineCount); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_PixelGrid.cpp b/Sources/yoga/Algorithm_PixelGrid.cpp deleted file mode 100644 index 3905fd48..00000000 --- a/Sources/yoga/Algorithm_PixelGrid.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" - -#include "Algorithm_PixelGrid.h" -#include "Numeric_Comparison.h" - -namespace facebook::yoga { - -float roundValueToPixelGrid( - const double value, - const double pointScaleFactor, - const bool forceCeil, - const bool forceFloor) { - double scaledValue = value * pointScaleFactor; - // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue - // - fractial`. - double fractial = fmod(scaledValue, 1.0); - if (fractial < 0) { - // This branch is for handling negative numbers for `value`. - // - // Regarding `floor` and `ceil`. Note that for a number x, `floor(x) <= x <= - // ceil(x)` even for negative numbers. Here are a couple of examples: - // - x = 2.2: floor( 2.2) = 2, ceil( 2.2) = 3 - // - x = -2.2: floor(-2.2) = -3, ceil(-2.2) = -2 - // - // Regarding `fmodf`. For fractional negative numbers, `fmodf` returns a - // negative number. For example, `fmodf(-2.2) = -0.2`. However, we want - // `fractial` to be the number such that subtracting it from `value` will - // give us `floor(value)`. In the case of negative numbers, adding 1 to - // `fmodf(value)` gives us this. Let's continue the example from above: - // - fractial = fmodf(-2.2) = -0.2 - // - Add 1 to the fraction: fractial2 = fractial + 1 = -0.2 + 1 = 0.8 - // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 - ++fractial; - } - if (yoga::inexactEquals(fractial, 0)) { - // First we check if the value is already rounded - scaledValue = scaledValue - fractial; - } else if (yoga::inexactEquals(fractial, 1.0)) { - scaledValue = scaledValue - fractial + 1.0; - } else if (forceCeil) { - // Next we check if we need to use forced rounding - scaledValue = scaledValue - fractial + 1.0; - } else if (forceFloor) { - scaledValue = scaledValue - fractial; - } else { - // Finally we just round the value - scaledValue = scaledValue - fractial + - (!std::isnan(fractial) && - (fractial > 0.5 || yoga::inexactEquals(fractial, 0.5)) - ? 1.0 - : 0.0); - } - return (std::isnan(scaledValue) || std::isnan(pointScaleFactor)) - ? YGUndefined - : (float)(scaledValue / pointScaleFactor); -} - -void roundLayoutResultsToPixelGrid( - yoga::Node* const node, - const double absoluteLeft, - const double absoluteTop) { - const auto pointScaleFactor = node->getConfig()->getPointScaleFactor(); - - const double nodeLeft = node->getLayout().position(PhysicalEdge::Left); - const double nodeTop = node->getLayout().position(PhysicalEdge::Top); - - const double nodeWidth = node->getLayout().dimension(Dimension::Width); - const double nodeHeight = node->getLayout().dimension(Dimension::Height); - - const double absoluteNodeLeft = absoluteLeft + nodeLeft; - const double absoluteNodeTop = absoluteTop + nodeTop; - - const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; - const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; - - if (pointScaleFactor != 0.0f) { - // If a node has a custom measure function we never want to round down its - // size as this could lead to unwanted text truncation. - const bool textRounding = node->getNodeType() == NodeType::Text; - - node->setLayoutPosition( - roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding), - PhysicalEdge::Left); - - node->setLayoutPosition( - roundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding), - PhysicalEdge::Top); - - // We multiply dimension by scale factor and if the result is close to the - // whole number, we don't have any fraction To verify if the result is close - // to whole number we want to check both floor and ceil numbers - const bool hasFractionalWidth = - !yoga::inexactEquals(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && - !yoga::inexactEquals(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0); - const bool hasFractionalHeight = - !yoga::inexactEquals(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && - !yoga::inexactEquals(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); - - node->setLayoutDimension( - roundValueToPixelGrid( - absoluteNodeRight, - pointScaleFactor, - (textRounding && hasFractionalWidth), - (textRounding && !hasFractionalWidth)) - - roundValueToPixelGrid( - absoluteNodeLeft, pointScaleFactor, false, textRounding), - Dimension::Width); - - node->setLayoutDimension( - roundValueToPixelGrid( - absoluteNodeBottom, - pointScaleFactor, - (textRounding && hasFractionalHeight), - (textRounding && !hasFractionalHeight)) - - roundValueToPixelGrid( - absoluteNodeTop, pointScaleFactor, false, textRounding), - Dimension::Height); - } - - for (yoga::Node* child : node->getChildren()) { - roundLayoutResultsToPixelGrid(child, absoluteNodeLeft, absoluteNodeTop); - } -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_PixelGrid.h b/Sources/yoga/Algorithm_PixelGrid.h deleted file mode 100644 index cb6f0c97..00000000 --- a/Sources/yoga/Algorithm_PixelGrid.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -// Round a point value to the nearest physical pixel based on DPI -// (pointScaleFactor) -float roundValueToPixelGrid( - const double value, - const double pointScaleFactor, - const bool forceCeil, - const bool forceFloor); - -// Round the layout results of a node and its subtree to the pixel grid. -void roundLayoutResultsToPixelGrid( - yoga::Node* const node, - const double absoluteLeft, - const double absoluteTop); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_SizingMode.h b/Sources/yoga/Algorithm_SizingMode.h deleted file mode 100644 index ee1af852..00000000 --- a/Sources/yoga/Algorithm_SizingMode.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Debug_AssertFatal.h" -#include "Enums_MeasureMode.h" - -namespace facebook::yoga { - -/** - * Corresponds to a CSS auto box sizes. Missing "min-content", as Yoga does not - * current support automatic minimum sizes. - * https://www.w3.org/TR/css-sizing-3/#auto-box-sizes - * https://www.w3.org/TR/css-flexbox-1/#min-size-auto - */ -enum class SizingMode { - /** - * The size a box would take if its outer size filled the available space in - * the given axis; in other words, the stretch fit into the available space, - * if that is definite. Undefined if the available space is indefinite. - */ - StretchFit, - - /** - * A box’s “ideal” size in a given axis when given infinite available space. - * Usually this is the smallest size the box could take in that axis while - * still fitting around its contents, i.e. minimizing unfilled space while - * avoiding overflow. - */ - MaxContent, - - /** - * If the available space in a given axis is definite, equal to - * clamp(min-content size, stretch-fit size, max-content size) (i.e. - * max(min-content size, min(max-content size, stretch-fit size))). When - * sizing under a min-content constraint, equal to the min-content size. - * Otherwise, equal to the max-content size in that axis. - */ - FitContent, -}; - -inline MeasureMode measureMode(SizingMode mode) { - switch (mode) { - case SizingMode::StretchFit: - return MeasureMode::Exactly; - case SizingMode::MaxContent: - return MeasureMode::Undefined; - case SizingMode::FitContent: - return MeasureMode::AtMost; - } - - fatalWithMessage("Invalid SizingMode"); -} - -inline SizingMode sizingMode(MeasureMode mode) { - switch (mode) { - case MeasureMode::Exactly: - return SizingMode::StretchFit; - case MeasureMode::Undefined: - return SizingMode::MaxContent; - case MeasureMode::AtMost: - return SizingMode::FitContent; - } - - fatalWithMessage("Invalid MeasureMode"); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Algorithm_TrailingPosition.h b/Sources/yoga/Algorithm_TrailingPosition.h deleted file mode 100644 index a5fbbc6e..00000000 --- a/Sources/yoga/Algorithm_TrailingPosition.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" -#include "Algorithm_FlexDirection.h" -#include "Event_event.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -// Given an offset to an edge, returns the offset to the opposite edge on the -// same axis. This assumes that the width/height of both nodes is determined at -// this point. -inline float getPositionOfOppositeEdge( - float position, - FlexDirection axis, - const yoga::Node* const containingNode, - const yoga::Node* const node) { - return containingNode->getLayout().measuredDimension(dimension(axis)) - - node->getLayout().measuredDimension(dimension(axis)) - position; -} - -inline void setChildTrailingPosition( - const yoga::Node* const node, - yoga::Node* const child, - const FlexDirection axis) { - child->setLayoutPosition( - getPositionOfOppositeEdge( - child->getLayout().position(flexStartEdge(axis)), axis, node, child), - flexEndEdge(axis)); -} - -inline bool needsTrailingPosition(const FlexDirection axis) { - return axis == FlexDirection::RowReverse || - axis == FlexDirection::ColumnReverse; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/CMakeLists.txt b/Sources/yoga/CMakeLists.txt deleted file mode 100644 index b6eca1ac..00000000 --- a/Sources/yoga/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - - -cmake_minimum_required(VERSION 3.13...3.26) -project(yogacore) -set(CMAKE_VERBOSE_MAKEFILE on) - -if(TARGET yogacore) - return() -endif() - -include(CheckIPOSupported) - -set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) -include(${YOGA_ROOT}/cmake/project-defaults.cmake) - - -file(GLOB SOURCES CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) - -add_library(yogacore STATIC ${SOURCES}) - -# Yoga conditionally uses when building for Android -if (ANDROID) - target_link_libraries(yogacore log) -endif() - -check_ipo_supported(RESULT result) -if(result) - set_target_properties(yogacore PROPERTIES - CMAKE_INTERPROCEDURAL_OPTIMIZATION true) -endif() - -target_include_directories(yogacore - PUBLIC - $ - $) diff --git a/Sources/yoga/Config_Config.cpp b/Sources/yoga/Config_Config.cpp deleted file mode 100644 index 4e013884..00000000 --- a/Sources/yoga/Config_Config.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Config_Config.h" -#include "Debug_Log.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -bool configUpdateInvalidatesLayout( - const Config& oldConfig, - const Config& newConfig) { - return oldConfig.getErrata() != newConfig.getErrata() || - oldConfig.getEnabledExperiments() != newConfig.getEnabledExperiments() || - oldConfig.getPointScaleFactor() != newConfig.getPointScaleFactor() || - oldConfig.useWebDefaults() != newConfig.useWebDefaults(); -} - -Config::Config(YGLogger logger) : cloneNodeCallback_{nullptr} { - setLogger(logger); -} - -void Config::setUseWebDefaults(bool useWebDefaults) { - useWebDefaults_ = useWebDefaults; -} - -bool Config::useWebDefaults() const { - return useWebDefaults_; -} - -void Config::setExperimentalFeatureEnabled( - ExperimentalFeature feature, - bool enabled) { - experimentalFeatures_.set(static_cast(feature), enabled); -} - -bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const { - return experimentalFeatures_.test(static_cast(feature)); -} - -ExperimentalFeatureSet Config::getEnabledExperiments() const { - return experimentalFeatures_; -} - -void Config::setErrata(Errata errata) { - errata_ = errata; -} - -void Config::addErrata(Errata errata) { - errata_ |= errata; -} - -void Config::removeErrata(Errata errata) { - errata_ &= (~errata); -} - -Errata Config::getErrata() const { - return errata_; -} - -bool Config::hasErrata(Errata errata) const { - return (errata_ & errata) != Errata::None; -} - -void Config::setPointScaleFactor(float pointScaleFactor) { - pointScaleFactor_ = pointScaleFactor; -} - -float Config::getPointScaleFactor() const { - return pointScaleFactor_; -} - -void Config::setContext(void* context) { - context_ = context; -} - -void* Config::getContext() const { - return context_; -} - -void Config::setLogger(YGLogger logger) { - logger_ = logger; -} - -void Config::log( - const yoga::Node* node, - LogLevel logLevel, - const char* format, - va_list args) const { - logger_(this, node, unscopedEnum(logLevel), format, args); -} - -void Config::setCloneNodeCallback(YGCloneNodeFunc cloneNode) { - cloneNodeCallback_ = cloneNode; -} - -YGNodeRef Config::cloneNode( - YGNodeConstRef node, - YGNodeConstRef owner, - size_t childIndex) const { - YGNodeRef clone = nullptr; - if (cloneNodeCallback_ != nullptr) { - clone = cloneNodeCallback_(node, owner, childIndex); - } - if (clone == nullptr) { - clone = YGNodeClone(node); - } - return clone; -} - -/*static*/ const Config& Config::getDefault() { - static Config config{getDefaultLogger()}; - return config; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Config_Config.h b/Sources/yoga/Config_Config.h deleted file mode 100644 index 2eff5c3b..00000000 --- a/Sources/yoga/Config_Config.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Yoga.h" -#include "Enums_Errata.h" -#include "Enums_ExperimentalFeature.h" -#include "Enums_LogLevel.h" - -// Tag struct used to form the opaque YGConfigRef for the public C API -struct YGConfig {}; - -namespace facebook::yoga { - -class Config; -class Node; - -using ExperimentalFeatureSet = std::bitset()>; - -// Whether moving a node from an old to new config should dirty previously -// calculated layout results. -bool configUpdateInvalidatesLayout( - const Config& oldConfig, - const Config& newConfig); - -class YG_EXPORT Config : public ::YGConfig { - public: - Config(YGLogger logger); - - void setUseWebDefaults(bool useWebDefaults); - bool useWebDefaults() const; - - void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled); - bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const; - ExperimentalFeatureSet getEnabledExperiments() const; - - void setErrata(Errata errata); - void addErrata(Errata errata); - void removeErrata(Errata errata); - Errata getErrata() const; - bool hasErrata(Errata errata) const; - - void setPointScaleFactor(float pointScaleFactor); - float getPointScaleFactor() const; - - void setContext(void* context); - void* getContext() const; - - void setLogger(YGLogger logger); - void log( - const yoga::Node* node, - LogLevel logLevel, - const char* format, - va_list args) const; - - void setCloneNodeCallback(YGCloneNodeFunc cloneNode); - YGNodeRef - cloneNode(YGNodeConstRef node, YGNodeConstRef owner, size_t childIndex) const; - - static const Config& getDefault(); - - private: - YGCloneNodeFunc cloneNodeCallback_; - YGLogger logger_; - - bool useWebDefaults_ : 1 = false; - - ExperimentalFeatureSet experimentalFeatures_{}; - Errata errata_ = Errata::None; - float pointScaleFactor_ = 1.0f; - void* context_ = nullptr; -}; - -inline Config* resolveRef(const YGConfigRef ref) { - return static_cast(ref); -} - -inline const Config* resolveRef(const YGConfigConstRef ref) { - return static_cast(ref); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Debug_AssertFatal.cpp b/Sources/yoga/Debug_AssertFatal.cpp deleted file mode 100644 index d83cd019..00000000 --- a/Sources/yoga/Debug_AssertFatal.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include - -#include "Config_Config.h" -#include "Debug_AssertFatal.h" -#include "Debug_Log.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -[[noreturn]] void fatalWithMessage(const char* message) { -#if defined(__cpp_exceptions) - throw std::logic_error(message); -#else - std::terminate(); -#endif -} - -void assertFatal(const bool condition, const char* message) { - if (!condition) { - yoga::log(LogLevel::Fatal, "%s\n", message); - fatalWithMessage(message); - } -} - -void assertFatalWithNode( - const yoga::Node* const node, - const bool condition, - const char* message) { - if (!condition) { - yoga::log(node, LogLevel::Fatal, "%s\n", message); - fatalWithMessage(message); - } -} - -void assertFatalWithConfig( - const yoga::Config* const config, - const bool condition, - const char* message) { - if (!condition) { - yoga::log(config, LogLevel::Fatal, "%s\n", message); - fatalWithMessage(message); - } -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Debug_AssertFatal.h b/Sources/yoga/Debug_AssertFatal.h deleted file mode 100644 index b1169e8b..00000000 --- a/Sources/yoga/Debug_AssertFatal.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" - -namespace facebook::yoga { - -class Node; -class Config; - -[[noreturn]] void fatalWithMessage(const char* message); - -void assertFatal(bool condition, const char* message); -void assertFatalWithNode( - const yoga::Node* node, - bool condition, - const char* message); -void assertFatalWithConfig( - const yoga::Config* config, - bool condition, - const char* message); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Debug_Log.cpp b/Sources/yoga/Debug_Log.cpp deleted file mode 100644 index fdd0903d..00000000 --- a/Sources/yoga/Debug_Log.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Debug_Log.h" - -#ifdef ANDROID -#include -#endif - -namespace facebook::yoga { - -namespace { - -void vlog( - const yoga::Config* config, - const yoga::Node* node, - LogLevel level, - const char* format, - va_list args) { - if (config == nullptr) { - getDefaultLogger()(nullptr, node, unscopedEnum(level), format, args); - } else { - config->log(node, level, format, args); - } -} -} // namespace - -void log(LogLevel level, const char* format, ...) noexcept { - va_list args; - va_start(args, format); - vlog(nullptr, nullptr, level, format, args); - va_end(args); -} - -void log( - const yoga::Node* node, - LogLevel level, - const char* format, - ...) noexcept { - va_list args; - va_start(args, format); - vlog( - node == nullptr ? nullptr : node->getConfig(), node, level, format, args); - va_end(args); -} - -void log( - const yoga::Config* config, - LogLevel level, - const char* format, - ...) noexcept { - va_list args; - va_start(args, format); - vlog(config, nullptr, level, format, args); - va_end(args); -} - -YGLogger getDefaultLogger() { - return [](const YGConfigConstRef /*config*/, - const YGNodeConstRef /*node*/, - YGLogLevel level, - const char* format, - va_list args) -> int { -#ifdef ANDROID - int androidLevel = YGLogLevelDebug; - switch (level) { - case YGLogLevelFatal: - androidLevel = ANDROID_LOG_FATAL; - break; - case YGLogLevelError: - androidLevel = ANDROID_LOG_ERROR; - break; - case YGLogLevelWarn: - androidLevel = ANDROID_LOG_WARN; - break; - case YGLogLevelInfo: - androidLevel = ANDROID_LOG_INFO; - break; - case YGLogLevelDebug: - androidLevel = ANDROID_LOG_DEBUG; - break; - case YGLogLevelVerbose: - androidLevel = ANDROID_LOG_VERBOSE; - break; - } - return __android_log_vprint(androidLevel, "yoga", format, args); -#else - switch (level) { - case YGLogLevelError: - case YGLogLevelFatal: - return vfprintf(stderr, format, args); - case YGLogLevelWarn: - case YGLogLevelInfo: - case YGLogLevelDebug: - case YGLogLevelVerbose: - default: - return vprintf(format, args); - } -#endif - }; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Debug_Log.h b/Sources/yoga/Debug_Log.h deleted file mode 100644 index bd53e944..00000000 --- a/Sources/yoga/Debug_Log.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" - -#include "Config_Config.h" -#include "Enums_LogLevel.h" -#include "Node_Node.h" - -namespace facebook::yoga { - -void log(LogLevel level, const char* format, ...) noexcept; - -void log( - const yoga::Node* node, - LogLevel level, - const char* message, - ...) noexcept; - -void log( - const yoga::Config* config, - LogLevel level, - const char* format, - ...) noexcept; - -YGLogger getDefaultLogger(); - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Align.h b/Sources/yoga/Enums_Align.h deleted file mode 100644 index 69709413..00000000 --- a/Sources/yoga/Enums_Align.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Align : uint8_t { - Auto = YGAlignAuto, - FlexStart = YGAlignFlexStart, - Center = YGAlignCenter, - FlexEnd = YGAlignFlexEnd, - Stretch = YGAlignStretch, - Baseline = YGAlignBaseline, - SpaceBetween = YGAlignSpaceBetween, - SpaceAround = YGAlignSpaceAround, - SpaceEvenly = YGAlignSpaceEvenly, -}; - -template <> -constexpr int32_t ordinalCount() { - return 9; -} - -constexpr Align scopedEnum(YGAlign unscoped) { - return static_cast(unscoped); -} - -constexpr YGAlign unscopedEnum(Align scoped) { - return static_cast(scoped); -} - -inline const char* toString(Align e) { - return YGAlignToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Dimension.h b/Sources/yoga/Enums_Dimension.h deleted file mode 100644 index 6b336f61..00000000 --- a/Sources/yoga/Enums_Dimension.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Dimension : uint8_t { - Width = YGDimensionWidth, - Height = YGDimensionHeight, -}; - -template <> -constexpr int32_t ordinalCount() { - return 2; -} - -constexpr Dimension scopedEnum(YGDimension unscoped) { - return static_cast(unscoped); -} - -constexpr YGDimension unscopedEnum(Dimension scoped) { - return static_cast(scoped); -} - -inline const char* toString(Dimension e) { - return YGDimensionToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Direction.h b/Sources/yoga/Enums_Direction.h deleted file mode 100644 index 3d7511bb..00000000 --- a/Sources/yoga/Enums_Direction.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Direction : uint8_t { - Inherit = YGDirectionInherit, - LTR = YGDirectionLTR, - RTL = YGDirectionRTL, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr Direction scopedEnum(YGDirection unscoped) { - return static_cast(unscoped); -} - -constexpr YGDirection unscopedEnum(Direction scoped) { - return static_cast(scoped); -} - -inline const char* toString(Direction e) { - return YGDirectionToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Display.h b/Sources/yoga/Enums_Display.h deleted file mode 100644 index 4022482b..00000000 --- a/Sources/yoga/Enums_Display.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Display : uint8_t { - Flex = YGDisplayFlex, - None = YGDisplayNone, -}; - -template <> -constexpr int32_t ordinalCount() { - return 2; -} - -constexpr Display scopedEnum(YGDisplay unscoped) { - return static_cast(unscoped); -} - -constexpr YGDisplay unscopedEnum(Display scoped) { - return static_cast(scoped); -} - -inline const char* toString(Display e) { - return YGDisplayToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Edge.h b/Sources/yoga/Enums_Edge.h deleted file mode 100644 index 0fa3dc4a..00000000 --- a/Sources/yoga/Enums_Edge.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Edge : uint8_t { - Left = YGEdgeLeft, - Top = YGEdgeTop, - Right = YGEdgeRight, - Bottom = YGEdgeBottom, - Start = YGEdgeStart, - End = YGEdgeEnd, - Horizontal = YGEdgeHorizontal, - Vertical = YGEdgeVertical, - All = YGEdgeAll, -}; - -template <> -constexpr int32_t ordinalCount() { - return 9; -} - -constexpr Edge scopedEnum(YGEdge unscoped) { - return static_cast(unscoped); -} - -constexpr YGEdge unscopedEnum(Edge scoped) { - return static_cast(scoped); -} - -inline const char* toString(Edge e) { - return YGEdgeToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Errata.h b/Sources/yoga/Enums_Errata.h deleted file mode 100644 index 92e5ed62..00000000 --- a/Sources/yoga/Enums_Errata.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Errata : uint32_t { - None = YGErrataNone, - StretchFlexBasis = YGErrataStretchFlexBasis, - AbsolutePositioningIncorrect = YGErrataAbsolutePositioningIncorrect, - AbsolutePercentAgainstInnerSize = YGErrataAbsolutePercentAgainstInnerSize, - All = YGErrataAll, - Classic = YGErrataClassic, -}; - -YG_DEFINE_ENUM_FLAG_OPERATORS(Errata) - -constexpr Errata scopedEnum(YGErrata unscoped) { - return static_cast(unscoped); -} - -constexpr YGErrata unscopedEnum(Errata scoped) { - return static_cast(scoped); -} - -inline const char* toString(Errata e) { - return YGErrataToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_ExperimentalFeature.h b/Sources/yoga/Enums_ExperimentalFeature.h deleted file mode 100644 index b68ff25f..00000000 --- a/Sources/yoga/Enums_ExperimentalFeature.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class ExperimentalFeature : uint8_t { - WebFlexBasis = YGExperimentalFeatureWebFlexBasis, -}; - -template <> -constexpr int32_t ordinalCount() { - return 1; -} - -constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) { - return static_cast(unscoped); -} - -constexpr YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) { - return static_cast(scoped); -} - -inline const char* toString(ExperimentalFeature e) { - return YGExperimentalFeatureToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_FlexDirection.h b/Sources/yoga/Enums_FlexDirection.h deleted file mode 100644 index 36f1f67f..00000000 --- a/Sources/yoga/Enums_FlexDirection.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class FlexDirection : uint8_t { - Column = YGFlexDirectionColumn, - ColumnReverse = YGFlexDirectionColumnReverse, - Row = YGFlexDirectionRow, - RowReverse = YGFlexDirectionRowReverse, -}; - -template <> -constexpr int32_t ordinalCount() { - return 4; -} - -constexpr FlexDirection scopedEnum(YGFlexDirection unscoped) { - return static_cast(unscoped); -} - -constexpr YGFlexDirection unscopedEnum(FlexDirection scoped) { - return static_cast(scoped); -} - -inline const char* toString(FlexDirection e) { - return YGFlexDirectionToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Gutter.h b/Sources/yoga/Enums_Gutter.h deleted file mode 100644 index 2d0c83af..00000000 --- a/Sources/yoga/Enums_Gutter.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Gutter : uint8_t { - Column = YGGutterColumn, - Row = YGGutterRow, - All = YGGutterAll, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr Gutter scopedEnum(YGGutter unscoped) { - return static_cast(unscoped); -} - -constexpr YGGutter unscopedEnum(Gutter scoped) { - return static_cast(scoped); -} - -inline const char* toString(Gutter e) { - return YGGutterToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Justify.h b/Sources/yoga/Enums_Justify.h deleted file mode 100644 index 09f74c6a..00000000 --- a/Sources/yoga/Enums_Justify.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Justify : uint8_t { - FlexStart = YGJustifyFlexStart, - Center = YGJustifyCenter, - FlexEnd = YGJustifyFlexEnd, - SpaceBetween = YGJustifySpaceBetween, - SpaceAround = YGJustifySpaceAround, - SpaceEvenly = YGJustifySpaceEvenly, -}; - -template <> -constexpr int32_t ordinalCount() { - return 6; -} - -constexpr Justify scopedEnum(YGJustify unscoped) { - return static_cast(unscoped); -} - -constexpr YGJustify unscopedEnum(Justify scoped) { - return static_cast(scoped); -} - -inline const char* toString(Justify e) { - return YGJustifyToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_LogLevel.h b/Sources/yoga/Enums_LogLevel.h deleted file mode 100644 index aec9bebd..00000000 --- a/Sources/yoga/Enums_LogLevel.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class LogLevel : uint8_t { - Error = YGLogLevelError, - Warn = YGLogLevelWarn, - Info = YGLogLevelInfo, - Debug = YGLogLevelDebug, - Verbose = YGLogLevelVerbose, - Fatal = YGLogLevelFatal, -}; - -template <> -constexpr int32_t ordinalCount() { - return 6; -} - -constexpr LogLevel scopedEnum(YGLogLevel unscoped) { - return static_cast(unscoped); -} - -constexpr YGLogLevel unscopedEnum(LogLevel scoped) { - return static_cast(scoped); -} - -inline const char* toString(LogLevel e) { - return YGLogLevelToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_MeasureMode.h b/Sources/yoga/Enums_MeasureMode.h deleted file mode 100644 index 79306832..00000000 --- a/Sources/yoga/Enums_MeasureMode.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class MeasureMode : uint8_t { - Undefined = YGMeasureModeUndefined, - Exactly = YGMeasureModeExactly, - AtMost = YGMeasureModeAtMost, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr MeasureMode scopedEnum(YGMeasureMode unscoped) { - return static_cast(unscoped); -} - -constexpr YGMeasureMode unscopedEnum(MeasureMode scoped) { - return static_cast(scoped); -} - -inline const char* toString(MeasureMode e) { - return YGMeasureModeToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_NodeType.h b/Sources/yoga/Enums_NodeType.h deleted file mode 100644 index 92735421..00000000 --- a/Sources/yoga/Enums_NodeType.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class NodeType : uint8_t { - Default = YGNodeTypeDefault, - Text = YGNodeTypeText, -}; - -template <> -constexpr int32_t ordinalCount() { - return 2; -} - -constexpr NodeType scopedEnum(YGNodeType unscoped) { - return static_cast(unscoped); -} - -constexpr YGNodeType unscopedEnum(NodeType scoped) { - return static_cast(scoped); -} - -inline const char* toString(NodeType e) { - return YGNodeTypeToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Overflow.h b/Sources/yoga/Enums_Overflow.h deleted file mode 100644 index 4aa45f9a..00000000 --- a/Sources/yoga/Enums_Overflow.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Overflow : uint8_t { - Visible = YGOverflowVisible, - Hidden = YGOverflowHidden, - Scroll = YGOverflowScroll, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr Overflow scopedEnum(YGOverflow unscoped) { - return static_cast(unscoped); -} - -constexpr YGOverflow unscopedEnum(Overflow scoped) { - return static_cast(scoped); -} - -inline const char* toString(Overflow e) { - return YGOverflowToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_PhysicalEdge.h b/Sources/yoga/Enums_PhysicalEdge.h deleted file mode 100644 index bd369954..00000000 --- a/Sources/yoga/Enums_PhysicalEdge.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Enums_Edge.h" - -namespace facebook::yoga { - -enum class PhysicalEdge : uint32_t { - Left = yoga::to_underlying(Edge::Left), - Top = yoga::to_underlying(Edge::Top), - Right = yoga::to_underlying(Edge::Right), - Bottom = yoga::to_underlying(Edge::Bottom), -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_PositionType.h b/Sources/yoga/Enums_PositionType.h deleted file mode 100644 index 269974b0..00000000 --- a/Sources/yoga/Enums_PositionType.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class PositionType : uint8_t { - Static = YGPositionTypeStatic, - Relative = YGPositionTypeRelative, - Absolute = YGPositionTypeAbsolute, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr PositionType scopedEnum(YGPositionType unscoped) { - return static_cast(unscoped); -} - -constexpr YGPositionType unscopedEnum(PositionType scoped) { - return static_cast(scoped); -} - -inline const char* toString(PositionType e) { - return YGPositionTypeToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Unit.h b/Sources/yoga/Enums_Unit.h deleted file mode 100644 index 6b69aa4e..00000000 --- a/Sources/yoga/Enums_Unit.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Unit : uint8_t { - Undefined = YGUnitUndefined, - Point = YGUnitPoint, - Percent = YGUnitPercent, - Auto = YGUnitAuto, -}; - -template <> -constexpr int32_t ordinalCount() { - return 4; -} - -constexpr Unit scopedEnum(YGUnit unscoped) { - return static_cast(unscoped); -} - -constexpr YGUnit unscopedEnum(Unit scoped) { - return static_cast(scoped); -} - -inline const char* toString(Unit e) { - return YGUnitToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_Wrap.h b/Sources/yoga/Enums_Wrap.h deleted file mode 100644 index 8ffec26f..00000000 --- a/Sources/yoga/Enums_Wrap.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once - -#include -#include "YGEnums.h" -#include "Enums_YogaEnums.h" - -namespace facebook::yoga { - -enum class Wrap : uint8_t { - NoWrap = YGWrapNoWrap, - Wrap = YGWrapWrap, - WrapReverse = YGWrapWrapReverse, -}; - -template <> -constexpr int32_t ordinalCount() { - return 3; -} - -constexpr Wrap scopedEnum(YGWrap unscoped) { - return static_cast(unscoped); -} - -constexpr YGWrap unscopedEnum(Wrap scoped) { - return static_cast(scoped); -} - -inline const char* toString(Wrap e) { - return YGWrapToString(unscopedEnum(e)); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Enums_YogaEnums.h b/Sources/yoga/Enums_YogaEnums.h deleted file mode 100644 index de446621..00000000 --- a/Sources/yoga/Enums_YogaEnums.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -namespace facebook::yoga { - -/** - * Concept for any enum/enum class - */ -template -concept Enumeration = std::is_enum_v; - -/** - * Count of ordinals in a Yoga enum which is sequential - */ -template -constexpr int32_t ordinalCount(); - -/** - * Concept for a yoga enum which is sequential - */ -template -concept HasOrdinality = (ordinalCount() > 0); - -/** - * Count of bits needed to represent every ordinal - */ -template -constexpr int32_t bitCount() { - return std::bit_width( - static_cast>(ordinalCount() - 1)); -} - -/** - * Polyfill of C++ 23 to_underlying() - * https://en.cppreference.com/w/cpp/utility/to_underlying - */ -constexpr auto to_underlying(Enumeration auto e) noexcept { - return static_cast>(e); -} - -/** - * Convenience function to iterate through every value in a Yoga enum as part of - * a range-based for loop. - */ -template -auto ordinals() { - struct Iterator { - EnumT e{}; - - EnumT operator*() const { - return e; - } - - Iterator& operator++() { - e = static_cast(to_underlying(e) + 1); - return *this; - } - - bool operator==(const Iterator& other) const = default; - bool operator!=(const Iterator& other) const = default; - }; - - struct Range { - Iterator begin() const { - return Iterator{}; - } - Iterator end() const { - return Iterator{static_cast(ordinalCount())}; - } - }; - - return Range{}; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Event_event.cpp b/Sources/yoga/Event_event.cpp deleted file mode 100644 index 1df7a29c..00000000 --- a/Sources/yoga/Event_event.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Event_event.h" -#include -#include - -namespace facebook::yoga { - -const char* LayoutPassReasonToString(const LayoutPassReason value) { - switch (value) { - case LayoutPassReason::kInitial: - return "initial"; - case LayoutPassReason::kAbsLayout: - return "abs_layout"; - case LayoutPassReason::kStretch: - return "stretch"; - case LayoutPassReason::kMultilineStretch: - return "multiline_stretch"; - case LayoutPassReason::kFlexLayout: - return "flex_layout"; - case LayoutPassReason::kMeasureChild: - return "measure"; - case LayoutPassReason::kAbsMeasureChild: - return "abs_measure"; - case LayoutPassReason::kFlexMeasure: - return "flex_measure"; - default: - return "unknown"; - } -} - -namespace { - -struct Node { - std::function subscriber = nullptr; - Node* next = nullptr; - - Node(std::function&& subscriber) - : subscriber{std::move(subscriber)} {} -}; - -std::atomic subscribers{nullptr}; - -Node* push(Node* newHead) { - Node* oldHead; - do { - oldHead = subscribers.load(std::memory_order_relaxed); - if (newHead != nullptr) { - newHead->next = oldHead; - } - } while (!subscribers.compare_exchange_weak( - oldHead, newHead, std::memory_order_release, std::memory_order_relaxed)); - return oldHead; -} - -} // namespace - -void Event::reset() { - auto head = push(nullptr); - while (head != nullptr) { - auto current = head; - head = head->next; - delete current; - } -} - -void Event::subscribe(std::function&& subscriber) { - push(new Node{std::move(subscriber)}); -} - -void Event::publish( - YGNodeConstRef node, - Type eventType, - const Data& eventData) { - for (auto subscriber = subscribers.load(std::memory_order_relaxed); - subscriber != nullptr; - subscriber = subscriber->next) { - subscriber->subscriber(node, eventType, eventData); - } -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Event_event.h b/Sources/yoga/Event_event.h deleted file mode 100644 index bad21ca9..00000000 --- a/Sources/yoga/Event_event.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Yoga.h" - -#include -#include -#include -#include - -namespace facebook::yoga { - -enum struct LayoutType : int { - kLayout = 0, - kMeasure = 1, - kCachedLayout = 2, - kCachedMeasure = 3 -}; - -enum struct LayoutPassReason : int { - kInitial = 0, - kAbsLayout = 1, - kStretch = 2, - kMultilineStretch = 3, - kFlexLayout = 4, - kMeasureChild = 5, - kAbsMeasureChild = 6, - kFlexMeasure = 7, - COUNT -}; - -struct LayoutData { - int layouts; - int measures; - uint32_t maxMeasureCache; - int cachedLayouts; - int cachedMeasures; - int measureCallbacks; - std::array(LayoutPassReason::COUNT)> - measureCallbackReasonsCount; -}; - -const char* LayoutPassReasonToString(const LayoutPassReason value); - -struct YG_EXPORT Event { - enum Type { - NodeAllocation, - NodeDeallocation, - NodeLayout, - LayoutPassStart, - LayoutPassEnd, - MeasureCallbackStart, - MeasureCallbackEnd, - NodeBaselineStart, - NodeBaselineEnd, - }; - class Data; - using Subscriber = void(YGNodeConstRef, Type, Data); - using Subscribers = std::vector>; - - template - struct TypedData {}; - - class Data { - const void* data_; - - public: - template - Data(const TypedData& data) : data_{&data} {} - - template - const TypedData& get() const { - return *static_cast*>(data_); - } - }; - - static void reset(); - - static void subscribe(std::function&& subscriber); - - template - static void publish(YGNodeConstRef node, const TypedData& eventData = {}) { - publish(node, E, Data{eventData}); - } - - private: - static void publish(YGNodeConstRef, Type, const Data&); -}; - -template <> -struct Event::TypedData { - YGConfigConstRef config; -}; - -template <> -struct Event::TypedData { - YGConfigConstRef config; -}; - -template <> -struct Event::TypedData { - LayoutData* layoutData; -}; - -template <> -struct Event::TypedData { - float width; - YGMeasureMode widthMeasureMode; - float height; - YGMeasureMode heightMeasureMode; - float measuredWidth; - float measuredHeight; - const LayoutPassReason reason; -}; - -template <> -struct Event::TypedData { - LayoutType layoutType; -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Node_CachedMeasurement.h b/Sources/yoga/Node_CachedMeasurement.h deleted file mode 100644 index 1896f373..00000000 --- a/Sources/yoga/Node_CachedMeasurement.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Yoga.h" - -#include "Algorithm_SizingMode.h" -#include "Numeric_Comparison.h" - -namespace facebook::yoga { - -struct CachedMeasurement { - float availableWidth{-1}; - float availableHeight{-1}; - SizingMode widthSizingMode{SizingMode::MaxContent}; - SizingMode heightSizingMode{SizingMode::MaxContent}; - - float computedWidth{-1}; - float computedHeight{-1}; - - bool operator==(CachedMeasurement measurement) const { - bool isEqual = widthSizingMode == measurement.widthSizingMode && - heightSizingMode == measurement.heightSizingMode; - - if (!yoga::isUndefined(availableWidth) || - !yoga::isUndefined(measurement.availableWidth)) { - isEqual = isEqual && availableWidth == measurement.availableWidth; - } - if (!yoga::isUndefined(availableHeight) || - !yoga::isUndefined(measurement.availableHeight)) { - isEqual = isEqual && availableHeight == measurement.availableHeight; - } - if (!yoga::isUndefined(computedWidth) || - !yoga::isUndefined(measurement.computedWidth)) { - isEqual = isEqual && computedWidth == measurement.computedWidth; - } - if (!yoga::isUndefined(computedHeight) || - !yoga::isUndefined(measurement.computedHeight)) { - isEqual = isEqual && computedHeight == measurement.computedHeight; - } - - return isEqual; - } -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Node_LayoutResults.cpp b/Sources/yoga/Node_LayoutResults.cpp deleted file mode 100644 index a7609642..00000000 --- a/Sources/yoga/Node_LayoutResults.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include - -#include "Node_LayoutResults.h" -#include "Numeric_Comparison.h" - -namespace facebook::yoga { - -bool LayoutResults::operator==(LayoutResults layout) const { - bool isEqual = yoga::inexactEquals(position_, layout.position_) && - yoga::inexactEquals(dimensions_, layout.dimensions_) && - yoga::inexactEquals(margin_, layout.margin_) && - yoga::inexactEquals(border_, layout.border_) && - yoga::inexactEquals(padding_, layout.padding_) && - direction() == layout.direction() && - hadOverflow() == layout.hadOverflow() && - lastOwnerDirection == layout.lastOwnerDirection && - nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex && - cachedLayout == layout.cachedLayout && - computedFlexBasis == layout.computedFlexBasis; - - for (uint32_t i = 0; i < LayoutResults::MaxCachedMeasurements && isEqual; - ++i) { - isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i]; - } - - if (!yoga::isUndefined(measuredDimensions_[0]) || - !yoga::isUndefined(layout.measuredDimensions_[0])) { - isEqual = - isEqual && (measuredDimensions_[0] == layout.measuredDimensions_[0]); - } - if (!yoga::isUndefined(measuredDimensions_[1]) || - !yoga::isUndefined(layout.measuredDimensions_[1])) { - isEqual = - isEqual && (measuredDimensions_[1] == layout.measuredDimensions_[1]); - } - - return isEqual; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Node_LayoutResults.h b/Sources/yoga/Node_LayoutResults.h deleted file mode 100644 index ca39077e..00000000 --- a/Sources/yoga/Node_LayoutResults.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Debug_AssertFatal.h" -#include "Enums_Dimension.h" -#include "Enums_Direction.h" -#include "Enums_Edge.h" -#include "Enums_PhysicalEdge.h" -#include "Node_CachedMeasurement.h" -#include "Numeric_FloatOptional.h" - -namespace facebook::yoga { - -struct LayoutResults { - // This value was chosen based on empirical data: - // 98% of analyzed layouts require less than 8 entries. - static constexpr int32_t MaxCachedMeasurements = 8; - - uint32_t computedFlexBasisGeneration = 0; - FloatOptional computedFlexBasis = {}; - - // Instead of recomputing the entire layout every single time, we cache some - // information to break early when nothing changed - uint32_t generationCount = 0; - Direction lastOwnerDirection = Direction::Inherit; - - uint32_t nextCachedMeasurementsIndex = 0; - std::array cachedMeasurements = {}; - - CachedMeasurement cachedLayout{}; - - Direction direction() const { - return direction_; - } - - void setDirection(Direction direction) { - direction_ = direction; - } - - bool hadOverflow() const { - return hadOverflow_; - } - - void setHadOverflow(bool hadOverflow) { - hadOverflow_ = hadOverflow; - } - - float dimension(Dimension axis) const { - return dimensions_[yoga::to_underlying(axis)]; - } - - void setDimension(Dimension axis, float dimension) { - dimensions_[yoga::to_underlying(axis)] = dimension; - } - - float measuredDimension(Dimension axis) const { - return measuredDimensions_[yoga::to_underlying(axis)]; - } - - void setMeasuredDimension(Dimension axis, float dimension) { - measuredDimensions_[yoga::to_underlying(axis)] = dimension; - } - - float position(PhysicalEdge physicalEdge) const { - return position_[yoga::to_underlying(physicalEdge)]; - } - - void setPosition(PhysicalEdge physicalEdge, float dimension) { - position_[yoga::to_underlying(physicalEdge)] = dimension; - } - - float margin(PhysicalEdge physicalEdge) const { - return margin_[yoga::to_underlying(physicalEdge)]; - } - - void setMargin(PhysicalEdge physicalEdge, float dimension) { - margin_[yoga::to_underlying(physicalEdge)] = dimension; - } - - float border(PhysicalEdge physicalEdge) const { - return border_[yoga::to_underlying(physicalEdge)]; - } - - void setBorder(PhysicalEdge physicalEdge, float dimension) { - border_[yoga::to_underlying(physicalEdge)] = dimension; - } - - float padding(PhysicalEdge physicalEdge) const { - return padding_[yoga::to_underlying(physicalEdge)]; - } - - void setPadding(PhysicalEdge physicalEdge, float dimension) { - padding_[yoga::to_underlying(physicalEdge)] = dimension; - } - - bool operator==(LayoutResults layout) const; - bool operator!=(LayoutResults layout) const { - return !(*this == layout); - } - - private: - Direction direction_ : bitCount() = Direction::Inherit; - bool hadOverflow_ : 1 = false; - - std::array dimensions_ = {{YGUndefined, YGUndefined}}; - std::array measuredDimensions_ = {{YGUndefined, YGUndefined}}; - std::array position_ = {}; - std::array margin_ = {}; - std::array border_ = {}; - std::array padding_ = {}; -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Node_Node.cpp b/Sources/yoga/Node_Node.cpp deleted file mode 100644 index c89930e4..00000000 --- a/Sources/yoga/Node_Node.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -#include "Debug_AssertFatal.h" -#include "Node_Node.h" -#include "Numeric_Comparison.h" - -namespace facebook::yoga { - -Node::Node() : Node{&Config::getDefault()} {} - -Node::Node(const yoga::Config* config) : config_{config} { - yoga::assertFatal( - config != nullptr, "Attempting to construct Node with null config"); - - if (config->useWebDefaults()) { - useWebDefaults(); - } -} - -Node::Node(Node&& node) { - hasNewLayout_ = node.hasNewLayout_; - isReferenceBaseline_ = node.isReferenceBaseline_; - isDirty_ = node.isDirty_; - alwaysFormsContainingBlock_ = node.alwaysFormsContainingBlock_; - nodeType_ = node.nodeType_; - context_ = node.context_; - measureFunc_ = node.measureFunc_; - baselineFunc_ = node.baselineFunc_; - dirtiedFunc_ = node.dirtiedFunc_; - style_ = node.style_; - layout_ = node.layout_; - lineIndex_ = node.lineIndex_; - owner_ = node.owner_; - children_ = std::move(node.children_); - config_ = node.config_; - resolvedDimensions_ = node.resolvedDimensions_; - for (auto c : children_) { - c->setOwner(this); - } -} - -YGSize Node::measure( - float width, - MeasureMode widthMode, - float height, - MeasureMode heightMode) { - return measureFunc_( - this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode)); -} - -float Node::baseline(float width, float height) const { - return baselineFunc_(this, width, height); -} - -float Node::dimensionWithMargin( - const FlexDirection axis, - const float widthSize) { - return getLayout().measuredDimension(dimension(axis)) + - style_.computeMarginForAxis(axis, widthSize); -} - -bool Node::isLayoutDimensionDefined(const FlexDirection axis) { - const float value = getLayout().measuredDimension(dimension(axis)); - return yoga::isDefined(value) && value >= 0.0f; -} - -// Setters - -void Node::setMeasureFunc(YGMeasureFunc measureFunc) { - if (measureFunc == nullptr) { - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate - // places in Litho - setNodeType(NodeType::Default); - } else { - yoga::assertFatalWithNode( - this, - children_.size() == 0, - "Cannot set measure function: Nodes with measure functions cannot have " - "children."); - // TODO: t18095186 Move nodeType to opt-in function and mark appropriate - // places in Litho - setNodeType(NodeType::Text); - } - - measureFunc_ = measureFunc; -} - -void Node::replaceChild(Node* child, size_t index) { - children_[index] = child; -} - -void Node::replaceChild(Node* oldChild, Node* newChild) { - std::replace(children_.begin(), children_.end(), oldChild, newChild); -} - -void Node::insertChild(Node* child, size_t index) { - children_.insert(children_.begin() + static_cast(index), child); -} - -void Node::setConfig(yoga::Config* config) { - yoga::assertFatal( - config != nullptr, "Attempting to set a null config on a Node"); - yoga::assertFatalWithConfig( - config, - config->useWebDefaults() == config_->useWebDefaults(), - "UseWebDefaults may not be changed after constructing a Node"); - - if (yoga::configUpdateInvalidatesLayout(*config_, *config)) { - markDirtyAndPropagate(); - } - - config_ = config; -} - -void Node::setDirty(bool isDirty) { - if (isDirty == isDirty_) { - return; - } - isDirty_ = isDirty; - if (isDirty && dirtiedFunc_) { - dirtiedFunc_(this); - } -} - -bool Node::removeChild(Node* child) { - std::vector::iterator p = - std::find(children_.begin(), children_.end(), child); - if (p != children_.end()) { - children_.erase(p); - return true; - } - return false; -} - -void Node::removeChild(size_t index) { - children_.erase(children_.begin() + static_cast(index)); -} - -void Node::setLayoutDirection(Direction direction) { - layout_.setDirection(direction); -} - -void Node::setLayoutMargin(float margin, PhysicalEdge edge) { - layout_.setMargin(edge, margin); -} - -void Node::setLayoutBorder(float border, PhysicalEdge edge) { - layout_.setBorder(edge, border); -} - -void Node::setLayoutPadding(float padding, PhysicalEdge edge) { - layout_.setPadding(edge, padding); -} - -void Node::setLayoutLastOwnerDirection(Direction direction) { - layout_.lastOwnerDirection = direction; -} - -void Node::setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis) { - layout_.computedFlexBasis = computedFlexBasis; -} - -void Node::setLayoutPosition(float position, PhysicalEdge edge) { - layout_.setPosition(edge, position); -} - -void Node::setLayoutComputedFlexBasisGeneration( - uint32_t computedFlexBasisGeneration) { - layout_.computedFlexBasisGeneration = computedFlexBasisGeneration; -} - -void Node::setLayoutMeasuredDimension( - float measuredDimension, - Dimension dimension) { - layout_.setMeasuredDimension(dimension, measuredDimension); -} - -void Node::setLayoutHadOverflow(bool hadOverflow) { - layout_.setHadOverflow(hadOverflow); -} - -void Node::setLayoutDimension(float LengthValue, Dimension dimension) { - layout_.setDimension(dimension, LengthValue); -} - -// If both left and right are defined, then use left. Otherwise return +left or -// -right depending on which is defined. Ignore statically positioned nodes as -// insets do not apply to them. -float Node::relativePosition( - FlexDirection axis, - Direction direction, - float axisSize) const { - if (style_.positionType() == PositionType::Static) { - return 0; - } - if (style_.isInlineStartPositionDefined(axis, direction)) { - return style_.computeInlineStartPosition(axis, direction, axisSize); - } - - return -1 * style_.computeInlineEndPosition(axis, direction, axisSize); -} - -void Node::setPosition( - const Direction direction, - const float mainSize, - const float crossSize, - const float ownerWidth) { - /* Root nodes should be always layouted as LTR, so we don't return negative - * values. */ - const Direction directionRespectingRoot = - owner_ != nullptr ? direction : Direction::LTR; - const FlexDirection mainAxis = - yoga::resolveDirection(style_.flexDirection(), directionRespectingRoot); - const FlexDirection crossAxis = - yoga::resolveCrossDirection(mainAxis, directionRespectingRoot); - - // In the case of position static these are just 0. See: - // https://www.w3.org/TR/css-position-3/#valdef-position-static - const float relativePositionMain = - relativePosition(mainAxis, directionRespectingRoot, mainSize); - const float relativePositionCross = - relativePosition(crossAxis, directionRespectingRoot, crossSize); - - const auto mainAxisLeadingEdge = inlineStartEdge(mainAxis, direction); - const auto mainAxisTrailingEdge = inlineEndEdge(mainAxis, direction); - const auto crossAxisLeadingEdge = inlineStartEdge(crossAxis, direction); - const auto crossAxisTrailingEdge = inlineEndEdge(crossAxis, direction); - - setLayoutPosition( - (style_.computeInlineStartMargin(mainAxis, direction, ownerWidth) + - relativePositionMain), - mainAxisLeadingEdge); - setLayoutPosition( - (style_.computeInlineEndMargin(mainAxis, direction, ownerWidth) + - relativePositionMain), - mainAxisTrailingEdge); - setLayoutPosition( - (style_.computeInlineStartMargin(crossAxis, direction, ownerWidth) + - relativePositionCross), - crossAxisLeadingEdge); - setLayoutPosition( - (style_.computeInlineEndMargin(crossAxis, direction, ownerWidth) + - relativePositionCross), - crossAxisTrailingEdge); -} - -Style::Length Node::resolveFlexBasisPtr() const { - Style::Length flexBasis = style_.flexBasis(); - if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) { - return flexBasis; - } - if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) { - return config_->useWebDefaults() ? value::ofAuto() : value::points(0); - } - return value::ofAuto(); -} - -void Node::resolveDimension() { - for (auto dim : {Dimension::Width, Dimension::Height}) { - if (style_.maxDimension(dim).isDefined() && - yoga::inexactEquals( - style_.maxDimension(dim), style_.minDimension(dim))) { - resolvedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim); - } else { - resolvedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim); - } - } -} - -Direction Node::resolveDirection(const Direction ownerDirection) { - if (style_.direction() == Direction::Inherit) { - return ownerDirection != Direction::Inherit ? ownerDirection - : Direction::LTR; - } else { - return style_.direction(); - } -} - -void Node::clearChildren() { - children_.clear(); - children_.shrink_to_fit(); -} - -// Other Methods - -void Node::cloneChildrenIfNeeded() { - size_t i = 0; - for (Node*& child : children_) { - if (child->getOwner() != this) { - child = resolveRef(config_->cloneNode(child, this, i)); - child->setOwner(this); - } - i += 1; - } -} - -void Node::markDirtyAndPropagate() { - if (!isDirty_) { - setDirty(true); - setLayoutComputedFlexBasis(FloatOptional()); - if (owner_) { - owner_->markDirtyAndPropagate(); - } - } -} - -float Node::resolveFlexGrow() const { - // Root nodes flexGrow should always be 0 - if (owner_ == nullptr) { - return 0.0; - } - if (style_.flexGrow().isDefined()) { - return style_.flexGrow().unwrap(); - } - if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) { - return style_.flex().unwrap(); - } - return Style::DefaultFlexGrow; -} - -float Node::resolveFlexShrink() const { - if (owner_ == nullptr) { - return 0.0; - } - if (style_.flexShrink().isDefined()) { - return style_.flexShrink().unwrap(); - } - if (!config_->useWebDefaults() && style_.flex().isDefined() && - style_.flex().unwrap() < 0.0f) { - return -style_.flex().unwrap(); - } - return config_->useWebDefaults() ? Style::WebDefaultFlexShrink - : Style::DefaultFlexShrink; -} - -bool Node::isNodeFlexible() { - return ( - (style_.positionType() != PositionType::Absolute) && - (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); -} - -void Node::reset() { - yoga::assertFatalWithNode( - this, - children_.size() == 0, - "Cannot reset a node which still has children attached"); - yoga::assertFatalWithNode( - this, owner_ == nullptr, "Cannot reset a node still attached to a owner"); - - *this = Node{getConfig()}; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Node_Node.h b/Sources/yoga/Node_Node.h deleted file mode 100644 index 5daa5954..00000000 --- a/Sources/yoga/Node_Node.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "Yoga.h" - -#include "Config_Config.h" -#include "Enums_Dimension.h" -#include "Enums_Direction.h" -#include "Enums_Edge.h" -#include "Enums_Errata.h" -#include "Enums_MeasureMode.h" -#include "Enums_NodeType.h" -#include "Enums_PhysicalEdge.h" -#include "Node_LayoutResults.h" -#include "Style_Style.h" - -// Tag struct used to form the opaque YGNodeRef for the public C API -struct YGNode {}; - -namespace facebook::yoga { - -class YG_EXPORT Node : public ::YGNode { - public: - Node(); - explicit Node(const Config* config); - - Node(Node&&); - - // Does not expose true value semantics, as children are not cloned eagerly. - // Should we remove this? - Node(const Node& node) = default; - - // assignment means potential leaks of existing children, or alternatively - // freeing unowned memory, double free, or freeing stack memory. - Node& operator=(const Node&) = delete; - - // Getters - void* getContext() const { - return context_; - } - - bool alwaysFormsContainingBlock() const { - return alwaysFormsContainingBlock_; - } - - bool getHasNewLayout() const { - return hasNewLayout_; - } - - NodeType getNodeType() const { - return nodeType_; - } - - bool hasMeasureFunc() const noexcept { - return measureFunc_ != nullptr; - } - - YGSize measure(float, MeasureMode, float, MeasureMode); - - bool hasBaselineFunc() const noexcept { - return baselineFunc_ != nullptr; - } - - float baseline(float width, float height) const; - - float dimensionWithMargin(const FlexDirection axis, const float widthSize); - - bool isLayoutDimensionDefined(const FlexDirection axis); - - /** - * Whether the node has a "definite length" along the given axis. - * https://www.w3.org/TR/css-sizing-3/#definite - */ - inline bool hasDefiniteLength(Dimension dimension, float ownerSize) { - auto usedValue = getResolvedDimension(dimension).resolve(ownerSize); - return usedValue.isDefined() && usedValue.unwrap() >= 0.0f; - } - - bool hasErrata(Errata errata) const { - return config_->hasErrata(errata); - } - - YGDirtiedFunc getDirtiedFunc() const { - return dirtiedFunc_; - } - - // For Performance reasons passing as reference. - Style& style() { - return style_; - } - - const Style& style() const { - return style_; - } - - // For Performance reasons passing as reference. - LayoutResults& getLayout() { - return layout_; - } - - const LayoutResults& getLayout() const { - return layout_; - } - - size_t getLineIndex() const { - return lineIndex_; - } - - bool isReferenceBaseline() const { - return isReferenceBaseline_; - } - - // returns the Node that owns this Node. An owner is used to identify - // the YogaTree that a Node belongs to. This method will return the parent - // of the Node when a Node only belongs to one YogaTree or nullptr when - // the Node is shared between two or more YogaTrees. - Node* getOwner() const { - return owner_; - } - - const std::vector& getChildren() const { - return children_; - } - - Node* getChild(size_t index) const { - return children_.at(index); - } - - size_t getChildCount() const { - return children_.size(); - } - - const Config* getConfig() const { - return config_; - } - - bool isDirty() const { - return isDirty_; - } - - std::array getResolvedDimensions() const { - return resolvedDimensions_; - } - - Style::Length getResolvedDimension(Dimension dimension) const { - return resolvedDimensions_[static_cast(dimension)]; - } - - // Setters - - void setContext(void* context) { - context_ = context; - } - - void setAlwaysFormsContainingBlock(bool alwaysFormsContainingBlock) { - alwaysFormsContainingBlock_ = alwaysFormsContainingBlock; - } - - void setHasNewLayout(bool hasNewLayout) { - hasNewLayout_ = hasNewLayout; - } - - void setNodeType(NodeType nodeType) { - nodeType_ = nodeType; - } - - void setMeasureFunc(YGMeasureFunc measureFunc); - - void setBaselineFunc(YGBaselineFunc baseLineFunc) { - baselineFunc_ = baseLineFunc; - } - - void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { - dirtiedFunc_ = dirtiedFunc; - } - - void setStyle(const Style& style) { - style_ = style; - } - - void setLayout(const LayoutResults& layout) { - layout_ = layout; - } - - void setLineIndex(size_t lineIndex) { - lineIndex_ = lineIndex; - } - - void setIsReferenceBaseline(bool isReferenceBaseline) { - isReferenceBaseline_ = isReferenceBaseline; - } - - void setOwner(Node* owner) { - owner_ = owner; - } - - void setChildren(const std::vector& children) { - children_ = children; - } - - // TODO: rvalue override for setChildren - - void setConfig(Config* config); - - void setDirty(bool isDirty); - void setLayoutLastOwnerDirection(Direction direction); - void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis); - void setLayoutComputedFlexBasisGeneration( - uint32_t computedFlexBasisGeneration); - void setLayoutMeasuredDimension(float measuredDimension, Dimension dimension); - void setLayoutHadOverflow(bool hadOverflow); - void setLayoutDimension(float LengthValue, Dimension dimension); - void setLayoutDirection(Direction direction); - void setLayoutMargin(float margin, PhysicalEdge edge); - void setLayoutBorder(float border, PhysicalEdge edge); - void setLayoutPadding(float padding, PhysicalEdge edge); - void setLayoutPosition(float position, PhysicalEdge edge); - void setPosition( - const Direction direction, - const float mainSize, - const float crossSize, - const float ownerWidth); - - // Other methods - Style::Length resolveFlexBasisPtr() const; - void resolveDimension(); - Direction resolveDirection(const Direction ownerDirection); - void clearChildren(); - /// Replaces the occurrences of oldChild with newChild - void replaceChild(Node* oldChild, Node* newChild); - void replaceChild(Node* child, size_t index); - void insertChild(Node* child, size_t index); - /// Removes the first occurrence of child - bool removeChild(Node* child); - void removeChild(size_t index); - - void cloneChildrenIfNeeded(); - void markDirtyAndPropagate(); - float resolveFlexGrow() const; - float resolveFlexShrink() const; - bool isNodeFlexible(); - void reset(); - - private: - // Used to allow resetting the node - Node& operator=(Node&&) = default; - - float relativePosition( - FlexDirection axis, - Direction direction, - const float axisSize) const; - - void useWebDefaults() { - style_.setFlexDirection(FlexDirection::Row); - style_.setAlignContent(Align::Stretch); - } - - bool hasNewLayout_ : 1 = true; - bool isReferenceBaseline_ : 1 = false; - bool isDirty_ : 1 = false; - bool alwaysFormsContainingBlock_ : 1 = false; - NodeType nodeType_ : bitCount() = NodeType::Default; - void* context_ = nullptr; - YGMeasureFunc measureFunc_ = nullptr; - YGBaselineFunc baselineFunc_ = nullptr; - YGDirtiedFunc dirtiedFunc_ = nullptr; - Style style_; - LayoutResults layout_; - size_t lineIndex_ = 0; - Node* owner_ = nullptr; - std::vector children_; - const Config* config_; - std::array resolvedDimensions_{ - {value::undefined(), value::undefined()}}; -}; - -inline Node* resolveRef(const YGNodeRef ref) { - return static_cast(ref); -} - -inline const Node* resolveRef(const YGNodeConstRef ref) { - return static_cast(ref); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Numeric_Comparison.h b/Sources/yoga/Numeric_Comparison.h deleted file mode 100644 index f31c6481..00000000 --- a/Sources/yoga/Numeric_Comparison.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -#include "Yoga.h" - -namespace facebook::yoga { - -constexpr bool isUndefined(std::floating_point auto value) { - return value != value; -} - -constexpr bool isDefined(std::floating_point auto value) { - return !isUndefined(value); -} - -/** - * Constexpr version of `std::isinf` before C++ 23 - */ -constexpr bool isinf(auto value) { - return value == +std::numeric_limits::infinity() || - value == -std::numeric_limits::infinity(); -} - -constexpr auto maxOrDefined( - std::floating_point auto a, - std::floating_point auto b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::max(a, b); - } - return yoga::isUndefined(a) ? b : a; -} - -constexpr auto minOrDefined( - std::floating_point auto a, - std::floating_point auto b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::min(a, b); - } - - return yoga::isUndefined(a) ? b : a; -} - -// Custom equality functions using a hardcoded epsilon of 0.0001f, or returning -// true if both floats are NaN. -inline bool inexactEquals(float a, float b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::abs(a - b) < 0.0001f; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -inline bool inexactEquals(double a, double b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::abs(a - b) < 0.0001; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -template -bool inexactEquals( - const std::array& val1, - const std::array& val2) { - bool areEqual = true; - for (std::size_t i = 0; i < Size && areEqual; ++i) { - areEqual = inexactEquals(val1[i], val2[i]); - } - return areEqual; -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Numeric_FloatOptional.h b/Sources/yoga/Numeric_FloatOptional.h deleted file mode 100644 index e3a51a13..00000000 --- a/Sources/yoga/Numeric_FloatOptional.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Numeric_Comparison.h" -#include - -namespace facebook::yoga { - -struct FloatOptional { - private: - float value_ = std::numeric_limits::quiet_NaN(); - - public: - explicit constexpr FloatOptional(float value) : value_(value) {} - constexpr FloatOptional() = default; - - // returns the wrapped value, or a value x with YGIsUndefined(x) == true - constexpr float unwrap() const { - return value_; - } - - constexpr float unwrapOrDefault(float defaultValue) const { - return isUndefined() ? defaultValue : value_; - } - - constexpr bool isUndefined() const { - return yoga::isUndefined(value_); - } - - constexpr bool isDefined() const { - return yoga::isDefined(value_); - } -}; - -// operators take FloatOptional by value, as it is a 32bit value - -constexpr bool operator==(FloatOptional lhs, FloatOptional rhs) { - return lhs.unwrap() == rhs.unwrap() || - (lhs.isUndefined() && rhs.isUndefined()); -} -constexpr bool operator!=(FloatOptional lhs, FloatOptional rhs) { - return !(lhs == rhs); -} - -constexpr bool operator==(FloatOptional lhs, float rhs) { - return lhs == FloatOptional{rhs}; -} -constexpr bool operator!=(FloatOptional lhs, float rhs) { - return !(lhs == rhs); -} - -constexpr bool operator==(float lhs, FloatOptional rhs) { - return rhs == lhs; -} -constexpr bool operator!=(float lhs, FloatOptional rhs) { - return !(lhs == rhs); -} - -constexpr FloatOptional operator+(FloatOptional lhs, FloatOptional rhs) { - return FloatOptional{lhs.unwrap() + rhs.unwrap()}; -} - -constexpr bool operator>(FloatOptional lhs, FloatOptional rhs) { - return lhs.unwrap() > rhs.unwrap(); -} - -constexpr bool operator<(FloatOptional lhs, FloatOptional rhs) { - return lhs.unwrap() < rhs.unwrap(); -} - -constexpr bool operator>=(FloatOptional lhs, FloatOptional rhs) { - return lhs > rhs || lhs == rhs; -} - -constexpr bool operator<=(FloatOptional lhs, FloatOptional rhs) { - return lhs < rhs || lhs == rhs; -} - -constexpr FloatOptional maxOrDefined(FloatOptional lhs, FloatOptional rhs) { - return FloatOptional{yoga::maxOrDefined(lhs.unwrap(), rhs.unwrap())}; -} - -inline bool inexactEquals(FloatOptional lhs, FloatOptional rhs) { - return yoga::inexactEquals(lhs.unwrap(), rhs.unwrap()); -} - -} // namespace facebook::yoga diff --git a/Sources/yoga/Style_SmallValueBuffer.h b/Sources/yoga/Style_SmallValueBuffer.h deleted file mode 100644 index 2860a420..00000000 --- a/Sources/yoga/Style_SmallValueBuffer.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace facebook::yoga { - -// Container which allows storing 32 or 64 bit integer values, whose index may -// never change. Values are first stored in a fixed buffer of `BufferSize` -// 32-bit chunks, before falling back to heap allocation. -template -class SmallValueBuffer { - public: - SmallValueBuffer() = default; - SmallValueBuffer(const SmallValueBuffer& other) { - *this = other; - } - SmallValueBuffer(SmallValueBuffer&& other) = default; - - // Add a new element to the buffer, returning the index of the element - uint16_t push(uint32_t value) { - const auto index = count_++; - assert(index < 4096 && "SmallValueBuffer can only hold up to 4096 chunks"); - if (index < buffer_.size()) { - buffer_[index] = value; - return index; - } - - if (overflow_ == nullptr) { - overflow_ = std::make_unique(); - } - - overflow_->buffer_.push_back(value); - overflow_->wideElements_.push_back(false); - return index; - } - - uint16_t push(uint64_t value) { - const auto lsb = static_cast(value & 0xFFFFFFFF); - const auto msb = static_cast(value >> 32); - - const auto lsbIndex = push(lsb); - [[maybe_unused]] const auto msbIndex = push(msb); - assert( - msbIndex < 4096 && "SmallValueBuffer can only hold up to 4096 chunks"); - - if (lsbIndex < buffer_.size()) { - wideElements_[lsbIndex] = true; - } else { - overflow_->wideElements_[lsbIndex - buffer_.size()] = true; - } - return lsbIndex; - } - - // Replace an existing element in the buffer with a new value. A new index - // may be returned, e.g. if a new value is wider than the previous. - [[nodiscard]] uint16_t replace(uint16_t index, uint32_t value) { - if (index < buffer_.size()) { - buffer_[index] = value; - } else { - overflow_->buffer_.at(index - buffer_.size()) = value; - } - - return index; - } - - [[nodiscard]] uint16_t replace(uint16_t index, uint64_t value) { - const bool isWide = index < wideElements_.size() - ? wideElements_[index] - : overflow_->wideElements_.at(index - buffer_.size()); - - if (isWide) { - const auto lsb = static_cast(value & 0xFFFFFFFF); - const auto msb = static_cast(value >> 32); - - [[maybe_unused]] auto lsbIndex = replace(index, lsb); - [[maybe_unused]] auto msbIndex = replace(index + 1, msb); - return index; - } else { - return push(value); - } - } - - // Get a value of a given width - uint32_t get32(uint16_t index) const { - if (index < buffer_.size()) { - return buffer_[index]; - } else { - return overflow_->buffer_.at(index - buffer_.size()); - } - } - - uint64_t get64(uint16_t index) const { - const auto lsb = get32(index); - const auto msb = get32(index + 1); - return (static_cast(msb) << 32) | lsb; - } - - SmallValueBuffer& operator=(const SmallValueBuffer& other) { - count_ = other.count_; - buffer_ = other.buffer_; - wideElements_ = other.wideElements_; - overflow_ = other.overflow_ ? std::make_unique(*other.overflow_) - : nullptr; - return *this; - } - - SmallValueBuffer& operator=(SmallValueBuffer&& other) = default; - - private: - struct Overflow { - std::vector buffer_; - std::vector wideElements_; - }; - - uint16_t count_{0}; - std::array buffer_; - std::bitset wideElements_; - std::unique_ptr overflow_; -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Style_Style.h b/Sources/yoga/Style_Style.h deleted file mode 100644 index a18967b2..00000000 --- a/Sources/yoga/Style_Style.h +++ /dev/null @@ -1,678 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "Yoga.h" - -#include "Algorithm_FlexDirection.h" -#include "Enums_Align.h" -#include "Enums_Dimension.h" -#include "Enums_Direction.h" -#include "Enums_Display.h" -#include "Enums_Edge.h" -#include "Enums_FlexDirection.h" -#include "Enums_Gutter.h" -#include "Enums_Justify.h" -#include "Enums_Overflow.h" -#include "Enums_PhysicalEdge.h" -#include "Enums_PositionType.h" -#include "Enums_Unit.h" -#include "Enums_Wrap.h" -#include "Numeric_FloatOptional.h" -#include "Style_StyleLength.h" -#include "Style_StyleValuePool.h" - -namespace facebook::yoga { - -class YG_EXPORT Style { - public: - using Length = StyleLength; - - static constexpr float DefaultFlexGrow = 0.0f; - static constexpr float DefaultFlexShrink = 0.0f; - static constexpr float WebDefaultFlexShrink = 1.0f; - - Direction direction() const { - return direction_; - } - void setDirection(Direction value) { - direction_ = value; - } - - FlexDirection flexDirection() const { - return flexDirection_; - } - void setFlexDirection(FlexDirection value) { - flexDirection_ = value; - } - - Justify justifyContent() const { - return justifyContent_; - } - void setJustifyContent(Justify value) { - justifyContent_ = value; - } - - Align alignContent() const { - return alignContent_; - } - void setAlignContent(Align value) { - alignContent_ = value; - } - - Align alignItems() const { - return alignItems_; - } - void setAlignItems(Align value) { - alignItems_ = value; - } - - Align alignSelf() const { - return alignSelf_; - } - void setAlignSelf(Align value) { - alignSelf_ = value; - } - - PositionType positionType() const { - return positionType_; - } - void setPositionType(PositionType value) { - positionType_ = value; - } - - Wrap flexWrap() const { - return flexWrap_; - } - void setFlexWrap(Wrap value) { - flexWrap_ = value; - } - - Overflow overflow() const { - return overflow_; - } - void setOverflow(Overflow value) { - overflow_ = value; - } - - Display display() const { - return display_; - } - void setDisplay(Display value) { - display_ = value; - } - - FloatOptional flex() const { - return pool_.getNumber(flex_); - } - void setFlex(FloatOptional value) { - pool_.store(flex_, value); - } - - FloatOptional flexGrow() const { - return pool_.getNumber(flexGrow_); - } - void setFlexGrow(FloatOptional value) { - pool_.store(flexGrow_, value); - } - - FloatOptional flexShrink() const { - return pool_.getNumber(flexShrink_); - } - void setFlexShrink(FloatOptional value) { - pool_.store(flexShrink_, value); - } - - Style::Length flexBasis() const { - return pool_.getLength(flexBasis_); - } - void setFlexBasis(Style::Length value) { - pool_.store(flexBasis_, value); - } - - Style::Length margin(Edge edge) const { - return pool_.getLength(margin_[yoga::to_underlying(edge)]); - } - void setMargin(Edge edge, Style::Length value) { - pool_.store(margin_[yoga::to_underlying(edge)], value); - } - - Style::Length position(Edge edge) const { - return pool_.getLength(position_[yoga::to_underlying(edge)]); - } - void setPosition(Edge edge, Style::Length value) { - pool_.store(position_[yoga::to_underlying(edge)], value); - } - - Style::Length padding(Edge edge) const { - return pool_.getLength(padding_[yoga::to_underlying(edge)]); - } - void setPadding(Edge edge, Style::Length value) { - pool_.store(padding_[yoga::to_underlying(edge)], value); - } - - Style::Length border(Edge edge) const { - return pool_.getLength(border_[yoga::to_underlying(edge)]); - } - void setBorder(Edge edge, Style::Length value) { - pool_.store(border_[yoga::to_underlying(edge)], value); - } - - Style::Length gap(Gutter gutter) const { - return pool_.getLength(gap_[yoga::to_underlying(gutter)]); - } - void setGap(Gutter gutter, Style::Length value) { - pool_.store(gap_[yoga::to_underlying(gutter)], value); - } - - Style::Length dimension(Dimension axis) const { - return pool_.getLength(dimensions_[yoga::to_underlying(axis)]); - } - void setDimension(Dimension axis, Style::Length value) { - pool_.store(dimensions_[yoga::to_underlying(axis)], value); - } - - Style::Length minDimension(Dimension axis) const { - return pool_.getLength(minDimensions_[yoga::to_underlying(axis)]); - } - void setMinDimension(Dimension axis, Style::Length value) { - pool_.store(minDimensions_[yoga::to_underlying(axis)], value); - } - - Style::Length maxDimension(Dimension axis) const { - return pool_.getLength(maxDimensions_[yoga::to_underlying(axis)]); - } - void setMaxDimension(Dimension axis, Style::Length value) { - pool_.store(maxDimensions_[yoga::to_underlying(axis)], value); - } - - FloatOptional aspectRatio() const { - return pool_.getNumber(aspectRatio_); - } - void setAspectRatio(FloatOptional value) { - pool_.store(aspectRatio_, value); - } - - bool horizontalInsetsDefined() const { - return position_[yoga::to_underlying(Edge::Left)].isDefined() || - position_[yoga::to_underlying(Edge::Right)].isDefined() || - position_[yoga::to_underlying(Edge::All)].isDefined() || - position_[yoga::to_underlying(Edge::Horizontal)].isDefined() || - position_[yoga::to_underlying(Edge::Start)].isDefined() || - position_[yoga::to_underlying(Edge::End)].isDefined(); - } - - bool verticalInsetsDefined() const { - return position_[yoga::to_underlying(Edge::Top)].isDefined() || - position_[yoga::to_underlying(Edge::Bottom)].isDefined() || - position_[yoga::to_underlying(Edge::All)].isDefined() || - position_[yoga::to_underlying(Edge::Vertical)].isDefined(); - } - - bool isFlexStartPositionDefined(FlexDirection axis, Direction direction) - const { - return computePosition(flexStartEdge(axis), direction).isDefined(); - } - - bool isInlineStartPositionDefined(FlexDirection axis, Direction direction) - const { - return computePosition(inlineStartEdge(axis, direction), direction) - .isDefined(); - } - - bool isFlexEndPositionDefined(FlexDirection axis, Direction direction) const { - return computePosition(flexEndEdge(axis), direction).isDefined(); - } - - bool isInlineEndPositionDefined(FlexDirection axis, Direction direction) - const { - return computePosition(inlineEndEdge(axis, direction), direction) - .isDefined(); - } - - float computeFlexStartPosition( - FlexDirection axis, - Direction direction, - float axisSize) const { - return computePosition(flexStartEdge(axis), direction) - .resolve(axisSize) - .unwrapOrDefault(0.0f); - } - - float computeInlineStartPosition( - FlexDirection axis, - Direction direction, - float axisSize) const { - return computePosition(inlineStartEdge(axis, direction), direction) - .resolve(axisSize) - .unwrapOrDefault(0.0f); - } - - float computeFlexEndPosition( - FlexDirection axis, - Direction direction, - float axisSize) const { - return computePosition(flexEndEdge(axis), direction) - .resolve(axisSize) - .unwrapOrDefault(0.0f); - } - - float computeInlineEndPosition( - FlexDirection axis, - Direction direction, - float axisSize) const { - return computePosition(inlineEndEdge(axis, direction), direction) - .resolve(axisSize) - .unwrapOrDefault(0.0f); - } - - float computeFlexStartMargin( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeMargin(flexStartEdge(axis), direction) - .resolve(widthSize) - .unwrapOrDefault(0.0f); - } - - float computeInlineStartMargin( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeMargin(inlineStartEdge(axis, direction), direction) - .resolve(widthSize) - .unwrapOrDefault(0.0f); - } - - float computeFlexEndMargin( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeMargin(flexEndEdge(axis), direction) - .resolve(widthSize) - .unwrapOrDefault(0.0f); - } - - float computeInlineEndMargin( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeMargin(inlineEndEdge(axis, direction), direction) - .resolve(widthSize) - .unwrapOrDefault(0.0f); - } - - float computeFlexStartBorder(FlexDirection axis, Direction direction) const { - return maxOrDefined( - computeBorder(flexStartEdge(axis), direction).resolve(0.0f).unwrap(), - 0.0f); - } - - float computeInlineStartBorder(FlexDirection axis, Direction direction) - const { - return maxOrDefined( - computeBorder(inlineStartEdge(axis, direction), direction) - .resolve(0.0f) - .unwrap(), - 0.0f); - } - - float computeFlexEndBorder(FlexDirection axis, Direction direction) const { - return maxOrDefined( - computeBorder(flexEndEdge(axis), direction).resolve(0.0f).unwrap(), - 0.0f); - } - - float computeInlineEndBorder(FlexDirection axis, Direction direction) const { - return maxOrDefined( - computeBorder(inlineEndEdge(axis, direction), direction) - .resolve(0.0f) - .unwrap(), - 0.0f); - } - - float computeFlexStartPadding( - FlexDirection axis, - Direction direction, - float widthSize) const { - return maxOrDefined( - computePadding(flexStartEdge(axis), direction) - .resolve(widthSize) - .unwrap(), - 0.0f); - } - - float computeInlineStartPadding( - FlexDirection axis, - Direction direction, - float widthSize) const { - return maxOrDefined( - computePadding(inlineStartEdge(axis, direction), direction) - .resolve(widthSize) - .unwrap(), - 0.0f); - } - - float computeFlexEndPadding( - FlexDirection axis, - Direction direction, - float widthSize) const { - return maxOrDefined( - computePadding(flexEndEdge(axis), direction) - .resolve(widthSize) - .unwrap(), - 0.0f); - } - - float computeInlineEndPadding( - FlexDirection axis, - Direction direction, - float widthSize) const { - return maxOrDefined( - computePadding(inlineEndEdge(axis, direction), direction) - .resolve(widthSize) - .unwrap(), - 0.0f); - } - - float computeInlineStartPaddingAndBorder( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeInlineStartPadding(axis, direction, widthSize) + - computeInlineStartBorder(axis, direction); - } - - float computeFlexStartPaddingAndBorder( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeFlexStartPadding(axis, direction, widthSize) + - computeFlexStartBorder(axis, direction); - } - - float computeInlineEndPaddingAndBorder( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeInlineEndPadding(axis, direction, widthSize) + - computeInlineEndBorder(axis, direction); - } - - float computeFlexEndPaddingAndBorder( - FlexDirection axis, - Direction direction, - float widthSize) const { - return computeFlexEndPadding(axis, direction, widthSize) + - computeFlexEndBorder(axis, direction); - } - - float computeBorderForAxis(FlexDirection axis) const { - return computeInlineStartBorder(axis, Direction::LTR) + - computeInlineEndBorder(axis, Direction::LTR); - } - - float computeMarginForAxis(FlexDirection axis, float widthSize) const { - // The total margin for a given axis does not depend on the direction - // so hardcoding LTR here to avoid piping direction to this function - return computeInlineStartMargin(axis, Direction::LTR, widthSize) + - computeInlineEndMargin(axis, Direction::LTR, widthSize); - } - - float computeGapForAxis(FlexDirection axis) const { - auto gap = isRow(axis) ? computeColumnGap() : computeRowGap(); - // TODO: Validate percentage gap, and expose ability to set percentage to - // public API - return maxOrDefined(gap.resolve(0.0f /*ownerSize*/).unwrap(), 0.0f); - } - - bool flexStartMarginIsAuto(FlexDirection axis, Direction direction) const { - return computeMargin(flexStartEdge(axis), direction).isAuto(); - } - - bool flexEndMarginIsAuto(FlexDirection axis, Direction direction) const { - return computeMargin(flexEndEdge(axis), direction).isAuto(); - } - - bool operator==(const Style& other) const { - return direction_ == other.direction_ && - flexDirection_ == other.flexDirection_ && - justifyContent_ == other.justifyContent_ && - alignContent_ == other.alignContent_ && - alignItems_ == other.alignItems_ && alignSelf_ == other.alignSelf_ && - positionType_ == other.positionType_ && flexWrap_ == other.flexWrap_ && - overflow_ == other.overflow_ && display_ == other.display_ && - numbersEqual(flex_, pool_, other.flex_, other.pool_) && - numbersEqual(flexGrow_, pool_, other.flexGrow_, other.pool_) && - numbersEqual(flexShrink_, pool_, other.flexShrink_, other.pool_) && - lengthsEqual(flexBasis_, pool_, other.flexBasis_, other.pool_) && - lengthsEqual(margin_, pool_, other.margin_, other.pool_) && - lengthsEqual(position_, pool_, other.position_, other.pool_) && - lengthsEqual(padding_, pool_, other.padding_, other.pool_) && - lengthsEqual(border_, pool_, other.border_, other.pool_) && - lengthsEqual(gap_, pool_, other.gap_, other.pool_) && - lengthsEqual(dimensions_, pool_, other.dimensions_, other.pool_) && - lengthsEqual( - minDimensions_, pool_, other.minDimensions_, other.pool_) && - lengthsEqual( - maxDimensions_, pool_, other.maxDimensions_, other.pool_) && - numbersEqual(aspectRatio_, pool_, other.aspectRatio_, other.pool_); - } - - bool operator!=(const Style& other) const { - return !(*this == other); - } - - private: - using Dimensions = std::array()>; - using Edges = std::array()>; - using Gutters = std::array()>; - - static inline bool numbersEqual( - const StyleValueHandle& lhsHandle, - const StyleValuePool& lhsPool, - const StyleValueHandle& rhsHandle, - const StyleValuePool& rhsPool) { - return (lhsHandle.isUndefined() && rhsHandle.isUndefined()) || - (lhsPool.getNumber(lhsHandle) == rhsPool.getNumber(rhsHandle)); - } - - static inline bool lengthsEqual( - const StyleValueHandle& lhsHandle, - const StyleValuePool& lhsPool, - const StyleValueHandle& rhsHandle, - const StyleValuePool& rhsPool) { - return (lhsHandle.isUndefined() && rhsHandle.isUndefined()) || - (lhsPool.getLength(lhsHandle) == rhsPool.getLength(rhsHandle)); - } - - template - static inline bool lengthsEqual( - const std::array& lhs, - const StyleValuePool& lhsPool, - const std::array& rhs, - const StyleValuePool& rhsPool) { - return std::equal( - lhs.begin(), - lhs.end(), - rhs.begin(), - rhs.end(), - [&](const auto& lhs, const auto& rhs) { - return lengthsEqual(lhs, lhsPool, rhs, rhsPool); - }); - } - - Style::Length computeColumnGap() const { - if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) { - return pool_.getLength(gap_[yoga::to_underlying(Gutter::Column)]); - } else { - return pool_.getLength(gap_[yoga::to_underlying(Gutter::All)]); - } - } - - Style::Length computeRowGap() const { - if (gap_[yoga::to_underlying(Gutter::Row)].isDefined()) { - return pool_.getLength(gap_[yoga::to_underlying(Gutter::Row)]); - } else { - return pool_.getLength(gap_[yoga::to_underlying(Gutter::All)]); - } - } - - Style::Length computeLeftEdge(const Edges& edges, Direction layoutDirection) - const { - if (layoutDirection == Direction::LTR && - edges[yoga::to_underlying(Edge::Start)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Start)]); - } else if ( - layoutDirection == Direction::RTL && - edges[yoga::to_underlying(Edge::End)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::End)]); - } else if (edges[yoga::to_underlying(Edge::Left)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Left)]); - } else if (edges[yoga::to_underlying(Edge::Horizontal)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Horizontal)]); - } else { - return pool_.getLength(edges[yoga::to_underlying(Edge::All)]); - } - } - - Style::Length computeTopEdge(const Edges& edges) const { - if (edges[yoga::to_underlying(Edge::Top)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Top)]); - } else if (edges[yoga::to_underlying(Edge::Vertical)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Vertical)]); - } else { - return pool_.getLength(edges[yoga::to_underlying(Edge::All)]); - } - } - - Style::Length computeRightEdge(const Edges& edges, Direction layoutDirection) - const { - if (layoutDirection == Direction::LTR && - edges[yoga::to_underlying(Edge::End)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::End)]); - } else if ( - layoutDirection == Direction::RTL && - edges[yoga::to_underlying(Edge::Start)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Start)]); - } else if (edges[yoga::to_underlying(Edge::Right)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Right)]); - } else if (edges[yoga::to_underlying(Edge::Horizontal)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Horizontal)]); - } else { - return pool_.getLength(edges[yoga::to_underlying(Edge::All)]); - } - } - - Style::Length computeBottomEdge(const Edges& edges) const { - if (edges[yoga::to_underlying(Edge::Bottom)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Bottom)]); - } else if (edges[yoga::to_underlying(Edge::Vertical)].isDefined()) { - return pool_.getLength(edges[yoga::to_underlying(Edge::Vertical)]); - } else { - return pool_.getLength(edges[yoga::to_underlying(Edge::All)]); - } - } - - Style::Length computePosition(PhysicalEdge edge, Direction direction) const { - switch (edge) { - case PhysicalEdge::Left: - return computeLeftEdge(position_, direction); - case PhysicalEdge::Top: - return computeTopEdge(position_); - case PhysicalEdge::Right: - return computeRightEdge(position_, direction); - case PhysicalEdge::Bottom: - return computeBottomEdge(position_); - } - - fatalWithMessage("Invalid physical edge"); - } - - Style::Length computeMargin(PhysicalEdge edge, Direction direction) const { - switch (edge) { - case PhysicalEdge::Left: - return computeLeftEdge(margin_, direction); - case PhysicalEdge::Top: - return computeTopEdge(margin_); - case PhysicalEdge::Right: - return computeRightEdge(margin_, direction); - case PhysicalEdge::Bottom: - return computeBottomEdge(margin_); - } - - fatalWithMessage("Invalid physical edge"); - } - - Style::Length computePadding(PhysicalEdge edge, Direction direction) const { - switch (edge) { - case PhysicalEdge::Left: - return computeLeftEdge(padding_, direction); - case PhysicalEdge::Top: - return computeTopEdge(padding_); - case PhysicalEdge::Right: - return computeRightEdge(padding_, direction); - case PhysicalEdge::Bottom: - return computeBottomEdge(padding_); - } - - fatalWithMessage("Invalid physical edge"); - } - - Style::Length computeBorder(PhysicalEdge edge, Direction direction) const { - switch (edge) { - case PhysicalEdge::Left: - return computeLeftEdge(border_, direction); - case PhysicalEdge::Top: - return computeTopEdge(border_); - case PhysicalEdge::Right: - return computeRightEdge(border_, direction); - case PhysicalEdge::Bottom: - return computeBottomEdge(border_); - } - - fatalWithMessage("Invalid physical edge"); - } - - Direction direction_ : bitCount() = Direction::Inherit; - FlexDirection flexDirection_ - : bitCount() = FlexDirection::Column; - Justify justifyContent_ : bitCount() = Justify::FlexStart; - Align alignContent_ : bitCount() = Align::FlexStart; - Align alignItems_ : bitCount() = Align::Stretch; - Align alignSelf_ : bitCount() = Align::Auto; - PositionType positionType_ - : bitCount() = PositionType::Relative; - Wrap flexWrap_ : bitCount() = Wrap::NoWrap; - Overflow overflow_ : bitCount() = Overflow::Visible; - Display display_ : bitCount() = Display::Flex; - - StyleValueHandle flex_{}; - StyleValueHandle flexGrow_{}; - StyleValueHandle flexShrink_{}; - StyleValueHandle flexBasis_{StyleValueHandle::ofAuto()}; - Edges margin_{}; - Edges position_{}; - Edges padding_{}; - Edges border_{}; - Gutters gap_{}; - Dimensions dimensions_{ - StyleValueHandle::ofAuto(), - StyleValueHandle::ofAuto()}; - Dimensions minDimensions_{}; - Dimensions maxDimensions_{}; - StyleValueHandle aspectRatio_{}; - - StyleValuePool pool_; -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/Style_StyleLength.h b/Sources/yoga/Style_StyleLength.h deleted file mode 100644 index b0754ae1..00000000 --- a/Sources/yoga/Style_StyleLength.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include "Enums_Unit.h" -#include "Numeric_FloatOptional.h" - -namespace facebook::yoga { - -/** - * Style::Length represents a CSS Value which may be one of: - * 1. Undefined - * 2. A keyword (e.g. auto) - * 3. A CSS value: - * a. value (e.g. 10px) - * b. value of a reference - * 4. (soon) A math function which returns a value - * - * References: - * 1. https://www.w3.org/TR/css-values-4/#lengths - * 2. https://www.w3.org/TR/css-values-4/#percentage-value - * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages - * 4. https://www.w3.org/TR/css-values-4/#math - */ -class StyleLength { - public: - constexpr StyleLength() = default; - - constexpr static StyleLength points(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleLength{FloatOptional{value}, Unit::Point}; - } - - constexpr static StyleLength percent(float value) { - return yoga::isUndefined(value) || yoga::isinf(value) - ? undefined() - : StyleLength{FloatOptional{value}, Unit::Percent}; - } - - constexpr static StyleLength ofAuto() { - return StyleLength{{}, Unit::Auto}; - } - - constexpr static StyleLength undefined() { - return StyleLength{{}, Unit::Undefined}; - } - - constexpr bool isAuto() const { - return unit_ == Unit::Auto; - } - - constexpr bool isUndefined() const { - return unit_ == Unit::Undefined; - } - - constexpr bool isDefined() const { - return !isUndefined(); - } - - constexpr FloatOptional value() const { - return value_; - } - - constexpr Unit unit() const { - return unit_; - } - - constexpr FloatOptional resolve(float referenceLength) { - switch (unit_) { - case Unit::Point: - return value_; - case Unit::Percent: - return FloatOptional{value_.unwrap() * referenceLength * 0.01f}; - default: - return FloatOptional{}; - } - } - - explicit constexpr operator YGValue() const { - return YGValue{value_.unwrap(), unscopedEnum(unit_)}; - } - - constexpr bool operator==(const StyleLength& rhs) const { - return value_ == rhs.value_ && unit_ == rhs.unit_; - } - - private: - // We intentionally do not allow direct construction using value and unit, to - // avoid invalid, or redundant combinations. - constexpr StyleLength(FloatOptional value, Unit unit) - : value_(value), unit_(unit) {} - - FloatOptional value_{}; - Unit unit_{Unit::Undefined}; -}; - -inline bool inexactEquals(const StyleLength& a, const StyleLength& b) { - return a.unit() == b.unit() && inexactEquals(a.value(), b.value()); -} - -namespace value { - -/** - * Canonical unit (one YGUnitPoint) - */ -constexpr StyleLength points(float value) { - return StyleLength::points(value); -} - -/** - * Percent of reference - */ -constexpr StyleLength percent(float value) { - return StyleLength::percent(value); -} - -/** - * "auto" keyword - */ -constexpr StyleLength ofAuto() { - return StyleLength::ofAuto(); -} - -/** - * Undefined - */ -constexpr StyleLength undefined() { - return StyleLength::undefined(); -} - -} // namespace value - -} // namespace facebook::yoga diff --git a/Sources/yoga/Style_StyleValueHandle.h b/Sources/yoga/Style_StyleValueHandle.h deleted file mode 100644 index 93c7917c..00000000 --- a/Sources/yoga/Style_StyleValueHandle.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "Yoga.h" - -#include "Numeric_FloatOptional.h" -#include "Style_SmallValueBuffer.h" -#include "Style_StyleLength.h" - -namespace facebook::yoga { - -#pragma pack(push) -#pragma pack(1) - -/** - * StyleValueHandle is a small (16-bit) handle to a length or number in a style. - * The value may be embedded directly in the handle if simple, or the handle may - * instead point to an index within a StyleValuePool. - * - * To read or write a value from a StyleValueHandle, use - * `StyleValuePool::store()`, and `StyleValuePool::getLength()`/ - * `StyleValuePool::getNumber()`. - */ -class StyleValueHandle { - public: - static constexpr StyleValueHandle ofAuto() { - StyleValueHandle handle; - handle.setType(Type::Auto); - return handle; - } - - constexpr bool isUndefined() const { - return type() == Type::Undefined; - } - - constexpr bool isDefined() const { - return !isUndefined(); - } - - constexpr bool isAuto() const { - return type() == Type::Auto; - } - - private: - friend class StyleValuePool; - - static constexpr uint16_t kHandleTypeMask = 0b0000'0000'0000'0111; - static constexpr uint16_t kHandleIndexedMask = 0b0000'0000'0000'1000; - static constexpr uint16_t kHandleValueMask = 0b1111'1111'1111'0000; - - enum class Type : uint8_t { - Undefined, - Point, - Percent, - Number, - Auto, - }; - - constexpr Type type() const { - return static_cast(repr_ & kHandleTypeMask); - } - - constexpr void setType(Type handleType) { - repr_ &= (~kHandleTypeMask); - repr_ |= static_cast(handleType); - } - - constexpr uint16_t value() const { - return repr_ >> 4; - } - - constexpr void setValue(uint16_t value) { - repr_ &= (~kHandleValueMask); - repr_ |= (value << 4); - } - - constexpr bool isValueIndexed() const { - return (repr_ & kHandleIndexedMask) != 0; - } - - constexpr void setValueIsIndexed() { - repr_ |= kHandleIndexedMask; - } - - uint16_t repr_{0}; -}; - -#pragma pack(pop) - -} // namespace facebook::yoga diff --git a/Sources/yoga/Style_StyleValuePool.h b/Sources/yoga/Style_StyleValuePool.h deleted file mode 100644 index 3768a187..00000000 --- a/Sources/yoga/Style_StyleValuePool.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -#include "Numeric_FloatOptional.h" -#include "Style_SmallValueBuffer.h" -#include "Style_StyleLength.h" -#include "Style_StyleValueHandle.h" - -namespace facebook::yoga { - -/** - * StyleValuePool allows compact storage for a sparse collection of assigned - * lengths and numbers. Values are referred to using StyleValueHandle. In most - * cases StyleValueHandle can embed the value directly, but if not, the value is - * stored within a buffer provided by the pool. The pool contains a fixed number - * of inline slots before falling back to heap allocating additional slots. - */ -class StyleValuePool { - public: - void store(StyleValueHandle& handle, StyleLength length) { - if (length.isUndefined()) { - handle.setType(StyleValueHandle::Type::Undefined); - } else if (length.isAuto()) { - handle.setType(StyleValueHandle::Type::Auto); - } else { - auto type = length.unit() == Unit::Point - ? StyleValueHandle::Type::Point - : StyleValueHandle::Type::Percent; - storeValue(handle, length.value().unwrap(), type); - } - } - - void store(StyleValueHandle& handle, FloatOptional number) { - if (number.isUndefined()) { - handle.setType(StyleValueHandle::Type::Undefined); - } else { - storeValue(handle, number.unwrap(), StyleValueHandle::Type::Number); - } - } - - StyleLength getLength(StyleValueHandle handle) const { - if (handle.isUndefined()) { - return value::undefined(); - } else if (handle.isAuto()) { - return value::ofAuto(); - } else { - assert( - handle.type() == StyleValueHandle::Type::Point || - handle.type() == StyleValueHandle::Type::Percent); - float value = (handle.isValueIndexed()) - ? std::bit_cast(buffer_.get32(handle.value())) - : unpackInlineInteger(handle.value()); - - return handle.type() == StyleValueHandle::Type::Point - ? value::points(value) - : value::percent(value); - } - } - - FloatOptional getNumber(StyleValueHandle handle) const { - if (handle.isUndefined()) { - return FloatOptional{}; - } else { - assert(handle.type() == StyleValueHandle::Type::Number); - float value = (handle.isValueIndexed()) - ? std::bit_cast(buffer_.get32(handle.value())) - : unpackInlineInteger(handle.value()); - return FloatOptional{value}; - } - } - - private: - void storeValue( - StyleValueHandle& handle, - float value, - StyleValueHandle::Type type) { - handle.setType(type); - - if (handle.isValueIndexed()) { - auto newIndex = - buffer_.replace(handle.value(), std::bit_cast(value)); - handle.setValue(newIndex); - } else if (isIntegerPackable(value)) { - handle.setValue(packInlineInteger(value)); - } else { - auto newIndex = buffer_.push(std::bit_cast(value)); - handle.setValue(newIndex); - handle.setValueIsIndexed(); - } - } - - static constexpr bool isIntegerPackable(float f) { - constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1; - - int32_t i = static_cast(f); - return static_cast(i) == f && i >= -kMaxInlineAbsValue && - i <= +kMaxInlineAbsValue; - } - - static constexpr uint16_t packInlineInteger(float value) { - uint16_t isNegative = value < 0 ? 1 : 0; - return static_cast( - (isNegative << 11) | - (static_cast(value) * (isNegative ? -1 : 1))); - } - - static constexpr float unpackInlineInteger(uint16_t value) { - constexpr uint16_t kValueSignMask = 0b0000'1000'0000'0000; - constexpr uint16_t kValueMagnitudeMask = 0b0000'0111'1111'1111; - const bool isNegative = (value & kValueSignMask) != 0; - return static_cast( - (value & kValueMagnitudeMask) * (isNegative ? -1 : 1)); - } - - SmallValueBuffer<4> buffer_; -}; - -} // namespace facebook::yoga diff --git a/Sources/yoga/YGConfig.cpp b/Sources/yoga/YGConfig.cpp deleted file mode 100644 index 0ceeb983..00000000 --- a/Sources/yoga/YGConfig.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" -#include "Debug_AssertFatal.h" -#include "Debug_Log.h" - -using namespace facebook; -using namespace facebook::yoga; - -YGConfigRef YGConfigNew(void) { - return new yoga::Config(getDefaultLogger()); -} - -void YGConfigFree(const YGConfigRef config) { - delete resolveRef(config); -} - -YGConfigConstRef YGConfigGetDefault() { - return &yoga::Config::getDefault(); -} - -void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) { - resolveRef(config)->setUseWebDefaults(enabled); -} - -bool YGConfigGetUseWebDefaults(const YGConfigConstRef config) { - return resolveRef(config)->useWebDefaults(); -} - -void YGConfigSetPointScaleFactor( - const YGConfigRef config, - const float pixelsInPoint) { - yoga::assertFatalWithConfig( - resolveRef(config), - pixelsInPoint >= 0.0f, - "Scale factor should not be less than zero"); - - resolveRef(config)->setPointScaleFactor(pixelsInPoint); -} - -float YGConfigGetPointScaleFactor(const YGConfigConstRef config) { - return resolveRef(config)->getPointScaleFactor(); -} - -void YGConfigSetErrata(YGConfigRef config, YGErrata errata) { - resolveRef(config)->setErrata(scopedEnum(errata)); -} - -YGErrata YGConfigGetErrata(YGConfigConstRef config) { - return unscopedEnum(resolveRef(config)->getErrata()); -} - -void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { - if (logger != nullptr) { - resolveRef(config)->setLogger(logger); - } else { - resolveRef(config)->setLogger(getDefaultLogger()); - } -} - -void YGConfigSetContext(const YGConfigRef config, void* context) { - resolveRef(config)->setContext(context); -} - -void* YGConfigGetContext(const YGConfigConstRef config) { - return resolveRef(config)->getContext(); -} - -void YGConfigSetExperimentalFeatureEnabled( - const YGConfigRef config, - const YGExperimentalFeature feature, - const bool enabled) { - resolveRef(config)->setExperimentalFeatureEnabled( - scopedEnum(feature), enabled); -} - -bool YGConfigIsExperimentalFeatureEnabled( - const YGConfigConstRef config, - const YGExperimentalFeature feature) { - return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature)); -} - -void YGConfigSetCloneNodeFunc( - const YGConfigRef config, - const YGCloneNodeFunc callback) { - resolveRef(config)->setCloneNodeCallback(callback); -} diff --git a/Sources/yoga/YGEnums.cpp b/Sources/yoga/YGEnums.cpp deleted file mode 100644 index 43974691..00000000 --- a/Sources/yoga/YGEnums.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#include "YGEnums.h" - -const char* YGAlignToString(const YGAlign value) { - switch (value) { - case YGAlignAuto: - return "auto"; - case YGAlignFlexStart: - return "flex-start"; - case YGAlignCenter: - return "center"; - case YGAlignFlexEnd: - return "flex-end"; - case YGAlignStretch: - return "stretch"; - case YGAlignBaseline: - return "baseline"; - case YGAlignSpaceBetween: - return "space-between"; - case YGAlignSpaceAround: - return "space-around"; - case YGAlignSpaceEvenly: - return "space-evenly"; - } - return "unknown"; -} - -const char* YGDimensionToString(const YGDimension value) { - switch (value) { - case YGDimensionWidth: - return "width"; - case YGDimensionHeight: - return "height"; - } - return "unknown"; -} - -const char* YGDirectionToString(const YGDirection value) { - switch (value) { - case YGDirectionInherit: - return "inherit"; - case YGDirectionLTR: - return "ltr"; - case YGDirectionRTL: - return "rtl"; - } - return "unknown"; -} - -const char* YGDisplayToString(const YGDisplay value) { - switch (value) { - case YGDisplayFlex: - return "flex"; - case YGDisplayNone: - return "none"; - } - return "unknown"; -} - -const char* YGEdgeToString(const YGEdge value) { - switch (value) { - case YGEdgeLeft: - return "left"; - case YGEdgeTop: - return "top"; - case YGEdgeRight: - return "right"; - case YGEdgeBottom: - return "bottom"; - case YGEdgeStart: - return "start"; - case YGEdgeEnd: - return "end"; - case YGEdgeHorizontal: - return "horizontal"; - case YGEdgeVertical: - return "vertical"; - case YGEdgeAll: - return "all"; - } - return "unknown"; -} - -const char* YGErrataToString(const YGErrata value) { - switch (value) { - case YGErrataNone: - return "none"; - case YGErrataStretchFlexBasis: - return "stretch-flex-basis"; - case YGErrataAbsolutePositioningIncorrect: - return "absolute-positioning-incorrect"; - case YGErrataAbsolutePercentAgainstInnerSize: - return "absolute-percent-against-inner-size"; - case YGErrataAll: - return "all"; - case YGErrataClassic: - return "classic"; - } - return "unknown"; -} - -const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) { - switch (value) { - case YGExperimentalFeatureWebFlexBasis: - return "web-flex-basis"; - } - return "unknown"; -} - -const char* YGFlexDirectionToString(const YGFlexDirection value) { - switch (value) { - case YGFlexDirectionColumn: - return "column"; - case YGFlexDirectionColumnReverse: - return "column-reverse"; - case YGFlexDirectionRow: - return "row"; - case YGFlexDirectionRowReverse: - return "row-reverse"; - } - return "unknown"; -} - -const char* YGGutterToString(const YGGutter value) { - switch (value) { - case YGGutterColumn: - return "column"; - case YGGutterRow: - return "row"; - case YGGutterAll: - return "all"; - } - return "unknown"; -} - -const char* YGJustifyToString(const YGJustify value) { - switch (value) { - case YGJustifyFlexStart: - return "flex-start"; - case YGJustifyCenter: - return "center"; - case YGJustifyFlexEnd: - return "flex-end"; - case YGJustifySpaceBetween: - return "space-between"; - case YGJustifySpaceAround: - return "space-around"; - case YGJustifySpaceEvenly: - return "space-evenly"; - } - return "unknown"; -} - -const char* YGLogLevelToString(const YGLogLevel value) { - switch (value) { - case YGLogLevelError: - return "error"; - case YGLogLevelWarn: - return "warn"; - case YGLogLevelInfo: - return "info"; - case YGLogLevelDebug: - return "debug"; - case YGLogLevelVerbose: - return "verbose"; - case YGLogLevelFatal: - return "fatal"; - } - return "unknown"; -} - -const char* YGMeasureModeToString(const YGMeasureMode value) { - switch (value) { - case YGMeasureModeUndefined: - return "undefined"; - case YGMeasureModeExactly: - return "exactly"; - case YGMeasureModeAtMost: - return "at-most"; - } - return "unknown"; -} - -const char* YGNodeTypeToString(const YGNodeType value) { - switch (value) { - case YGNodeTypeDefault: - return "default"; - case YGNodeTypeText: - return "text"; - } - return "unknown"; -} - -const char* YGOverflowToString(const YGOverflow value) { - switch (value) { - case YGOverflowVisible: - return "visible"; - case YGOverflowHidden: - return "hidden"; - case YGOverflowScroll: - return "scroll"; - } - return "unknown"; -} - -const char* YGPositionTypeToString(const YGPositionType value) { - switch (value) { - case YGPositionTypeStatic: - return "static"; - case YGPositionTypeRelative: - return "relative"; - case YGPositionTypeAbsolute: - return "absolute"; - } - return "unknown"; -} - -const char* YGUnitToString(const YGUnit value) { - switch (value) { - case YGUnitUndefined: - return "undefined"; - case YGUnitPoint: - return "point"; - case YGUnitPercent: - return "percent"; - case YGUnitAuto: - return "auto"; - } - return "unknown"; -} - -const char* YGWrapToString(const YGWrap value) { - switch (value) { - case YGWrapNoWrap: - return "no-wrap"; - case YGWrapWrap: - return "wrap"; - case YGWrapWrapReverse: - return "wrap-reverse"; - } - return "unknown"; -} diff --git a/Sources/yoga/YGNode.cpp b/Sources/yoga/YGNode.cpp deleted file mode 100644 index 94dc5556..00000000 --- a/Sources/yoga/YGNode.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" - -#include "Algorithm_Cache.h" -#include "Algorithm_CalculateLayout.h" -#include "Debug_AssertFatal.h" -#include "Debug_Log.h" -#include "Event_event.h" -#include "Node_Node.h" - -using namespace facebook; -using namespace facebook::yoga; - -YGNodeRef YGNodeNew(void) { - return YGNodeNewWithConfig(YGConfigGetDefault()); -} - -YGNodeRef YGNodeNewWithConfig(const YGConfigConstRef config) { - auto* node = new yoga::Node{resolveRef(config)}; - yoga::assertFatal( - config != nullptr, "Tried to construct YGNode with null config"); - Event::publish(node, {config}); - - return node; -} - -YGNodeRef YGNodeClone(YGNodeConstRef oldNodeRef) { - auto oldNode = resolveRef(oldNodeRef); - const auto node = new yoga::Node(*oldNode); - Event::publish(node, {node->getConfig()}); - node->setOwner(nullptr); - return node; -} - -void YGNodeFree(const YGNodeRef nodeRef) { - const auto node = resolveRef(nodeRef); - - if (auto owner = node->getOwner()) { - owner->removeChild(node); - node->setOwner(nullptr); - } - - const size_t childCount = node->getChildCount(); - for (size_t i = 0; i < childCount; i++) { - auto child = node->getChild(i); - child->setOwner(nullptr); - } - - node->clearChildren(); - - Event::publish(node, {YGNodeGetConfig(node)}); - delete resolveRef(node); -} - -void YGNodeFreeRecursive(YGNodeRef rootRef) { - const auto root = resolveRef(rootRef); - - size_t skipped = 0; - while (root->getChildCount() > skipped) { - const auto child = root->getChild(skipped); - if (child->getOwner() != root) { - // Don't free shared nodes that we don't own. - skipped += 1; - } else { - YGNodeRemoveChild(root, child); - YGNodeFreeRecursive(child); - } - } - YGNodeFree(root); -} - -void YGNodeFinalize(const YGNodeRef node) { - Event::publish(node, {YGNodeGetConfig(node)}); - delete resolveRef(node); -} - -void YGNodeReset(YGNodeRef node) { - resolveRef(node)->reset(); -} - -void YGNodeCalculateLayout( - const YGNodeRef node, - const float ownerWidth, - const float ownerHeight, - const YGDirection ownerDirection) { - yoga::calculateLayout( - resolveRef(node), ownerWidth, ownerHeight, scopedEnum(ownerDirection)); -} - -bool YGNodeGetHasNewLayout(YGNodeConstRef node) { - return resolveRef(node)->getHasNewLayout(); -} - -void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { - resolveRef(node)->setHasNewLayout(hasNewLayout); -} - -bool YGNodeIsDirty(YGNodeConstRef node) { - return resolveRef(node)->isDirty(); -} - -void YGNodeMarkDirty(const YGNodeRef nodeRef) { - const auto node = resolveRef(nodeRef); - - yoga::assertFatalWithNode( - node, - node->hasMeasureFunc(), - "Only leaf nodes with custom measure functions " - "should manually mark themselves as dirty"); - - node->markDirtyAndPropagate(); -} - -void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) { - resolveRef(node)->setDirtiedFunc(dirtiedFunc); -} - -YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node) { - return resolveRef(node)->getDirtiedFunc(); -} - -void YGNodeInsertChild( - const YGNodeRef ownerRef, - const YGNodeRef childRef, - const size_t index) { - auto owner = resolveRef(ownerRef); - auto child = resolveRef(childRef); - - yoga::assertFatalWithNode( - owner, - child->getOwner() == nullptr, - "Child already has a owner, it must be removed first."); - - yoga::assertFatalWithNode( - owner, - !owner->hasMeasureFunc(), - "Cannot add child: Nodes with measure functions cannot have children."); - - owner->insertChild(child, index); - child->setOwner(owner); - owner->markDirtyAndPropagate(); -} - -void YGNodeSwapChild( - const YGNodeRef ownerRef, - const YGNodeRef childRef, - const size_t index) { - auto owner = resolveRef(ownerRef); - auto child = resolveRef(childRef); - - owner->replaceChild(child, index); - child->setOwner(owner); -} - -void YGNodeRemoveChild( - const YGNodeRef ownerRef, - const YGNodeRef excludedChildRef) { - auto owner = resolveRef(ownerRef); - auto excludedChild = resolveRef(excludedChildRef); - - if (owner->getChildCount() == 0) { - // This is an empty set. Nothing to remove. - return; - } - - // Children may be shared between parents, which is indicated by not having an - // owner. We only want to reset the child completely if it is owned - // exclusively by one node. - auto childOwner = excludedChild->getOwner(); - if (owner->removeChild(excludedChild)) { - if (owner == childOwner) { - excludedChild->setLayout({}); // layout is no longer valid - excludedChild->setOwner(nullptr); - } - owner->markDirtyAndPropagate(); - } -} - -void YGNodeRemoveAllChildren(const YGNodeRef ownerRef) { - auto owner = resolveRef(ownerRef); - - const size_t childCount = owner->getChildCount(); - if (childCount == 0) { - // This is an empty set already. Nothing to do. - return; - } - auto* firstChild = owner->getChild(0); - if (firstChild->getOwner() == owner) { - // If the first child has this node as its owner, we assume that this child - // set is unique. - for (size_t i = 0; i < childCount; i++) { - yoga::Node* oldChild = owner->getChild(i); - oldChild->setLayout({}); // layout is no longer valid - oldChild->setOwner(nullptr); - } - owner->clearChildren(); - owner->markDirtyAndPropagate(); - return; - } - // Otherwise, we are not the owner of the child set. We don't have to do - // anything to clear it. - owner->setChildren({}); - owner->markDirtyAndPropagate(); -} - -void YGNodeSetChildren( - const YGNodeRef ownerRef, - const YGNodeRef* childrenRefs, - const size_t count) { - auto owner = resolveRef(ownerRef); - auto children = reinterpret_cast(childrenRefs); - - if (!owner) { - return; - } - - const std::vector childrenVector = {children, children + count}; - if (childrenVector.size() == 0) { - if (owner->getChildCount() > 0) { - for (auto* child : owner->getChildren()) { - child->setLayout({}); - child->setOwner(nullptr); - } - owner->setChildren({}); - owner->markDirtyAndPropagate(); - } - } else { - if (owner->getChildCount() > 0) { - for (auto* oldChild : owner->getChildren()) { - // Our new children may have nodes in common with the old children. We - // don't reset these common nodes. - if (std::find(childrenVector.begin(), childrenVector.end(), oldChild) == - childrenVector.end()) { - oldChild->setLayout({}); - oldChild->setOwner(nullptr); - } - } - } - owner->setChildren(childrenVector); - for (yoga::Node* child : childrenVector) { - child->setOwner(owner); - } - owner->markDirtyAndPropagate(); - } -} - -YGNodeRef YGNodeGetChild(const YGNodeRef nodeRef, const size_t index) { - const auto node = resolveRef(nodeRef); - - if (index < node->getChildren().size()) { - return node->getChild(index); - } - return nullptr; -} - -size_t YGNodeGetChildCount(const YGNodeConstRef node) { - return resolveRef(node)->getChildren().size(); -} - -YGNodeRef YGNodeGetOwner(const YGNodeRef node) { - return resolveRef(node)->getOwner(); -} - -YGNodeRef YGNodeGetParent(const YGNodeRef node) { - return resolveRef(node)->getOwner(); -} - -void YGNodeSetConfig(YGNodeRef node, YGConfigRef config) { - resolveRef(node)->setConfig(resolveRef(config)); -} - -YGConfigConstRef YGNodeGetConfig(YGNodeRef node) { - return resolveRef(node)->getConfig(); -} - -void YGNodeSetContext(YGNodeRef node, void* context) { - return resolveRef(node)->setContext(context); -} - -void* YGNodeGetContext(YGNodeConstRef node) { - return resolveRef(node)->getContext(); -} - -void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc) { - resolveRef(node)->setMeasureFunc(measureFunc); -} - -bool YGNodeHasMeasureFunc(YGNodeConstRef node) { - return resolveRef(node)->hasMeasureFunc(); -} - -void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) { - resolveRef(node)->setBaselineFunc(baselineFunc); -} - -bool YGNodeHasBaselineFunc(YGNodeConstRef node) { - return resolveRef(node)->hasBaselineFunc(); -} - -void YGNodeSetIsReferenceBaseline(YGNodeRef nodeRef, bool isReferenceBaseline) { - const auto node = resolveRef(nodeRef); - if (node->isReferenceBaseline() != isReferenceBaseline) { - node->setIsReferenceBaseline(isReferenceBaseline); - node->markDirtyAndPropagate(); - } -} - -bool YGNodeIsReferenceBaseline(YGNodeConstRef node) { - return resolveRef(node)->isReferenceBaseline(); -} - -void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { - return resolveRef(node)->setNodeType(scopedEnum(nodeType)); -} - -YGNodeType YGNodeGetNodeType(YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->getNodeType()); -} - -void YGNodeSetAlwaysFormsContainingBlock( - YGNodeRef node, - bool alwaysFormsContainingBlock) { - resolveRef(node)->setAlwaysFormsContainingBlock(alwaysFormsContainingBlock); -} - -bool YGNodeGetAlwaysFormsContainingBlock(YGNodeConstRef node) { - return resolveRef(node)->alwaysFormsContainingBlock(); -} - -// TODO: This leaks internal details to the public API. Remove after removing -// ComponentKit usage of it. -bool YGNodeCanUseCachedMeasurement( - YGMeasureMode widthMode, - float availableWidth, - YGMeasureMode heightMode, - float availableHeight, - YGMeasureMode lastWidthMode, - float lastAvailableWidth, - YGMeasureMode lastHeightMode, - float lastAvailableHeight, - float lastComputedWidth, - float lastComputedHeight, - float marginRow, - float marginColumn, - YGConfigRef config) { - return yoga::canUseCachedMeasurement( - sizingMode(scopedEnum(widthMode)), - availableWidth, - sizingMode(scopedEnum(heightMode)), - availableHeight, - sizingMode(scopedEnum(lastWidthMode)), - lastAvailableWidth, - sizingMode(scopedEnum(lastHeightMode)), - lastAvailableHeight, - lastComputedWidth, - lastComputedHeight, - marginRow, - marginColumn, - resolveRef(config)); -} diff --git a/Sources/yoga/YGNodeLayout.cpp b/Sources/yoga/YGNodeLayout.cpp deleted file mode 100644 index fb60e1c4..00000000 --- a/Sources/yoga/YGNodeLayout.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" -#include "Debug_AssertFatal.h" -#include "Enums_Edge.h" -#include "Node_Node.h" - -using namespace facebook; -using namespace facebook::yoga; - -namespace { - -template -float getResolvedLayoutProperty(const YGNodeConstRef nodeRef, const Edge edge) { - const auto node = resolveRef(nodeRef); - yoga::assertFatalWithNode( - node, - edge <= Edge::End, - "Cannot get layout properties of multi-edge shorthands"); - - if (edge == Edge::Start) { - if (node->getLayout().direction() == Direction::RTL) { - return (node->getLayout().*LayoutMember)(PhysicalEdge::Right); - } else { - return (node->getLayout().*LayoutMember)(PhysicalEdge::Left); - } - } - - if (edge == Edge::End) { - if (node->getLayout().direction() == Direction::RTL) { - return (node->getLayout().*LayoutMember)(PhysicalEdge::Left); - } else { - return (node->getLayout().*LayoutMember)(PhysicalEdge::Right); - } - } - - return (node->getLayout().*LayoutMember)(static_cast(edge)); -} - -} // namespace - -float YGNodeLayoutGetLeft(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position(PhysicalEdge::Left); -} - -float YGNodeLayoutGetTop(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position(PhysicalEdge::Top); -} - -float YGNodeLayoutGetRight(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position(PhysicalEdge::Right); -} - -float YGNodeLayoutGetBottom(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position(PhysicalEdge::Bottom); -} - -float YGNodeLayoutGetWidth(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().dimension(Dimension::Width); -} - -float YGNodeLayoutGetHeight(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().dimension(Dimension::Height); -} - -YGDirection YGNodeLayoutGetDirection(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->getLayout().direction()); -} - -bool YGNodeLayoutGetHadOverflow(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().hadOverflow(); -} - -float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::margin>( - node, scopedEnum(edge)); -} - -float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::border>( - node, scopedEnum(edge)); -} - -float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::padding>( - node, scopedEnum(edge)); -} diff --git a/Sources/yoga/YGNodeStyle.cpp b/Sources/yoga/YGNodeStyle.cpp deleted file mode 100644 index bb6c8ed4..00000000 --- a/Sources/yoga/YGNodeStyle.cpp +++ /dev/null @@ -1,385 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" -#include "Debug_AssertFatal.h" -#include "Node_Node.h" - -using namespace facebook; -using namespace facebook::yoga; - -namespace { - -template -void updateStyle(YGNodeRef node, ValueT value) { - auto& style = resolveRef(node)->style(); - if ((style.*GetterT)() != value) { - (style.*SetterT)(value); - resolveRef(node)->markDirtyAndPropagate(); - } -} - -template -void updateStyle(YGNodeRef node, IdxT idx, ValueT value) { - auto& style = resolveRef(node)->style(); - if ((style.*GetterT)(idx) != value) { - (style.*SetterT)(idx, value); - resolveRef(node)->markDirtyAndPropagate(); - } -} - -} // namespace - -void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeConstRef srcNode) { - auto dst = resolveRef(dstNode); - auto src = resolveRef(srcNode); - - if (dst->style() != src->style()) { - dst->setStyle(src->style()); - dst->markDirtyAndPropagate(); - } -} - -void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { - updateStyle<&Style::direction, &Style::setDirection>(node, scopedEnum(value)); -} - -YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().direction()); -} - -void YGNodeStyleSetFlexDirection( - const YGNodeRef node, - const YGFlexDirection flexDirection) { - updateStyle<&Style::flexDirection, &Style::setFlexDirection>( - node, scopedEnum(flexDirection)); -} - -YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().flexDirection()); -} - -void YGNodeStyleSetJustifyContent( - const YGNodeRef node, - const YGJustify justifyContent) { - updateStyle<&Style::justifyContent, &Style::setJustifyContent>( - node, scopedEnum(justifyContent)); -} - -YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().justifyContent()); -} - -void YGNodeStyleSetAlignContent( - const YGNodeRef node, - const YGAlign alignContent) { - updateStyle<&Style::alignContent, &Style::setAlignContent>( - node, scopedEnum(alignContent)); -} - -YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().alignContent()); -} - -void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - updateStyle<&Style::alignItems, &Style::setAlignItems>( - node, scopedEnum(alignItems)); -} - -YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().alignItems()); -} - -void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - updateStyle<&Style::alignSelf, &Style::setAlignSelf>( - node, scopedEnum(alignSelf)); -} - -YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().alignSelf()); -} - -void YGNodeStyleSetPositionType( - const YGNodeRef node, - const YGPositionType positionType) { - updateStyle<&Style::positionType, &Style::setPositionType>( - node, scopedEnum(positionType)); -} - -YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().positionType()); -} - -void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - updateStyle<&Style::flexWrap, &Style::setFlexWrap>( - node, scopedEnum(flexWrap)); -} - -YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().flexWrap()); -} - -void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - updateStyle<&Style::overflow, &Style::setOverflow>( - node, scopedEnum(overflow)); -} - -YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().overflow()); -} - -void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - updateStyle<&Style::display, &Style::setDisplay>(node, scopedEnum(display)); -} - -YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { - return unscopedEnum(resolveRef(node)->style().display()); -} - -void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { - updateStyle<&Style::flex, &Style::setFlex>(node, FloatOptional{flex}); -} - -float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) { - const auto node = resolveRef(nodeRef); - return node->style().flex().isUndefined() ? YGUndefined - : node->style().flex().unwrap(); -} - -void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { - updateStyle<&Style::flexGrow, &Style::setFlexGrow>( - node, FloatOptional{flexGrow}); -} - -float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) { - const auto node = resolveRef(nodeRef); - return node->style().flexGrow().isUndefined() - ? Style::DefaultFlexGrow - : node->style().flexGrow().unwrap(); -} - -void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { - updateStyle<&Style::flexShrink, &Style::setFlexShrink>( - node, FloatOptional{flexShrink}); -} - -float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { - const auto node = resolveRef(nodeRef); - return node->style().flexShrink().isUndefined() - ? (node->getConfig()->useWebDefaults() ? Style::WebDefaultFlexShrink - : Style::DefaultFlexShrink) - : node->style().flexShrink().unwrap(); -} - -void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { - updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, value::points(flexBasis)); -} - -void YGNodeStyleSetFlexBasisPercent( - const YGNodeRef node, - const float flexBasisPercent) { - updateStyle<&Style::flexBasis, &Style::setFlexBasis>( - node, value::percent(flexBasisPercent)); -} - -void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto()); -} - -YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().flexBasis(); -} - -void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { - updateStyle<&Style::position, &Style::setPosition>( - node, scopedEnum(edge), value::points(points)); -} - -void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { - updateStyle<&Style::position, &Style::setPosition>( - node, scopedEnum(edge), value::percent(percent)); -} - -YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { - return (YGValue)resolveRef(node)->style().position(scopedEnum(edge)); -} - -void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { - updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::points(points)); -} - -void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { - updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::percent(percent)); -} - -void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { - updateStyle<&Style::margin, &Style::setMargin>( - node, scopedEnum(edge), value::ofAuto()); -} - -YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { - return (YGValue)resolveRef(node)->style().margin(scopedEnum(edge)); -} - -void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { - updateStyle<&Style::padding, &Style::setPadding>( - node, scopedEnum(edge), value::points(points)); -} - -void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { - updateStyle<&Style::padding, &Style::setPadding>( - node, scopedEnum(edge), value::percent(percent)); -} - -YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { - return (YGValue)resolveRef(node)->style().padding(scopedEnum(edge)); -} - -void YGNodeStyleSetBorder( - const YGNodeRef node, - const YGEdge edge, - const float border) { - updateStyle<&Style::border, &Style::setBorder>( - node, scopedEnum(edge), value::points(border)); -} - -float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { - auto border = resolveRef(node)->style().border(scopedEnum(edge)); - if (border.isUndefined() || border.isAuto()) { - return YGUndefined; - } - - return static_cast(border).value; -} - -void YGNodeStyleSetGap( - const YGNodeRef node, - const YGGutter gutter, - const float gapLength) { - updateStyle<&Style::gap, &Style::setGap>( - node, scopedEnum(gutter), value::points(gapLength)); -} - -float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { - auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter)); - if (gapLength.isUndefined() || gapLength.isAuto()) { - return YGUndefined; - } - - return static_cast(gapLength).value; -} - -void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { - updateStyle<&Style::aspectRatio, &Style::setAspectRatio>( - node, FloatOptional{aspectRatio}); -} - -float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { - const FloatOptional op = resolveRef(node)->style().aspectRatio(); - return op.isUndefined() ? YGUndefined : op.unwrap(); -} - -void YGNodeStyleSetWidth(YGNodeRef node, float points) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::points(points)); -} - -void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::percent(percent)); -} - -void YGNodeStyleSetWidthAuto(YGNodeRef node) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value::ofAuto()); -} - -YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().dimension(Dimension::Width); -} - -void YGNodeStyleSetHeight(YGNodeRef node, float points) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::points(points)); -} - -void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::percent(percent)); -} - -void YGNodeStyleSetHeightAuto(YGNodeRef node) { - updateStyle<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value::ofAuto()); -} - -YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().dimension(Dimension::Height); -} - -void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { - updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value::points(minWidth)); -} - -void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { - updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value::percent(minWidth)); -} - -YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().minDimension(Dimension::Width); -} - -void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { - updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value::points(minHeight)); -} - -void YGNodeStyleSetMinHeightPercent( - const YGNodeRef node, - const float minHeight) { - updateStyle<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value::percent(minHeight)); -} - -YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().minDimension(Dimension::Height); -} - -void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { - updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value::points(maxWidth)); -} - -void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { - updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value::percent(maxWidth)); -} - -YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Width); -} - -void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { - updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value::points(maxHeight)); -} - -void YGNodeStyleSetMaxHeightPercent( - const YGNodeRef node, - const float maxHeight) { - updateStyle<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value::percent(maxHeight)); -} - -YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { - return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Height); -} diff --git a/Sources/yoga/YGPixelGrid.cpp b/Sources/yoga/YGPixelGrid.cpp deleted file mode 100644 index fa2158c3..00000000 --- a/Sources/yoga/YGPixelGrid.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "Yoga.h" - -#include "Algorithm_PixelGrid.h" - -using namespace facebook; -using namespace facebook::yoga; - -float YGRoundValueToPixelGrid( - const double value, - const double pointScaleFactor, - const bool forceCeil, - const bool forceFloor) { - return yoga::roundValueToPixelGrid( - value, pointScaleFactor, forceCeil, forceFloor); -} diff --git a/Sources/yoga/YGValue.cpp b/Sources/yoga/YGValue.cpp deleted file mode 100644 index 88de0494..00000000 --- a/Sources/yoga/YGValue.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "YGValue.h" -#include "Numeric_Comparison.h" - -using namespace facebook; -using namespace facebook::yoga; - -const YGValue YGValueZero = {0, YGUnitPoint}; -const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; -const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; - -bool YGFloatIsUndefined(const float value) { - return yoga::isUndefined(value); -} diff --git a/Sources/yoga/include/yoga/YGConfig.h b/Sources/yoga/include/yoga/YGConfig.h deleted file mode 100644 index 950b7fd8..00000000 --- a/Sources/yoga/include/yoga/YGConfig.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include - -#include "YGEnums.h" -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -typedef struct YGNode* YGNodeRef; -typedef const struct YGNode* YGNodeConstRef; - -/** - * Handle to a mutable Yoga configuration. - */ -typedef struct YGConfig* YGConfigRef; - -/** - * Handle to an immutable Yoga configruation. - */ -typedef const struct YGConfig* YGConfigConstRef; - -/** - * Allocates a set of configuration options. The configuration may be applied to - * multiple nodes (i.e. a single global config), or can be applied more - * granularly per-node. - */ -YG_EXPORT YGConfigRef YGConfigNew(void); - -/** - * Frees the associated Yoga configuration. - */ -YG_EXPORT void YGConfigFree(YGConfigRef config); - -/** - * Returns the default config values set by Yoga. - */ -YG_EXPORT YGConfigConstRef YGConfigGetDefault(void); - -/** - * Yoga by default creates new nodes with style defaults different from flexbox - * on web (e.g. `YGFlexDirectionColumn` and `YGPositionRelative`). - * `UseWebDefaults` instructs Yoga to instead use a default style consistent - * with the web. - */ -YG_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled); - -/** - * Whether the configuration is set to use web defaults. - */ -YG_EXPORT bool YGConfigGetUseWebDefaults(YGConfigConstRef config); - -/** - * Yoga will by deafult round final layout positions and dimensions to the - * nearst point. `pointScaleFactor` controls the density of the grid used for - * layout rounding (e.g. to round to the closest display pixel). - * - * May be set to 0.0f to avoid rounding the layout results. - */ -YG_EXPORT void YGConfigSetPointScaleFactor( - YGConfigRef config, - float pixelsInPoint); - -/** - * Get the currently set point scale factor. - */ -YG_EXPORT float YGConfigGetPointScaleFactor(YGConfigConstRef config); - -/** - * Configures how Yoga balances W3C conformance vs compatibility with layouts - * created against earlier versions of Yoga. - * - * By deafult Yoga will prioritize W3C conformance. `Errata` may be set to ask - * Yoga to produce specific incorrect behaviors. E.g. `YGConfigSetErrata(config, - * YGErrataStretchFlexBasis)`. - * - * YGErrata is a bitmask, and multiple errata may be set at once. Predfined - * constants exist for convenience: - * 1. YGErrataNone: No errata - * 2. YGErrataClassic: Match layout behaviors of Yoga 1.x - * 3. YGErrataAll: Match layout behaviors of Yoga 1.x, including - * `UseLegacyStretchBehaviour` - */ -YG_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata); - -/** - * Get the currently set errata. - */ -YG_EXPORT YGErrata YGConfigGetErrata(YGConfigConstRef config); - -/** - * Function pointer type for YGConfigSetLogger. - */ -typedef int (*YGLogger)( - YGConfigConstRef config, - YGNodeConstRef node, - YGLogLevel level, - const char* format, - va_list args); - -/** - * Set a custom log function for to use when logging diagnostics or fatal. - * errors. - */ -YG_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger); - -/** - * Sets an arbitrary context pointer on the config which may be read from during - * callbacks. - */ -YG_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); - -/** - * Gets the currently set context. - */ -YG_EXPORT void* YGConfigGetContext(YGConfigConstRef config); - -/** - * Function pointer type for YGConfigSetCloneNodeFunc. - */ -typedef YGNodeRef (*YGCloneNodeFunc)( - YGNodeConstRef oldNode, - YGNodeConstRef owner, - size_t childIndex); - -/** - * Enable an experimental/unsupported feature in Yoga. - */ -YG_EXPORT void YGConfigSetExperimentalFeatureEnabled( - YGConfigRef config, - YGExperimentalFeature feature, - bool enabled); - -/** - * Whether an experimental feature is set. - */ -YG_EXPORT bool YGConfigIsExperimentalFeatureEnabled( - YGConfigConstRef config, - YGExperimentalFeature feature); - -/** - * Sets a callback, called during layout, to create a new mutable Yoga node if - * Yoga must write to it and its owner is not its parent observed during layout. - */ -YG_EXPORT void YGConfigSetCloneNodeFunc( - YGConfigRef config, - YGCloneNodeFunc callback); - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGEnums.h b/Sources/yoga/include/yoga/YGEnums.h deleted file mode 100644 index 16e2a612..00000000 --- a/Sources/yoga/include/yoga/YGEnums.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @generated by enums.py -// clang-format off -#pragma once -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -YG_ENUM_DECL( - YGAlign, - YGAlignAuto, - YGAlignFlexStart, - YGAlignCenter, - YGAlignFlexEnd, - YGAlignStretch, - YGAlignBaseline, - YGAlignSpaceBetween, - YGAlignSpaceAround, - YGAlignSpaceEvenly) - -YG_ENUM_DECL( - YGDimension, - YGDimensionWidth, - YGDimensionHeight) - -YG_ENUM_DECL( - YGDirection, - YGDirectionInherit, - YGDirectionLTR, - YGDirectionRTL) - -YG_ENUM_DECL( - YGDisplay, - YGDisplayFlex, - YGDisplayNone) - -YG_ENUM_DECL( - YGEdge, - YGEdgeLeft, - YGEdgeTop, - YGEdgeRight, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeHorizontal, - YGEdgeVertical, - YGEdgeAll) - -YG_ENUM_DECL( - YGErrata, - YGErrataNone = 0, - YGErrataStretchFlexBasis = 1, - YGErrataAbsolutePositioningIncorrect = 2, - YGErrataAbsolutePercentAgainstInnerSize = 4, - YGErrataAll = 2147483647, - YGErrataClassic = 2147483646) -YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata) - -YG_ENUM_DECL( - YGExperimentalFeature, - YGExperimentalFeatureWebFlexBasis) - -YG_ENUM_DECL( - YGFlexDirection, - YGFlexDirectionColumn, - YGFlexDirectionColumnReverse, - YGFlexDirectionRow, - YGFlexDirectionRowReverse) - -YG_ENUM_DECL( - YGGutter, - YGGutterColumn, - YGGutterRow, - YGGutterAll) - -YG_ENUM_DECL( - YGJustify, - YGJustifyFlexStart, - YGJustifyCenter, - YGJustifyFlexEnd, - YGJustifySpaceBetween, - YGJustifySpaceAround, - YGJustifySpaceEvenly) - -YG_ENUM_DECL( - YGLogLevel, - YGLogLevelError, - YGLogLevelWarn, - YGLogLevelInfo, - YGLogLevelDebug, - YGLogLevelVerbose, - YGLogLevelFatal) - -YG_ENUM_DECL( - YGMeasureMode, - YGMeasureModeUndefined, - YGMeasureModeExactly, - YGMeasureModeAtMost) - -YG_ENUM_DECL( - YGNodeType, - YGNodeTypeDefault, - YGNodeTypeText) - -YG_ENUM_DECL( - YGOverflow, - YGOverflowVisible, - YGOverflowHidden, - YGOverflowScroll) - -YG_ENUM_DECL( - YGPositionType, - YGPositionTypeStatic, - YGPositionTypeRelative, - YGPositionTypeAbsolute) - -YG_ENUM_DECL( - YGUnit, - YGUnitUndefined, - YGUnitPoint, - YGUnitPercent, - YGUnitAuto) - -YG_ENUM_DECL( - YGWrap, - YGWrapNoWrap, - YGWrapWrap, - YGWrapWrapReverse) - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGMacros.h b/Sources/yoga/include/yoga/YGMacros.h deleted file mode 100644 index 6d1becce..00000000 --- a/Sources/yoga/include/yoga/YGMacros.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#ifdef __cplusplus -#include -#endif - -#ifdef __cplusplus -#define YG_EXTERN_C_BEGIN extern "C" { -#define YG_EXTERN_C_END } -#else -#define YG_EXTERN_C_BEGIN -#define YG_EXTERN_C_END -#endif - -#if defined(__cplusplus) -#define YG_DEPRECATED(message) [[deprecated(message)]] -#elif defined(_MSC_VER) -#define YG_DEPRECATED(message) __declspec(deprecated(message)) -#else -#define YG_DEPRECATED(message) __attribute__((deprecated(message))) -#endif - -#ifdef _WINDLL -#define YG_EXPORT __declspec(dllexport) -#elif !defined(_MSC_VER) -#define YG_EXPORT __attribute__((visibility("default"))) -#else -#define YG_EXPORT -#endif - -#ifdef NS_ENUM -// Cannot use NSInteger as NSInteger has a different size than int (which is the -// default type of a enum). Therefor when linking the Yoga C library into obj-c -// the header is a mismatch for the Yoga ABI. -#define YG_ENUM_BEGIN(name) NS_ENUM(int, name) -#define YG_ENUM_END(name) -#else -#define YG_ENUM_BEGIN(name) enum name -#define YG_ENUM_END(name) name -#endif - -#ifdef __cplusplus -#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \ - extern "C++" { \ - constexpr name operator~(name a) { \ - return static_cast( \ - ~static_cast::type>(a)); \ - } \ - constexpr name operator|(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) | \ - static_cast::type>(b)); \ - } \ - constexpr name operator&(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) & \ - static_cast::type>(b)); \ - } \ - constexpr name operator^(name a, name b) { \ - return static_cast( \ - static_cast::type>(a) ^ \ - static_cast::type>(b)); \ - } \ - inline name& operator|=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) |= \ - static_cast::type>(b)); \ - } \ - inline name& operator&=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) &= \ - static_cast::type>(b)); \ - } \ - inline name& operator^=(name& a, name b) { \ - return reinterpret_cast( \ - reinterpret_cast::type&>(a) ^= \ - static_cast::type>(b)); \ - } \ - } -#else -#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) -#endif - -#define YG_ENUM_DECL(NAME, ...) \ - typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ - YG_EXPORT const char* NAME##ToString(NAME); diff --git a/Sources/yoga/include/yoga/YGNode.h b/Sources/yoga/include/yoga/YGNode.h deleted file mode 100644 index 62d971c8..00000000 --- a/Sources/yoga/include/yoga/YGNode.h +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -#include "YGConfig.h" -#include "YGEnums.h" -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -/** - * Handle to a mutable Yoga Node. - */ -typedef struct YGNode* YGNodeRef; - -/** - * Handle to an immutable Yoga Node. - */ -typedef const struct YGNode* YGNodeConstRef; - -/** - * Heap allocates and returns a new Yoga node using Yoga settings. - */ -YG_EXPORT YGNodeRef YGNodeNew(void); - -/** - * Heap allocates and returns a new Yoga node, with customized settings. - */ -YG_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigConstRef config); - -/** - * Returns a mutable copy of an existing node, with the same context and - * children, but no owner set. Does not call the function set by - * YGConfigSetCloneNodeFunc(). - */ -YG_EXPORT YGNodeRef YGNodeClone(YGNodeConstRef node); - -/** - * Frees the Yoga node, disconnecting it from its owner and children. - */ -YG_EXPORT void YGNodeFree(YGNodeRef node); - -/** - * Frees the subtree of Yoga nodes rooted at the given node. - */ -YG_EXPORT void YGNodeFreeRecursive(YGNodeRef node); - -/** - * Frees the Yoga node without disconnecting it from its owner or children. - * Allows garbage collecting Yoga nodes in parallel when the entire tree is - * unrechable. - */ -YG_EXPORT void YGNodeFinalize(YGNodeRef node); - -/** - * Resets the node to its default state. - */ -YG_EXPORT void YGNodeReset(YGNodeRef node); - -/** - * Calculates the layout of the tree rooted at the given node. - * - * Layout results may be read after calling YGNodeCalculateLayout() using - * functions like YGNodeLayoutGetLeft(), YGNodeLayoutGetTop(), etc. - * - * YGNodeGetHasNewLayout() may be read to know if the layout of the node or its - * subtrees may have changed since the last time YGNodeCalculate() was called. - */ -YG_EXPORT void YGNodeCalculateLayout( - YGNodeRef node, - float availableWidth, - float availableHeight, - YGDirection ownerDirection); - -/** - * Whether the given node may have new layout results. Must be reset by calling - * YGNodeSetHasNewLayout(). - */ -YG_EXPORT bool YGNodeGetHasNewLayout(YGNodeConstRef node); - -/** - * Sets whether a nodes layout is considered new. - */ -YG_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout); - -/** - * Whether the node's layout results are dirty due to it or its children - * changing. - */ -YG_EXPORT bool YGNodeIsDirty(YGNodeConstRef node); - -/** - * Marks a node with custom measure function as dirty. - */ -YG_EXPORT void YGNodeMarkDirty(YGNodeRef node); - -typedef void (*YGDirtiedFunc)(YGNodeConstRef node); - -/** - * Called when a change is made to the Yoga tree which dirties this node. - */ -YG_EXPORT void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc); - -/** - * Returns a dirtied func if set. - */ -YG_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeConstRef node); - -/** - * Inserts a child node at the given index. - */ -YG_EXPORT void YGNodeInsertChild(YGNodeRef node, YGNodeRef child, size_t index); - -/** - * Replaces the child node at a given index with a new one. - */ -YG_EXPORT void YGNodeSwapChild(YGNodeRef node, YGNodeRef child, size_t index); - -/** - * Removes the given child node. - */ -YG_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); - -/** - * Removes all children nodes. - */ -YG_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); - -/** - * Sets children according to the given list of nodes. - */ -YG_EXPORT void -YGNodeSetChildren(YGNodeRef owner, const YGNodeRef* children, size_t count); - -/** - * Get the child node at a given index. - */ -YG_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, size_t index); - -/** - * The number of child nodes. - */ -YG_EXPORT size_t YGNodeGetChildCount(YGNodeConstRef node); - -/** - * Get the parent/owner currently set for a node. - */ -YG_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node); - -/** - * Get the parent/owner currently set for a node. - */ -YG_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); - -/** - * Set a new config for the node after creation. - */ -YG_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config); - -/** - * Get the config currently set on the node. - */ -YG_EXPORT YGConfigConstRef YGNodeGetConfig(YGNodeRef node); - -/** - * Sets extra data on the Yoga node which may be read from during callbacks. - */ -YG_EXPORT void YGNodeSetContext(YGNodeRef node, void* context); - -/** - * Returns the context or NULL if no context has been set. - */ -YG_EXPORT void* YGNodeGetContext(YGNodeConstRef node); - -typedef struct YGSize { - float width; - float height; -} YGSize; - -/** - * Returns the computed dimensions of the node, following the contraints of - * `widthMode` and `heightMode`: - * - * YGMeasureModeUndefined: The parent has not imposed any constraint on the - * child. It can be whatever size it wants. - * - * YGMeasureModeAtMost: The child can be as large as it wants up to the - * specified size. - * - * YGMeasureModeExactly: The parent has determined an exact size for the - * child. The child is going to be given those bounds regardless of how big it - * wants to be. - * - * @returns the size of the leaf node, measured under the given contraints. - */ -typedef YGSize (*YGMeasureFunc)( - YGNodeConstRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode); - -/** - * Allows providing custom measurements for a Yoga leaf node (usually for - * measuring text). YGNodeMarkDirty() must be set if content effecting the - * measurements of the node changes. - */ -YG_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc); - -/** - * Whether a measure function is set. - */ -YG_EXPORT bool YGNodeHasMeasureFunc(YGNodeConstRef node); - -/** - * @returns a defined offet to baseline (ascent). - */ -typedef float (*YGBaselineFunc)(YGNodeConstRef node, float width, float height); - -/** - * Set a custom function for determining the text baseline for use in baseline - * alignment. - */ -YG_EXPORT void YGNodeSetBaselineFunc( - YGNodeRef node, - YGBaselineFunc baselineFunc); - -/** - * Whether a baseline function is set. - */ -YG_EXPORT bool YGNodeHasBaselineFunc(YGNodeConstRef node); - -/** - * Sets this node should be considered the reference baseline among siblings. - */ -YG_EXPORT void YGNodeSetIsReferenceBaseline( - YGNodeRef node, - bool isReferenceBaseline); - -/** - * Whether this node is set as the reference baseline. - */ -YG_EXPORT bool YGNodeIsReferenceBaseline(YGNodeConstRef node); - -/** - * Sets whether a leaf node's layout results may be truncated during layout - * rounding. - */ -YG_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType); - -/** - * Wwhether a leaf node's layout results may be truncated during layout - * rounding. - */ -YG_EXPORT YGNodeType YGNodeGetNodeType(YGNodeConstRef node); - -/** - * Make it so that this node will always form a containing block for any - * descendant nodes. This is useful for when a node has a property outside of - * of Yoga that will form a containing block. For example, transforms or some of - * the others listed in - * https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block - */ -YG_EXPORT void YGNodeSetAlwaysFormsContainingBlock( - YGNodeRef node, - bool alwaysFormsContainingBlock); - -/** - * Whether the node will always form a containing block for any descendant. This - * can happen in situation where the client implements something like a - * transform that can affect containing blocks but is not handled by Yoga - * directly. - */ -YG_EXPORT bool YGNodeGetAlwaysFormsContainingBlock(YGNodeConstRef node); - -/** - * @deprecated - */ -YG_DEPRECATED( - "YGNodeCanUseCachedMeasurement may be removed in a future version of Yoga") -YG_EXPORT bool YGNodeCanUseCachedMeasurement( - YGMeasureMode widthMode, - float availableWidth, - YGMeasureMode heightMode, - float availableHeight, - YGMeasureMode lastWidthMode, - float lastAvailableWidth, - YGMeasureMode lastHeightMode, - float lastAvailableHeight, - float lastComputedWidth, - float lastComputedHeight, - float marginRow, - float marginColumn, - YGConfigRef config); - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGNodeLayout.h b/Sources/yoga/include/yoga/YGNodeLayout.h deleted file mode 100644 index 8af9c42a..00000000 --- a/Sources/yoga/include/yoga/YGNodeLayout.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "YGConfig.h" -#include "YGEnums.h" -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -YG_EXPORT float YGNodeLayoutGetLeft(YGNodeConstRef node); -YG_EXPORT float YGNodeLayoutGetTop(YGNodeConstRef node); -YG_EXPORT float YGNodeLayoutGetRight(YGNodeConstRef node); -YG_EXPORT float YGNodeLayoutGetBottom(YGNodeConstRef node); -YG_EXPORT float YGNodeLayoutGetWidth(YGNodeConstRef node); -YG_EXPORT float YGNodeLayoutGetHeight(YGNodeConstRef node); -YG_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeConstRef node); -YG_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeConstRef node); - -// Get the computed values for these nodes after performing layout. If they were -// set using point values then the returned value will be the same as -// YGNodeStyleGetXXX. However if they were set using a percentage value then the -// returned value is the computed value used during layout. -YG_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge); -YG_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge); -YG_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge); - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGNodeStyle.h b/Sources/yoga/include/yoga/YGNodeStyle.h deleted file mode 100644 index 1235ee70..00000000 --- a/Sources/yoga/include/yoga/YGNodeStyle.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "YGNode.h" -#include "YGValue.h" - -YG_EXTERN_C_BEGIN - -YG_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeConstRef srcNode); - -YG_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction); -YG_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlexDirection( - YGNodeRef node, - YGFlexDirection flexDirection); -YG_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetJustifyContent( - YGNodeRef node, - YGJustify justifyContent); -YG_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetAlignContent(YGNodeRef node, YGAlign alignContent); -YG_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems); -YG_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf); -YG_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetPositionType( - YGNodeRef node, - YGPositionType positionType); -YG_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap); -YG_EXPORT YGWrap YGNodeStyleGetFlexWrap(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow); -YG_EXPORT YGOverflow YGNodeStyleGetOverflow(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetDisplay(YGNodeRef node, YGDisplay display); -YG_EXPORT YGDisplay YGNodeStyleGetDisplay(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, float flex); -YG_EXPORT float YGNodeStyleGetFlex(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow); -YG_EXPORT float YGNodeStyleGetFlexGrow(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink); -YG_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis); -YG_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis); -YG_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node); -YG_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node); - -YG_EXPORT void -YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float position); -YG_EXPORT void -YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float position); -YG_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge); - -YG_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin); -YG_EXPORT void -YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float margin); -YG_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge); -YG_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge); - -YG_EXPORT void -YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float padding); -YG_EXPORT void -YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float padding); -YG_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge); - -YG_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border); -YG_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge); - -YG_EXPORT void -YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength); -YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); - -YG_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width); -YG_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width); -YG_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node); -YG_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height); -YG_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height); -YG_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node); -YG_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth); -YG_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth); -YG_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight); -YG_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight); -YG_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth); -YG_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth); -YG_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight); -YG_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight); -YG_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node); - -YG_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio); -YG_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node); - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGPixelGrid.h b/Sources/yoga/include/yoga/YGPixelGrid.h deleted file mode 100644 index 174c1163..00000000 --- a/Sources/yoga/include/yoga/YGPixelGrid.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "YGConfig.h" -#include "YGEnums.h" -#include "YGMacros.h" - -YG_EXTERN_C_BEGIN - -/** - * Rounds a point value to the nearest whole pixel, given a pointScaleFactor - * describing pixel density. - * @returns the rounded value in points - */ -YG_EXPORT float YGRoundValueToPixelGrid( - double value, - double pointScaleFactor, - bool forceCeil, - bool forceFloor); - -YG_EXTERN_C_END diff --git a/Sources/yoga/include/yoga/YGValue.h b/Sources/yoga/include/yoga/YGValue.h deleted file mode 100644 index 2681e66a..00000000 --- a/Sources/yoga/include/yoga/YGValue.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "YGEnums.h" -#include "YGMacros.h" - -/** - * Float value to represent "undefined" in style values. - */ -#ifdef __cplusplus -#include -constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); -#else -#include -#define YGUndefined NAN -#endif - -YG_EXTERN_C_BEGIN - -/** - * Structure used to represent a dimension in a style. - */ -typedef struct YGValue { - float value; - YGUnit unit; -} YGValue; - -/** - * Constant for a dimension of "auto". - */ -YG_EXPORT extern const YGValue YGValueAuto; - -/** - * Constant for a dimension which is not defined. - */ -YG_EXPORT extern const YGValue YGValueUndefined; - -/** - * Constant for a dimension that is zero-length. - */ -YG_EXPORT extern const YGValue YGValueZero; - -/** - * Whether a dimension represented as a float is defined. - */ -YG_EXPORT bool YGFloatIsUndefined(float value); - -YG_EXTERN_C_END - -// Equality operators for comparison of YGValue in C++ -#ifdef __cplusplus -inline bool operator==(const YGValue& lhs, const YGValue& rhs) { - if (lhs.unit != rhs.unit) { - return false; - } - - switch (lhs.unit) { - case YGUnitUndefined: - case YGUnitAuto: - return true; - case YGUnitPoint: - case YGUnitPercent: - return lhs.value == rhs.value; - } - - return false; -} - -inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { - return !(lhs == rhs); -} - -inline YGValue operator-(const YGValue& value) { - return {-value.value, value.unit}; -} -#endif diff --git a/Sources/yoga/include/yoga/Yoga.h b/Sources/yoga/include/yoga/Yoga.h deleted file mode 100644 index 85bfac39..00000000 --- a/Sources/yoga/include/yoga/Yoga.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -/** - * `#include ` includes all of Yoga's public headers. - */ - -#include "YGConfig.h" -#include "YGEnums.h" -#include "YGMacros.h" -#include "YGNode.h" -#include "YGNodeLayout.h" -#include "YGNodeStyle.h" -#include "YGPixelGrid.h" -#include "YGValue.h" diff --git a/Sources/yoga/module.modulemap b/Sources/yoga/module.modulemap deleted file mode 100644 index 6a0f4603..00000000 --- a/Sources/yoga/module.modulemap +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -module yoga [system] { - module core { - header "YGConfig.h" - header "YGEnums.h" - header "YGMacros.h" - header "YGNode.h" - header "YGNodeLayout.h" - header "YGNodeStyle.h" - header "YGPixelGrid.h" - header "YGValue.h" - header "Yoga.h" - export * - } -} diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 8360c41c..ae5d7145 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -6,7 +6,7 @@ # This is the minimum version number required. # Update this, if you use features of a newer version -fastlane_version "2.29.0" +fastlane_version '2.29.0' default_platform :ios skip_docs @@ -22,69 +22,52 @@ platform :ios do use_bundle_exec: true, try_repo_update_on_error: true ) - - cocoapods( - podfile: "Example/cocoapods", - use_bundle_exec: true, - try_repo_update_on_error: true - ) end - lane :build do swiftlint( - mode: :lint, - config_file: ".swiftlint.yml", - executable: "Pods/SwiftLint/swiftlint", + mode: :lint, + config_file: '.swiftlint.yml', + executable: 'Pods/SwiftLint/swiftlint', ignore_exit_status: true ) # FlexLayout xcodebuild( - project: "FlexLayout.xcodeproj", - scheme: "FlexLayoutInner", - configuration: "Release", + workspace: 'FlexLayout.xcworkspace', + scheme: 'FlexLayoutInner', + configuration: 'Release', build: true, clean: true, - destination: "platform=iOS Simulator,name=iPhone 15,OS=17.2" + destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2' ) # FlexLayoutSample from FlexLayout.xcworkspace xcodebuild( - workspace: "FlexLayout.xcworkspace", - scheme: "FlexLayoutSample", - configuration: "Release", + workspace: 'FlexLayout.xcworkspace', + scheme: 'FlexLayoutSample', + configuration: 'Release', build: true, # clean: true, - destination: "platform=iOS Simulator,name=iPhone 15,OS=17.2" - ) - - # Example Cocoapods - xcodebuild( - workspace: "Example/cocoapods/FlexLayoutSample.xcworkspace", - scheme: "FlexLayoutSample", - configuration: "Release", - build: true, - # clean: true, - destination: "platform=iOS Simulator,name=iPhone 15,OS=17.2" + destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2' ) # Example SPM (Swift Package Manager) xcodebuild( - project: "Example/SPM/FlexLayoutSample-SPM.xcodeproj", - scheme: "FlexLayoutSample-SPM", - configuration: "Release", + project: 'Example/SPM/FlexLayoutSample-SPM.xcodeproj', + scheme: 'FlexLayoutSample-SPM', + configuration: 'Release', build: true, clean: true, - destination: "platform=iOS Simulator,name=iPhone 15,OS=17.2" + destination: 'platform=iOS Simulator,name=iPhone 15,OS=17.2' ) end lane :tests do - scan(scheme: "FlexLayoutInner", workspace: "FlexLayout.xcworkspace", device: "iPhone 15") + scan(scheme: 'FlexLayoutInner', workspace: 'FlexLayout.xcworkspace', device: 'iPhone 15') end - lane :doc do + lane :doc do jazzy end @@ -92,25 +75,24 @@ platform :ios do install tests build - #pod_lib_lint(allow_warnings: true, verbose: false) + # pod_lib_lint(allow_warnings: true, verbose: false) end lane :deploy do ensure_git_branch - version = version_bump_podspec(path: "FlexLayout.podspec") - git_commit(path: ["./FlexLayout.podspec"], message: "Bumped to version #{version}") + version = version_bump_podspec(path: 'FlexLayout.podspec') + git_commit(path: ['./FlexLayout.podspec'], message: "Bumped to version #{version}") push_to_git_remote(remote_branch: 'master', force: false, tags: true) changelog = changelog_from_git_commits github_release = set_github_release( - repository_name: "layoutBox/FlexLayout", + repository_name: 'layoutBox/FlexLayout', api_token: ENV['GITHUB_TOKEN'], name: version, tag_name: version, description: changelog, - commitish: "master" + commitish: 'master' ) - sh("git fetch --tags") + sh('git fetch --tags') pod_push(allow_warnings: true, verbose: true) end - end