├── .clang-format ├── .clang-tidy ├── .editorconfig ├── .eslintrc.cjs ├── .github ├── ISSUE_TEMPLATE.md ├── actions │ ├── black │ │ └── action.yml │ ├── cache-emsdk │ │ └── action.yml │ ├── install-ninja │ │ └── action.yml │ ├── setup-android │ │ └── action.yml │ ├── setup-apple │ │ └── action.yml │ ├── setup-cpp │ │ └── action.yml │ └── setup-js │ │ └── action.yml └── workflows │ ├── publish-android-release.yml │ ├── publish-android-snashot.yml │ ├── publish-cocoapods-release.yml │ ├── publish-npm-release.yml │ ├── validate-android.yml │ ├── validate-apple.yml │ ├── validate-cpp.yml │ ├── validate-js.yml │ ├── validate-tests.yml │ └── validate-website.yml ├── .gitignore ├── .prettierignore ├── .prettierrc.js ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE-examples ├── Package.swift ├── README.md ├── Yoga.podspec ├── benchmark ├── Benchmark.cpp ├── Benchmark.h ├── CMakeLists.txt ├── TreeDeserialization.cpp ├── TreeDeserialization.h ├── YGBenchmark.c ├── benchmark └── captures │ ├── chat-mac.json │ ├── feed-android.json │ ├── profile-ios.json │ └── rendering-sample-mac.json ├── build.gradle ├── build_fuzz_tests ├── capture ├── CMakeLists.txt ├── CaptureTree.cpp ├── CaptureTree.h ├── NodeToString.cpp └── NodeToString.h ├── cmake ├── project-defaults.cmake └── yoga-config.cmake.in ├── enums.py ├── fuzz ├── CMakeLists.txt └── FuzzLayout.cpp ├── gentest ├── babel.config.cjs ├── fixtures │ ├── YGAbsolutePositionTest.html │ ├── YGAlignContentTest.html │ ├── YGAlignItemsTest.html │ ├── YGAlignSelfTest.html │ ├── YGAndroidNewsFeed.html │ ├── YGAspectRatioTest.html │ ├── YGAutoTest.html │ ├── YGBorderTest.html │ ├── YGBoxSizingTest.html │ ├── YGDimensionTest.html │ ├── YGDisplayTest.html │ ├── YGFlexDirectionTest.html │ ├── YGFlexTest.html │ ├── YGFlexWrapTest.html │ ├── YGGapTest.html │ ├── YGIntrinsicSizeTest.html │ ├── YGJustifyContentTest.html │ ├── YGMarginTest.html │ ├── YGMinMaxDimensionTest.html │ ├── YGPaddingTest.html │ ├── YGPercentageTest.html │ ├── YGRoundingTest.html │ ├── YGSizeOverflowTest.html │ └── YGStaticPositionTest.html ├── fonts │ └── Ahem.ttf ├── gentest-cpp.js ├── gentest-driver.ts ├── gentest-java.js ├── gentest-javascript.js ├── gentest-log.js ├── gentest-validate.ts ├── gentest.js ├── package.json ├── signedsource.d.ts ├── test-template.html └── tsconfig.json ├── gradle.properties ├── gradle ├── gradle-enterprise.gradle.kts.sample └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── java ├── AndroidManifest.xml ├── CMakeLists.txt ├── build.gradle.kts ├── com │ └── facebook │ │ └── yoga │ │ ├── LayoutPassReason.java │ │ ├── YogaAlign.java │ │ ├── YogaBaselineFunction.java │ │ ├── YogaBoxSizing.java │ │ ├── YogaConfig.java │ │ ├── YogaConfigFactory.java │ │ ├── YogaConfigJNIBase.java │ │ ├── YogaConfigJNIFinalizer.java │ │ ├── YogaConstants.java │ │ ├── YogaDimension.java │ │ ├── YogaDirection.java │ │ ├── YogaDisplay.java │ │ ├── YogaEdge.java │ │ ├── YogaErrata.java │ │ ├── YogaExperimentalFeature.java │ │ ├── YogaFlexDirection.java │ │ ├── YogaGutter.java │ │ ├── YogaJustify.java │ │ ├── YogaLayoutType.java │ │ ├── YogaLogLevel.java │ │ ├── YogaLogger.java │ │ ├── YogaMeasureFunction.java │ │ ├── YogaMeasureMode.java │ │ ├── YogaMeasureOutput.java │ │ ├── YogaNative.java │ │ ├── YogaNode.java │ │ ├── YogaNodeFactory.java │ │ ├── YogaNodeJNIBase.java │ │ ├── YogaNodeJNIFinalizer.java │ │ ├── YogaNodeType.java │ │ ├── YogaOverflow.java │ │ ├── YogaPositionType.java │ │ ├── YogaProps.java │ │ ├── YogaStyleInputs.java │ │ ├── YogaUnit.java │ │ ├── YogaValue.java │ │ ├── YogaWrap.java │ │ └── annotations │ │ └── DoNotStrip.java ├── gen │ └── com │ │ └── facebook │ │ └── yoga │ │ └── BuildConfig.java ├── jni │ ├── LayoutContext.cpp │ ├── LayoutContext.h │ ├── ScopedGlobalRef.h │ ├── ScopedLocalRef.h │ ├── YGJNI.h │ ├── YGJNIVanilla.cpp │ ├── YGJNIVanilla.h │ ├── YGJTypesVanilla.h │ ├── YogaJniException.cpp │ ├── YogaJniException.h │ ├── common.cpp │ ├── common.h │ ├── corefunctions.cpp │ ├── corefunctions.h │ ├── macros.h │ └── yogajni.cpp ├── proguard-rules.pro ├── res │ └── values │ │ └── strings.xml ├── tests │ ├── com │ │ └── facebook │ │ │ └── yoga │ │ │ ├── TestParametrization.java │ │ │ ├── YGAlignBaselineTest.java │ │ │ ├── YogaExceptionTest.java │ │ │ ├── YogaLoggerTest.java │ │ │ ├── YogaNodeStylePropertiesTest.java │ │ │ ├── YogaNodeTest.java │ │ │ ├── YogaValueTest.java │ │ │ └── utils │ │ │ └── TestUtils.java │ └── generated │ │ └── com │ │ └── facebook │ │ └── yoga │ │ ├── YGAbsolutePositionTest.java │ │ ├── YGAlignContentTest.java │ │ ├── YGAlignItemsTest.java │ │ ├── YGAlignSelfTest.java │ │ ├── YGAndroidNewsFeed.java │ │ ├── YGAspectRatioTest.java │ │ ├── YGAutoTest.java │ │ ├── YGBorderTest.java │ │ ├── YGBoxSizingTest.java │ │ ├── YGDimensionTest.java │ │ ├── YGDisplayContentsTest.java │ │ ├── YGDisplayTest.java │ │ ├── YGFlexDirectionTest.java │ │ ├── YGFlexTest.java │ │ ├── YGFlexWrapTest.java │ │ ├── YGGapTest.java │ │ ├── YGIntrinsicSizeTest.java │ │ ├── YGJustifyContentTest.java │ │ ├── YGMarginTest.java │ │ ├── YGMinMaxDimensionTest.java │ │ ├── YGPaddingTest.java │ │ ├── YGPercentageTest.java │ │ ├── YGRoundingTest.java │ │ ├── YGSizeOverflowTest.java │ │ └── YGStaticPositionTest.java └── yogajni.version ├── javascript ├── .gitignore ├── CMakeLists.txt ├── README.md ├── babel.config.cjs ├── jest.config.js ├── jest.setup.js ├── just.config.cjs ├── package.json ├── src │ ├── Config.cpp │ ├── Config.h │ ├── Layout.h │ ├── Node.cpp │ ├── Node.h │ ├── Size.h │ ├── Value.h │ ├── embind.cpp │ ├── generated │ │ └── YGEnums.ts │ ├── index.ts │ ├── load.ts │ └── wrapAssembly.ts ├── tests │ ├── Benchmarks │ │ └── YGBenchmark.test.ts │ ├── YGAlignBaselineTest.test.ts │ ├── YGComputedBorderTest.test.ts │ ├── YGComputedMarginTest.test.ts │ ├── YGComputedPaddingTest.test.ts │ ├── YGDirtiedTest.test.ts │ ├── YGErrataTest.test.ts │ ├── YGFlexBasisAuto.test.ts │ ├── YGHasNewLayout.test.ts │ ├── YGMeasureCacheTest.test.ts │ ├── YGMeasureTest.test.ts │ ├── bin │ │ └── run-bench.ts │ ├── generated │ │ ├── YGAbsolutePositionTest.test.ts │ │ ├── YGAlignContentTest.test.ts │ │ ├── YGAlignItemsTest.test.ts │ │ ├── YGAlignSelfTest.test.ts │ │ ├── YGAndroidNewsFeed.test.ts │ │ ├── YGAspectRatioTest.test.ts │ │ ├── YGAutoTest.test.ts │ │ ├── YGBorderTest.test.ts │ │ ├── YGBoxSizingTest.test.ts │ │ ├── YGDimensionTest.test.ts │ │ ├── YGDisplayContentsTest.test.ts │ │ ├── YGDisplayTest.test.ts │ │ ├── YGFlexDirectionTest.test.ts │ │ ├── YGFlexTest.test.ts │ │ ├── YGFlexWrapTest.test.ts │ │ ├── YGGapTest.test.ts │ │ ├── YGIntrinsicSizeTest.test.ts │ │ ├── YGJustifyContentTest.test.ts │ │ ├── YGMarginTest.test.ts │ │ ├── YGMinMaxDimensionTest.test.ts │ │ ├── YGPaddingTest.test.ts │ │ ├── YGPercentageTest.test.ts │ │ ├── YGRoundingTest.test.ts │ │ ├── YGSizeOverflowTest.test.ts │ │ └── YGStaticPositionTest.test.ts │ └── tools │ │ ├── MeasureCounter.ts │ │ ├── globals.ts │ │ └── utils.ts └── tsconfig.json ├── lib ├── jni │ ├── jni.h │ └── real │ │ └── jni.h ├── jsr-305 │ └── jsr305.jar ├── nlohmann │ └── json.hpp └── soloader │ └── soloader-0.5.1.aar ├── package.json ├── set-version.py ├── settings.gradle.kts ├── tests ├── CMakeLists.txt ├── EventsTest.cpp ├── FlexGapTest.cpp ├── FloatOptionalTest.cpp ├── OrdinalsTest.cpp ├── SmallValueBufferTest.cpp ├── StyleTest.cpp ├── StyleValuePoolTest.cpp ├── YGAlignBaselineTest.cpp ├── YGAspectRatioTest.cpp ├── YGBaselineFuncTest.cpp ├── YGCloneNodeTest.cpp ├── YGComputedMarginTest.cpp ├── YGComputedPaddingTest.cpp ├── YGConfigTest.cpp ├── YGDefaultValuesTest.cpp ├── YGDirtiedTest.cpp ├── YGDirtyMarkingTest.cpp ├── YGEdgeTest.cpp ├── YGHadOverflowTest.cpp ├── YGLayoutableChildrenTest.cpp ├── YGMeasureCacheTest.cpp ├── YGMeasureModeTest.cpp ├── YGMeasureTest.cpp ├── YGNodeCallbackTest.cpp ├── YGNodeChildTest.cpp ├── YGPersistenceTest.cpp ├── YGRelayoutTest.cpp ├── YGRoundingFunctionTest.cpp ├── YGRoundingMeasureFuncTest.cpp ├── YGScaleChangeTest.cpp ├── YGStyleTest.cpp ├── YGTreeMutationTest.cpp ├── YGValueTest.cpp ├── YGZeroOutLayoutRecursivelyTest.cpp ├── generated │ ├── YGAbsolutePositionTest.cpp │ ├── YGAlignContentTest.cpp │ ├── YGAlignItemsTest.cpp │ ├── YGAlignSelfTest.cpp │ ├── YGAndroidNewsFeed.cpp │ ├── YGAspectRatioTest.cpp │ ├── YGAutoTest.cpp │ ├── YGBorderTest.cpp │ ├── YGBoxSizingTest.cpp │ ├── YGDimensionTest.cpp │ ├── YGDisplayContentsTest.cpp │ ├── YGDisplayTest.cpp │ ├── YGFlexDirectionTest.cpp │ ├── YGFlexTest.cpp │ ├── YGFlexWrapTest.cpp │ ├── YGGapTest.cpp │ ├── YGIntrinsicSizeTest.cpp │ ├── YGJustifyContentTest.cpp │ ├── YGMarginTest.cpp │ ├── YGMinMaxDimensionTest.cpp │ ├── YGPaddingTest.cpp │ ├── YGPercentageTest.cpp │ ├── YGRoundingTest.cpp │ ├── YGSizeOverflowTest.cpp │ └── YGStaticPositionTest.cpp └── util │ ├── TestUtil.cpp │ └── TestUtil.h ├── unit_tests ├── unit_tests.bat ├── website ├── .eslintrc.cjs ├── .gitignore ├── README.md ├── babel.config.cjs ├── blog │ ├── 2023-06-30-announcing-yoga-2.0.md │ ├── 2024-06-24-announcing-yoga-3.1.md │ ├── 2024-12-02-announcing-yoga-3.2.md │ ├── authors.yml │ └── yoga-3-release │ │ ├── 2024-03-14-announcing-yoga-3.0.md │ │ └── img │ │ ├── image1.png │ │ ├── image10.png │ │ ├── image11.png │ │ ├── image12.png │ │ ├── image13.png │ │ ├── image14.png │ │ ├── image15.png │ │ ├── image16.png │ │ ├── image17.png │ │ ├── image2.png │ │ ├── image3.png │ │ ├── image4.png │ │ ├── image5.png │ │ ├── image6.png │ │ ├── image7.png │ │ ├── image8.png │ │ └── image9.png ├── docs │ ├── about-yoga.md │ ├── advanced │ │ ├── _category_.json │ │ ├── containing-block.md │ │ ├── external-layout-systems.mdx │ │ └── incremental-layout.mdx │ ├── getting-started │ │ ├── _category_.json │ │ ├── configuring-yoga.mdx │ │ └── laying-out-a-tree.mdx │ ├── img │ │ ├── config-contextual.svg │ │ ├── config-per-node.svg │ │ ├── config-uniform.svg │ │ ├── invalidation-clean-tree.svg │ │ ├── invalidation-dirtied-tree.svg │ │ ├── invalidation-new-layout-tree.svg │ │ ├── pixel-grid-after.png │ │ ├── pixel-grid-before.png │ │ └── wireframe-example.svg │ └── styling │ │ ├── _category_.json │ │ ├── align-content.mdx │ │ ├── align-items-self.mdx │ │ ├── aspect-ratio.mdx │ │ ├── display.mdx │ │ ├── flex-basis-grow-shrink.mdx │ │ ├── flex-direction.mdx │ │ ├── flex-wrap.mdx │ │ ├── gap.mdx │ │ ├── index.md │ │ ├── insets.mdx │ │ ├── justify-content.mdx │ │ ├── layout-direction.mdx │ │ ├── margin-padding-border.mdx │ │ ├── min-max-width-height.mdx │ │ ├── position.mdx │ │ └── width-height.mdx ├── docusaurus.config.js ├── package.json ├── sidebars.cjs ├── src │ ├── components │ │ ├── EditorToolbar.module.css │ │ ├── EditorToolbar.tsx │ │ ├── FlexStyle.ts │ │ ├── LayoutBox.module.css │ │ ├── LayoutBox.tsx │ │ ├── Playground.module.css │ │ ├── Playground.tsx │ │ └── YogaViewer.tsx │ ├── css │ │ └── custom.css │ └── pages │ │ ├── index.module.css │ │ ├── index.tsx │ │ ├── markdown-page.md │ │ ├── playground.module.css │ │ └── playground.tsx ├── static │ ├── .nojekyll │ └── img │ │ ├── docusaurus.png │ │ ├── favicon.svg │ │ ├── link.svg │ │ ├── logo.svg │ │ ├── meta_oss.svg │ │ ├── opengraph.png │ │ ├── undraw_docusaurus_mountain.svg │ │ ├── undraw_docusaurus_react.svg │ │ └── undraw_docusaurus_tree.svg └── tsconfig.json ├── yarn.lock └── yoga ├── CMakeLists.txt ├── YGConfig.cpp ├── YGConfig.h ├── YGEnums.cpp ├── YGEnums.h ├── YGMacros.h ├── YGNode.cpp ├── YGNode.h ├── YGNodeLayout.cpp ├── YGNodeLayout.h ├── YGNodeStyle.cpp ├── YGNodeStyle.h ├── YGPixelGrid.cpp ├── YGPixelGrid.h ├── YGValue.cpp ├── YGValue.h ├── Yoga.h ├── algorithm ├── AbsoluteLayout.cpp ├── AbsoluteLayout.h ├── Align.h ├── Baseline.cpp ├── Baseline.h ├── BoundAxis.h ├── Cache.cpp ├── Cache.h ├── CalculateLayout.cpp ├── CalculateLayout.h ├── FlexDirection.h ├── FlexLine.cpp ├── FlexLine.h ├── PixelGrid.cpp ├── PixelGrid.h ├── SizingMode.h └── TrailingPosition.h ├── config ├── Config.cpp └── Config.h ├── debug ├── AssertFatal.cpp ├── AssertFatal.h ├── Log.cpp └── Log.h ├── enums ├── Align.h ├── BoxSizing.h ├── Dimension.h ├── Direction.h ├── Display.h ├── Edge.h ├── Errata.h ├── ExperimentalFeature.h ├── FlexDirection.h ├── Gutter.h ├── Justify.h ├── LogLevel.h ├── MeasureMode.h ├── NodeType.h ├── Overflow.h ├── PhysicalEdge.h ├── PositionType.h ├── Unit.h ├── Wrap.h └── YogaEnums.h ├── event ├── event.cpp └── event.h ├── module.modulemap ├── node ├── CachedMeasurement.h ├── LayoutResults.cpp ├── LayoutResults.h ├── LayoutableChildren.h ├── Node.cpp └── Node.h ├── numeric ├── Comparison.h └── FloatOptional.h └── style ├── SmallValueBuffer.h ├── Style.h ├── StyleLength.h ├── StyleSizeLength.h ├── StyleValueHandle.h └── StyleValuePool.h /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Report 2 | 3 | - [ ] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate 4 | 5 | # Issues and Steps to Reproduce 6 | ***Replaces this with steps to repro your issue.*** 7 | 8 | # Expected Behavior 9 | ***Describe what you expected would happen.*** 10 | 11 | # Actual Behavior 12 | ***Describe what actually happened.*** 13 | 14 | # Link to Code 15 | ***If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.*** 16 | 17 | ***When applicable, use this [fiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) to post a web repro.*** 18 | -------------------------------------------------------------------------------- /.github/actions/black/action.yml: -------------------------------------------------------------------------------- 1 | name: Black Formatter 2 | inputs: 3 | directory: 4 | description: Directory to Lint 5 | required: true 6 | version: 7 | description: pypi version of "black" to use 8 | required: false 9 | default: 22.3.0 10 | 11 | runs: 12 | using: "composite" 13 | steps: 14 | - name: Ensure supported Python selected 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: '>=3.6.2' 18 | 19 | - name: pip install 20 | shell: bash 21 | run: pip install black==${{ inputs.version }} 22 | 23 | - name: black 24 | shell: bash 25 | run: black --check ${{ inputs.directory }} 26 | -------------------------------------------------------------------------------- /.github/actions/cache-emsdk/action.yml: -------------------------------------------------------------------------------- 1 | name: Cache the installed copy of emsdk and its build artifacts 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Cache emsdk 7 | uses: actions/cache@v3 8 | with: 9 | path: javascript/.emsdk 10 | key: emsdk-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('yarn.lock', 'javascript/package.json', 'javascript/just.config.cjs')}} 11 | -------------------------------------------------------------------------------- /.github/actions/install-ninja/action.yml: -------------------------------------------------------------------------------- 1 | name: Install Ninja 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Install ninja (Linux) 7 | if: ${{ runner.os == 'Linux' }} 8 | shell: bash 9 | run: sudo apt-get install -y ninja-build 10 | 11 | - name: Install ninja (Windows) 12 | if: ${{ runner.os == 'Windows' }} 13 | shell: powershell 14 | run: choco install ninja 15 | -------------------------------------------------------------------------------- /.github/actions/setup-android/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup Android environment 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Select Java Version 7 | uses: actions/setup-java@v2 8 | with: 9 | distribution: zulu 10 | java-version: 17 11 | - name: Configure Gradle Caches 12 | uses: gradle/gradle-build-action@v2 13 | -------------------------------------------------------------------------------- /.github/actions/setup-apple/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup Apple envirionment 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | # TODO: This and Ruby should be versioned 7 | - name: Install Cocoapods 8 | shell: bash 9 | run: sudo gem install cocoapods 10 | 11 | - uses: maxim-lobanov/setup-xcode@v1 12 | with: 13 | xcode-version: 14.3.1 14 | -------------------------------------------------------------------------------- /.github/actions/setup-cpp/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup C++ envirionment 2 | inputs: 3 | toolchain: 4 | description: Compiler toolchain to use (Clang, GCC, or MSVC) 5 | required: false 6 | default: 'Clang' 7 | 8 | runs: 9 | using: "composite" 10 | steps: 11 | - name: Install Ninja 12 | if: ${{ runner.os != 'Windows' }} 13 | uses: ./.github/actions/install-ninja 14 | 15 | - name: Set Clang as compiler 16 | if: ${{ inputs.toolchain == 'Clang' }} 17 | shell: bash 18 | run: | 19 | sudo apt-get install -y libc++-dev libc++abi-dev 20 | echo "CC=/usr/bin/clang" >> $GITHUB_ENV 21 | echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV 22 | echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV 23 | echo "LDFLAGS=-stdlib=libc++" >> $GITHUB_ENV 24 | 25 | - name: Set GCC as compiler 26 | if: ${{ inputs.toolchain == 'GCC' }} 27 | shell: bash 28 | run: | 29 | echo "CC=/usr/bin/gcc" >> $GITHUB_ENV 30 | echo "CXX=/usr/bin/g++" >> $GITHUB_ENV 31 | 32 | - name: Setup VS Developer Command Prompt 33 | if: ${{ runner.os == 'Windows' }} 34 | uses: ilammy/msvc-dev-cmd@v1 35 | -------------------------------------------------------------------------------- /.github/actions/setup-js/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup JavaScript envirionment 2 | 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Setup Node environment 7 | uses: actions/setup-node@v3 8 | with: 9 | node-version: 20.x 10 | cache: yarn 11 | cache-dependency-path: yarn.lock 12 | env: 13 | # https://github.com/actions/setup-node/issues/317 14 | FORCE_COLOR: 0 15 | 16 | - name: yarn install 17 | shell: bash 18 | run: yarn install --frozen-lockfile 19 | -------------------------------------------------------------------------------- /.github/workflows/publish-android-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish Android Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | publish: 11 | name: Publish to Maven Central 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Setup 18 | uses: ./.github/actions/setup-android 19 | 20 | - name: Publish to Maven Local 21 | run: ./gradlew publishToMavenLocal 22 | env: 23 | ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }} 24 | ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }} 25 | 26 | - name: Upload Build Artifacts 27 | uses: actions/upload-artifact@v4 28 | with: 29 | name: 'snapshot-artifacts' 30 | path: '~/.m2/repository/' 31 | 32 | - name: Publish to the Maven Central 33 | run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository 34 | env: 35 | ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }} 36 | ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }} 37 | ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }} 38 | ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }} 39 | -------------------------------------------------------------------------------- /.github/workflows/publish-android-snashot.yml: -------------------------------------------------------------------------------- 1 | name: Publish Android Snapshot 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | workflow_dispatch: 8 | 9 | jobs: 10 | publish: 11 | name: Publish Snapshot 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Setup 18 | uses: ./.github/actions/setup-android 19 | 20 | - name: Publish to Maven Local 21 | run: ./gradlew publishToMavenLocal 22 | env: 23 | ORG_GRADLE_PROJECT_USE_SNAPSHOT: true 24 | 25 | - name: Upload Build Artifacts 26 | uses: actions/upload-artifact@v4 27 | with: 28 | name: 'snapshot-artifacts' 29 | path: '~/.m2/repository/' 30 | 31 | - name: Publish to the Snapshot Repository 32 | run: ./gradlew publishToSonatype 33 | env: 34 | ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }} 35 | ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }} 36 | ORG_GRADLE_PROJECT_USE_SNAPSHOT: true 37 | -------------------------------------------------------------------------------- /.github/workflows/publish-cocoapods-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish CocoaPods Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | publish: 11 | name: Publish to CocoaPods trunk 12 | runs-on: macos-13 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Setup 18 | uses: ./.github/actions/setup-apple 19 | 20 | - name: Publish Yoga 21 | run: pod trunk push Yoga.podspec 22 | env: 23 | COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} 24 | -------------------------------------------------------------------------------- /.github/workflows/publish-npm-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish NPM Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | publish: 11 | name: Publish to npmjs registry 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Setup 18 | uses: ./.github/actions/setup-js 19 | 20 | - name: Store auth token in config file 21 | run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc 22 | 23 | - name: yarn publish 24 | run: yarn publish 25 | working-directory: javascript 26 | -------------------------------------------------------------------------------- /.github/workflows/validate-android.yml: -------------------------------------------------------------------------------- 1 | name: Validate Android 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | - 'release-*' 9 | workflow_dispatch: 10 | 11 | jobs: 12 | build: 13 | name: Build [${{ matrix.os }}][${{ matrix.mode }}] 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | mode: [Debug, Release] 18 | os: [ubuntu-latest, windows-latest] 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | 23 | - name: Setup 24 | uses: ./.github/actions/setup-android 25 | 26 | - name: Build 27 | run: ./gradlew assemble${{ matrix.mode }} --stacktrace 28 | -------------------------------------------------------------------------------- /.github/workflows/validate-apple.yml: -------------------------------------------------------------------------------- 1 | name: Validate Apple 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | - 'release-*' 9 | workflow_dispatch: 10 | 11 | jobs: 12 | lint-pods: 13 | name: Build [CocoaPods] 14 | runs-on: macos-13 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Setup 20 | uses: ./.github/actions/setup-apple 21 | 22 | - name: pod lib lint 23 | run: pod lib lint --verbose --include-podspecs=**/*.podspec 24 | 25 | test: 26 | name: Build [SwiftPM] 27 | runs-on: macos-13 28 | 29 | steps: 30 | - uses: actions/checkout@v3 31 | 32 | - name: Setup 33 | uses: ./.github/actions/setup-apple 34 | 35 | - name: Build Debug 36 | run: swift build -c debug 37 | 38 | - name: Build Release 39 | run: swift build -c release 40 | -------------------------------------------------------------------------------- /.github/workflows/validate-tests.yml: -------------------------------------------------------------------------------- 1 | name: Validate Tests 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | workflow_dispatch: 9 | 10 | jobs: 11 | validate: 12 | name: Validate 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Setup JS 18 | uses: ./.github/actions/setup-js 19 | 20 | - name: yarn gentest-validate 21 | run: yarn gentest-validate 22 | 23 | - name: yarn gentest 24 | run: yarn gentest -h 25 | 26 | - name: Check for modified tests 27 | run: | 28 | if [[ -n $(git status -s) ]]; then 29 | git status -s 30 | echo "yarn gentest modified these tests. Please run yarn gentest to resolve." 31 | exit 1 32 | fi 33 | -------------------------------------------------------------------------------- /.github/workflows/validate-website.yml: -------------------------------------------------------------------------------- 1 | name: Validate Website 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | push: 8 | branches: 9 | - main 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build_next: 14 | name: Build 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Setup 21 | uses: ./.github/actions/setup-js 22 | 23 | - name: Restore emsdk 24 | uses: ./.github/actions/cache-emsdk 25 | 26 | - name: Build Website 27 | run: yarn build 28 | working-directory: website 29 | 30 | typecheck: 31 | name: Typecheck [Docusaurus] 32 | runs-on: ubuntu-latest 33 | 34 | steps: 35 | - uses: actions/checkout@v3 36 | 37 | - name: Setup 38 | uses: ./.github/actions/setup-js 39 | 40 | - name: yarn tsc 41 | run: yarn tsc 42 | working-directory: website 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | 3 | /buck-cache/ 4 | /buck-out/ 5 | /.buckconfig.local 6 | /.buckd 7 | /gentest/test.html 8 | .buck-java11 9 | node_modules 10 | 11 | # Jekyll 12 | /.sass-cache/ 13 | /_site/ 14 | 15 | # Visual studio code 16 | !.vscode 17 | 18 | *.pdb 19 | *.tlog 20 | *.obj 21 | *.pch 22 | *.log 23 | *.orig 24 | 25 | # Xcode 26 | ## Build generated 27 | build/ 28 | DerivedData/ 29 | 30 | ## Various settings 31 | *.pbxuser 32 | !default.pbxuser 33 | *.mode1v3 34 | !default.mode1v3 35 | *.mode2v3 36 | !default.mode2v3 37 | *.perspectivev3 38 | !default.perspectivev3 39 | xcuserdata/ 40 | 41 | ## Other 42 | *.moved-aside 43 | *.xcuserstate 44 | 45 | ## Obj-C/Swift specific 46 | *.hmap 47 | *.ipa 48 | *.dSYM.zip 49 | *.dSYM 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | Pods/ 58 | 59 | # Carthage 60 | # 61 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 62 | # Carthage/Checkouts 63 | 64 | Carthage/Build 65 | 66 | # Gradle 67 | .gradle 68 | local.properties 69 | 70 | # NDK/CMake 71 | .cxx 72 | .externalNativeBuild 73 | 74 | # Docusarus build 75 | .docusaurus 76 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/binaries/** 2 | **/build/** 3 | **/generated/** 4 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | module.exports = { 11 | arrowParens: 'avoid', 12 | bracketSameLine: true, 13 | bracketSpacing: false, 14 | singleQuote: true, 15 | trailingComma: 'all', 16 | }; 17 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.cpptools", 4 | "EditorConfig.EditorConfig", 5 | "dbaeumer.vscode-eslint", 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug C++ Unit tests (lldb)", 9 | "type": "cppdbg", 10 | "MIMode": "lldb", 11 | "request": "launch", 12 | "program": "${workspaceFolder}/tests/build/yogatests", 13 | "cwd": "${workspaceFolder}", 14 | "preLaunchTask": "Build Unit Tests" 15 | }, 16 | { 17 | "name": "Debug C++ Unit tests (vsdbg)", 18 | "type": "cppvsdbg", 19 | "request": "launch", 20 | "program": "${workspaceFolder}/tests/build/yogatests", 21 | "cwd": "${workspaceFolder}", 22 | "preLaunchTask": "Build Unit Tests" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.codeActionsOnSave": { 4 | "source.fixAll.eslint": true 5 | }, 6 | "eslint.format.enable": true, 7 | "eslint.packageManager": "yarn", 8 | "eslint.enable": true, 9 | "eslint.validate": [ 10 | "javascript", 11 | "javascriptreact", 12 | "typescript", 13 | "typescriptreact" 14 | ], 15 | "eslint.workingDirectories": [ 16 | { 17 | "mode": "auto" 18 | } 19 | ], 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Build Unit Tests", 8 | "type": "shell", 9 | "command": "(which ninja && cmake -B build -S . -D CMAKE_BUILD_TYPE=Debug -G Ninja || cmake -B build -S . -D CMAKE_BUILD_TYPE=Debug) && cmake --build build", 10 | "windows": { 11 | "command": "(where ninja && cmake -B build -S . -D CMAKE_BUILD_TYPE=Debug -G Ninja || cmake -B build -S . -D CMAKE_BUILD_TYPE=Debug) && cmake --build build", 12 | }, 13 | "group": "build", 14 | "options": { 15 | "cwd": "tests" 16 | }, 17 | "presentation": { 18 | "reveal": "always", 19 | "panel": "new" 20 | } 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | cmake_minimum_required(VERSION 3.13...3.26) 7 | project(yoga-all) 8 | set(CMAKE_VERBOSE_MAKEFILE on) 9 | 10 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/project-defaults.cmake) 11 | 12 | add_subdirectory(yoga) 13 | add_subdirectory(tests) 14 | 15 | option(BUILD_FUZZ_TESTS "Build fuzz tests" OFF) 16 | 17 | if ('${CMAKE_CXX_COMPILER_ID}' MATCHES 'Clang' AND BUILD_FUZZ_TESTS) 18 | add_subdirectory(fuzz) 19 | endif() 20 | 21 | # cmake install config 22 | include(GNUInstallDirs) 23 | include(CMakePackageConfigHelpers) 24 | 25 | # declare target to install 26 | install(TARGETS yogacore EXPORT yoga-targets 27 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 28 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 29 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 30 | ) 31 | 32 | # install header files 33 | install(DIRECTORY 34 | "${CMAKE_CURRENT_LIST_DIR}/yoga" 35 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 36 | FILES_MATCHING PATTERN "*.h" 37 | ) 38 | 39 | # install target config 40 | install(EXPORT yoga-targets 41 | FILE yogaTargets.cmake 42 | NAMESPACE yoga:: 43 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/yoga 44 | ) 45 | 46 | 47 | # generate config file 48 | configure_package_config_file( 49 | ${CMAKE_CURRENT_SOURCE_DIR}/cmake/yoga-config.cmake.in 50 | ${CMAKE_CURRENT_BINARY_DIR}/yogaConfig.cmake 51 | INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/yoga 52 | ) 53 | 54 | # install config file 55 | install(FILES 56 | ${CMAKE_CURRENT_BINARY_DIR}/yogaConfig.cmake 57 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/yoga 58 | ) 59 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to yoga 2 | We want to make contributing to this project as easy and transparent as 3 | possible. 4 | 5 | ## Code of Conduct 6 | 7 | Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.fb.com/codeofconduct/) so that you can understand what actions will and will not be tolerated. 8 | 9 | ## Pull Requests 10 | We actively welcome your pull requests. 11 | 1. Fork the repo and create your branch from `main`. 12 | 2. If you've added code that should be tested, add tests 13 | 3. If you've changed APIs, update the documentation. 14 | 4. Ensure the test suite passes. 15 | 5. Make sure your code lints. 16 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 17 | 18 | ## Contributor License Agreement ("CLA") 19 | In order to accept your pull request, we need you to submit a CLA. You only need 20 | to do this once to work on any of Facebook's open source projects. 21 | 22 | Complete your CLA here: 23 | 24 | ## Issues 25 | We use GitHub issues to track public bugs. Please ensure your description is 26 | clear and has sufficient instructions to be able to reproduce the issue. 27 | 28 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 29 | disclosure of security bugs. In those cases, please go through the process 30 | outlined on that page and do not file a public issue. 31 | 32 | ## License 33 | By contributing to yoga, you agree that your contributions will be licensed 34 | under its MIT license. 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Facebook, Inc. and its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE-examples: -------------------------------------------------------------------------------- 1 | The examples provided by Facebook are for non-commercial testing and evaluation 2 | purposes only. Facebook reserves all rights not expressly granted. 3 | 4 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 5 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 7 | FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 8 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 9 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | /* 4 | * Copyright (c) Meta Platforms, Inc. and affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 11 | import PackageDescription 12 | 13 | let package = Package( 14 | name: "yoga", 15 | products: [ 16 | .library(name: "yoga", targets: [ "core" ]) 17 | ], 18 | targets: [ 19 | .target( 20 | name: "core", 21 | path: ".", 22 | sources: [ 23 | "yoga" 24 | ], 25 | publicHeadersPath: ".", 26 | cxxSettings: [ 27 | .headerSearchPath(".") 28 | ] 29 | ) 30 | ], 31 | cxxLanguageStandard: CXXLanguageStandard(rawValue: "c++20") 32 | ) 33 | -------------------------------------------------------------------------------- /Yoga.podspec: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | 7 | Pod::Spec.new do |spec| 8 | spec.name = 'Yoga' 9 | spec.version = '0.0.0' 10 | spec.license = { :type => 'MIT', :file => "LICENSE" } 11 | spec.homepage = 'https://yogalayout.dev/' 12 | spec.documentation_url = 'https://yogalayout.dev/docs' 13 | 14 | spec.summary = 'An embeddable and performant flexbox layout engine with bindings for multiple languages' 15 | 16 | spec.authors = {'Meta Open Source' => 'opensource@meta.com'} 17 | spec.source = { 18 | :git => 'https://github.com/facebook/yoga.git', 19 | :tag => "v#{spec.version.to_s}", 20 | } 21 | 22 | spec.ios.deployment_target = "13.4" 23 | 24 | spec.module_name = 'yoga' 25 | spec.requires_arc = false 26 | spec.pod_target_xcconfig = { 27 | 'DEFINES_MODULE' => 'YES', 28 | 'HEADER_SEARCH_PATHS' => '"$(PODS_TARGET_SRCROOT)"', 29 | } 30 | 31 | spec.compiler_flags = [ 32 | '-fno-omit-frame-pointer', 33 | '-fexceptions', 34 | '-Wall', 35 | '-Werror', 36 | '-std=c++20', 37 | '-fPIC' 38 | ] 39 | 40 | spec.swift_version = '5.1' 41 | spec.source_files = 'yoga/**/*.{h,cpp}' 42 | spec.header_mappings_dir = 'yoga' 43 | 44 | public_header_files = 'yoga/*.h' 45 | spec.public_header_files = public_header_files 46 | 47 | all_header_files = 'yoga/**/*.h' 48 | spec.private_header_files = Dir.glob(all_header_files) - Dir.glob(public_header_files) 49 | spec.preserve_paths = [all_header_files] 50 | end 51 | -------------------------------------------------------------------------------- /benchmark/Benchmark.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | namespace facebook::yoga { 19 | 20 | struct YogaNodeAndConfig { 21 | YogaNodeAndConfig( 22 | std::shared_ptr node, 23 | std::shared_ptr config, 24 | std::vector> children) 25 | : node_(std::move(node)), 26 | config_(std::move(config)), 27 | children_(std::move(children)) {} 28 | 29 | std::shared_ptr node_; 30 | std::shared_ptr config_; 31 | std::vector> children_; 32 | }; 33 | 34 | struct BenchmarkResult { 35 | std::chrono::steady_clock::duration treeCreationDuration; 36 | std::chrono::steady_clock::duration layoutDuration; 37 | }; 38 | 39 | } // namespace facebook::yoga 40 | -------------------------------------------------------------------------------- /benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | cmake_minimum_required(VERSION 3.13...3.26) 7 | project(benchmark) 8 | set(CMAKE_VERBOSE_MAKEFILE on) 9 | 10 | set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 11 | include(${YOGA_ROOT}/cmake/project-defaults.cmake) 12 | 13 | add_subdirectory(${YOGA_ROOT}/yoga ${CMAKE_CURRENT_BINARY_DIR}/yoga) 14 | 15 | file(GLOB SOURCES_LEGACY CONFIGURE_DEPENDS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 17 | file(GLOB SOURCES CONFIGURE_DEPENDS 18 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 19 | 20 | add_executable(benchmark ${SOURCES}) 21 | add_executable(benchmarklegacy ${SOURCES_LEGACY}) 22 | 23 | target_link_libraries(benchmark yogacore) 24 | target_link_libraries(benchmarklegacy yogacore) 25 | target_include_directories(benchmark 26 | PRIVATE 27 | $) 28 | -------------------------------------------------------------------------------- /benchmark/TreeDeserialization.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace facebook::yoga { 18 | 19 | using namespace nlohmann; 20 | 21 | YGFlexDirection flexDirectionFromString(const std::string& str); 22 | 23 | YGJustify justifyContentFromString(const std::string& str); 24 | 25 | YGAlign alignFromString(const std::string& str); 26 | 27 | YGWrap wrapFromString(const std::string& str); 28 | 29 | YGOverflow overflowFromString(const std::string& str); 30 | 31 | YGDisplay displayFromString(const std::string& str); 32 | 33 | YGPositionType positionTypeFromString(const std::string& str); 34 | 35 | YGUnit unitFromJson(json& j); 36 | 37 | YGEdge edgeFromString(const std::string& str); 38 | 39 | YGErrata errataFromString(const std::string& str); 40 | 41 | YGExperimentalFeature experimentalFeatureFromString(const std::string& str); 42 | 43 | std::string edgeStringFromPropertyName( 44 | const json::iterator& it, 45 | const std::string& propertyName); 46 | 47 | YGDirection directionFromString(const std::string& str); 48 | 49 | YGMeasureMode measureModeFromString(const std::string& str); 50 | 51 | SerializedMeasureFunc serializedMeasureFuncFromJson(json& j); 52 | } // namespace facebook::yoga 53 | -------------------------------------------------------------------------------- /benchmark/benchmark: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | cd "$(dirname "$0")" || exit 7 | CAPTURES_PATH="$(dirname "$(realpath "$0")")""/captures" 8 | 9 | if [ "$1" = "buck" ]; then 10 | buck run @//fbcode/mode/opt :benchmarkCXX "${CAPTURES_PATH}" 11 | else 12 | cmake -B build -S . -D CMAKE_BUILD_TYPE=Release 13 | cmake --build build 14 | build/benchmark "${CAPTURES_PATH}" 15 | fi 16 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | plugins { 9 | id("com.android.library") version "8.7.1" apply false 10 | id("com.android.application") version "8.7.1" apply false 11 | id("io.github.gradle-nexus.publish-plugin") version "1.3.0" 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | group = "com.facebook.yoga" 22 | 23 | if (project.hasProperty("USE_SNAPSHOT") && project.property("USE_SNAPSHOT").toBoolean()) { 24 | version = getProperty("VERSION_NAME") + "-SNAPSHOT" 25 | } else { 26 | version = getProperty("VERSION_NAME") 27 | } 28 | 29 | def sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString() 30 | def sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString() 31 | 32 | nexusPublishing { 33 | repositories { 34 | sonatype { 35 | username.set(sonatypeUsername) 36 | password.set(sonatypePassword) 37 | } 38 | } 39 | } 40 | 41 | task clean(type: Delete) { 42 | delete rootProject.buildDir 43 | } 44 | -------------------------------------------------------------------------------- /build_fuzz_tests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if [ "$#" -eq 0 ]; then 8 | build_type="Debug" 9 | else 10 | build_type="$1" 11 | fi 12 | 13 | export CC=clang 14 | export CXX=clang++ 15 | 16 | # Make sure libc++ isn't used, as libfuzzer is linked against stdlibc++ which causes conflicts 17 | unset CXXFLAGS 18 | export LDFLAGS=-lstdc++ 19 | 20 | if which ninja; then 21 | set -e 22 | cmake -B build -S . -D BUILD_FUZZ_TESTS=ON -D CMAKE_BUILD_TYPE="$build_type" -G Ninja 23 | else 24 | set -e 25 | cmake -B build -S . -D BUILD_FUZZ_TESTS=ON -D CMAKE_BUILD_TYPE="$build_type" 26 | fi 27 | 28 | cmake --build build --target fuzz_layout 29 | -------------------------------------------------------------------------------- /capture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | cmake_minimum_required(VERSION 3.13...3.26) 7 | project(capture) 8 | set(CMAKE_VERBOSE_MAKEFILE on) 9 | 10 | set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 11 | include(${YOGA_ROOT}/cmake/project-defaults.cmake) 12 | 13 | add_subdirectory(${YOGA_ROOT}/yoga ${CMAKE_CURRENT_BINARY_DIR}/yoga) 14 | 15 | file(GLOB SOURCES CONFIGURE_DEPENDS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 17 | add_library(capture STATIC ${SOURCES}) 18 | 19 | target_link_libraries(capture yogacore) 20 | target_include_directories(capture 21 | PUBLIC 22 | $ 23 | $) 24 | -------------------------------------------------------------------------------- /capture/CaptureTree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | struct SerializedMeasureFunc { 19 | float inputWidth{0.0f}; 20 | YGMeasureMode widthMode{YGMeasureModeUndefined}; 21 | float inputHeight{0.0}; 22 | YGMeasureMode heightMode{YGMeasureModeUndefined}; 23 | float outputWidth{0.0f}; 24 | float outputHeight{0.0f}; 25 | std::chrono::steady_clock::duration::rep durationNs{}; 26 | }; 27 | 28 | using SerializedMeasureFuncMap = 29 | std::unordered_map>; 30 | 31 | void YGNodeCalculateLayoutWithCapture( 32 | YGNodeRef node, 33 | float availableWidth, 34 | float availableHeight, 35 | YGDirection ownerDirection, 36 | const std::filesystem::path& path); 37 | 38 | void captureMeasureFunc( 39 | YGNodeConstRef node, 40 | float width, 41 | YGMeasureMode widthMode, 42 | float height, 43 | YGMeasureMode heightMode, 44 | YGSize output, 45 | std::chrono::steady_clock::duration durationNs); 46 | 47 | } // namespace facebook::yoga 48 | -------------------------------------------------------------------------------- /capture/NodeToString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace facebook::yoga { 18 | 19 | enum class PrintOptions : uint8_t { 20 | Layout = 1 << 0, 21 | Children = 1 << 1, 22 | Style = 1 << 2, 23 | Config = 1 << 3, 24 | Node = 1 << 4, 25 | }; 26 | YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions); 27 | 28 | void serializeTree( 29 | nlohmann::json& j, 30 | SerializedMeasureFuncMap& nodesToMeasureFuncs, 31 | YGNodeRef node, 32 | PrintOptions options); 33 | 34 | void serializeLayoutInputs( 35 | nlohmann::json& j, 36 | float availableWidth, 37 | float availableHeight, 38 | YGDirection ownerDirection); 39 | 40 | } // namespace facebook::yoga 41 | -------------------------------------------------------------------------------- /cmake/project-defaults.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | set(CMAKE_CXX_STANDARD 20) 7 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) 8 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 9 | 10 | add_compile_definitions($<$:DEBUG>) 11 | 12 | if(MSVC) 13 | 14 | add_compile_options( 15 | # Don't omit frame pointers (e.g. for crash dumps) 16 | /Oy- 17 | # "Standard C++ exception handling" (C++ stack unwinding including extern c) 18 | /EHsc 19 | # Enable warnings and warnings as errors 20 | /W4 21 | /WX 22 | # Enable RTTI 23 | $<$:/GR> 24 | # Use /O2 (Maximize Speed) 25 | $<$:/O2>) 26 | 27 | else() 28 | 29 | add_compile_options( 30 | # Don't omit frame pointers (e.g. for crash dumps) 31 | -fno-omit-frame-pointer 32 | # Enable exception handling 33 | -fexceptions 34 | # Enable warnings and warnings as errors 35 | -Wall 36 | -Werror 37 | # Enable RTTI 38 | $<$:-frtti> 39 | # Use -O2 (prioritize speed) 40 | $<$:-O2> 41 | # Enable separate sections per function/data item 42 | $<$:-ffunction-sections> 43 | $<$:-fdata-sections>) 44 | 45 | add_link_options( 46 | # Discard unused sections 47 | $<$:$<$:-Wl,--gc-sections>> 48 | $<$:$<$:-Wl,-dead_strip>>) 49 | 50 | endif() 51 | -------------------------------------------------------------------------------- /cmake/yoga-config.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | @PACKAGE_INIT@ 7 | 8 | include("${CMAKE_CURRENT_LIST_DIR}/yogaTargets.cmake") 9 | 10 | check_required_components(yoga) -------------------------------------------------------------------------------- /fuzz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | # If google/oss-fuzz has set the fuzzing engine 7 | if(DEFINED ENV{LIB_FUZZING_ENGINE}) 8 | set(FUZZING_ENGINE $ENV{LIB_FUZZING_ENGINE}) 9 | set(FUZZING_COMPILE_FLAGS "") 10 | set(FUZZING_LINK_FLAGS "${FUZZING_ENGINE}") 11 | else() 12 | set(FUZZING_COMPILE_FLAGS "-fsanitize=fuzzer") 13 | set(FUZZING_LINK_FLAGS "-fsanitize=fuzzer") 14 | endif() 15 | 16 | add_executable(fuzz_layout FuzzLayout.cpp) 17 | set_target_properties(fuzz_layout PROPERTIES 18 | COMPILE_FLAGS "${FUZZING_COMPILE_FLAGS}" 19 | LINK_FLAGS "${FUZZING_LINK_FLAGS}" 20 | ) 21 | target_link_libraries(fuzz_layout yogacore) 22 | -------------------------------------------------------------------------------- /gentest/babel.config.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | module.exports = { 11 | presets: ['@babel/preset-typescript'], 12 | }; 13 | -------------------------------------------------------------------------------- /gentest/fixtures/YGAlignSelfTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | 18 |
19 |
20 |
21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /gentest/fixtures/YGAspectRatioTest.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 | -------------------------------------------------------------------------------- /gentest/fixtures/YGAutoTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 |
22 | 23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /gentest/fixtures/YGBorderTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 |
14 |
15 | 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /gentest/fixtures/YGDimensionTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 |
9 |
10 | -------------------------------------------------------------------------------- /gentest/fixtures/YGPaddingTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 |
14 |
15 | 16 |
18 |
19 |
20 | 21 |
23 |
24 |
25 | 26 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /gentest/fixtures/YGSizeOverflowTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /gentest/fonts/Ahem.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/gentest/fonts/Ahem.ttf -------------------------------------------------------------------------------- /gentest/gentest-log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // eslint-disable-next-line no-unused-vars 9 | function gentestLog(message) { 10 | console.log('gentest-log: ', message); 11 | } 12 | -------------------------------------------------------------------------------- /gentest/gentest-validate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | import * as fs from 'node:fs/promises'; 11 | import {dirname} from 'path'; 12 | import {fileURLToPath} from 'url'; 13 | import signedsource from 'signedsource'; 14 | import {glob} from 'glob'; 15 | 16 | const yogaRootDir = dirname(dirname(fileURLToPath(import.meta.url))); 17 | 18 | const filesToValidate = await glob( 19 | [ 20 | 'tests/generated/**/*.{h,cpp}', 21 | 'javascript/tests/generated/**/*.test.ts', 22 | 'java/tests/generated/com/facebook/yoga/**/*.java', 23 | ], 24 | { 25 | cwd: yogaRootDir, 26 | }, 27 | ); 28 | 29 | console.log(`Found ${filesToValidate.length} files to validate`); 30 | 31 | for (const file of filesToValidate) { 32 | const content = await fs.readFile(`${yogaRootDir}/${file}`, 'utf8'); 33 | if (signedsource.isSigned(content)) { 34 | console.log(`Checking ${file}`); 35 | const validSignature = signedsource.verifySignature(content); 36 | if (!validSignature) { 37 | console.error(`Invalid signature "${file}"`); 38 | process.exitCode = 1; 39 | } 40 | } else { 41 | console.log(`Skipped ${file}`); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /gentest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gentest", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "gentest": "node --disable-warning=ExperimentalWarning --loader=babel-register-esm ./gentest-driver.ts", 7 | "gentest-validate": "node --disable-warning=ExperimentalWarning --loader=babel-register-esm ./gentest-validate.ts" 8 | }, 9 | "type": "module", 10 | "dependencies": { 11 | "minimist": "^1.2.8", 12 | "selenium-webdriver": "^4.16.0", 13 | "signedsource": "^2.0.0" 14 | }, 15 | "devDependencies": { 16 | "@babel/core": "^7.23.0", 17 | "@babel/preset-typescript": "^7.23.0", 18 | "@tsconfig/node18": "^18.2.2", 19 | "@types/minimist": "^1.2.5", 20 | "@types/node": "^20.10.3", 21 | "@types/selenium-webdriver": "^4.1.21", 22 | "babel-register-esm": "^1.2.5", 23 | "glob": "^10.4.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gentest/signedsource.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | declare module 'signedsource'; 11 | -------------------------------------------------------------------------------- /gentest/test-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %s 7 | 8 | 9 | 10 | 11 | 12 | 13 | 56 | 57 | 58 | 59 |
60 | 61 | %s 62 | 63 |
64 |
65 |
66 | 67 | %s 68 | 69 |
70 |
71 | 72 |
73 | 74 | %s 75 | 76 |
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /gentest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node18/tsconfig.json", 3 | "compilerOptions": { 4 | "noEmit": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) Facebook, Inc. and its affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the LICENSE 5 | # file in the root directory of this source tree. 6 | # 7 | 8 | # Project-wide Gradle settings. 9 | 10 | android.useAndroidX=true 11 | 12 | org.gradle.jvmargs=-Xmx1536M 13 | 14 | VERSION_NAME=0.0.0 15 | -------------------------------------------------------------------------------- /gradle/gradle-enterprise.gradle.kts.sample: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // You can use this script to configure the gradleEnterprise{} block in your build. 9 | // You need to rename this file to ./gradle/gradle-enterprise.gradle.kts in order for 10 | // this to be processed. 11 | extensions.getByName("gradleEnterprise").withGroovyBuilder { 12 | setProperty("server", "https://your-gradle-enterprise-instance.example.com") 13 | getProperty("buildScan").withGroovyBuilder { 14 | "publishAlways"() 15 | "tag"(if(System.getenv("CI") != null) "CI" else "Local") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /java/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | cmake_minimum_required(VERSION 3.13...3.26) 7 | project(yogajni) 8 | set(CMAKE_VERBOSE_MAKEFILE on) 9 | 10 | set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 11 | include(${YOGA_ROOT}/cmake/project-defaults.cmake) 12 | 13 | add_subdirectory(${YOGA_ROOT}/yoga ${CMAKE_CURRENT_BINARY_DIR}/yoga) 14 | 15 | file(GLOB SOURCES CONFIGURE_DEPENDS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/jni/*.cpp) 17 | file(GLOB VERSION_SCRIPT CONFIGURE_DEPENDS 18 | ${CMAKE_CURRENT_SOURCE_DIR}/yogajni.version) 19 | 20 | add_library(yoga SHARED ${SOURCES}) 21 | target_link_libraries(yoga yogacore) 22 | target_link_options(yoga PRIVATE -Wl,--version-script=${VERSION_SCRIPT}) 23 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/LayoutPassReason.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public enum LayoutPassReason { 11 | INITIAL(0), 12 | ABS_LAYOUT(1), 13 | STRETCH(2), 14 | MULTILINE_STRETCH(3), 15 | FLEX_LAYOUT(4), 16 | MEASURE(5), 17 | ABS_MEASURE(6), 18 | FLEX_MEASURE(7); 19 | 20 | private final int mIntValue; 21 | 22 | LayoutPassReason(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static LayoutPassReason fromInt(int value) { 31 | switch (value) { 32 | case 0: return INITIAL; 33 | case 1: return ABS_LAYOUT; 34 | case 2: return STRETCH; 35 | case 3: return MULTILINE_STRETCH; 36 | case 4: return FLEX_LAYOUT; 37 | case 5: return MEASURE; 38 | case 6: return ABS_MEASURE; 39 | case 7: return FLEX_MEASURE; 40 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaAlign.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaAlign { 13 | AUTO(0), 14 | FLEX_START(1), 15 | CENTER(2), 16 | FLEX_END(3), 17 | STRETCH(4), 18 | BASELINE(5), 19 | SPACE_BETWEEN(6), 20 | SPACE_AROUND(7), 21 | SPACE_EVENLY(8); 22 | 23 | private final int mIntValue; 24 | 25 | YogaAlign(int intValue) { 26 | mIntValue = intValue; 27 | } 28 | 29 | public int intValue() { 30 | return mIntValue; 31 | } 32 | 33 | public static YogaAlign fromInt(int value) { 34 | switch (value) { 35 | case 0: return AUTO; 36 | case 1: return FLEX_START; 37 | case 2: return CENTER; 38 | case 3: return FLEX_END; 39 | case 4: return STRETCH; 40 | case 5: return BASELINE; 41 | case 6: return SPACE_BETWEEN; 42 | case 7: return SPACE_AROUND; 43 | case 8: return SPACE_EVENLY; 44 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaBaselineFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public interface YogaBaselineFunction { 11 | /** 12 | * Return the baseline of the node in points. When no baseline function is set the baseline 13 | * default to the computed height of the node. 14 | */ 15 | float baseline(YogaNode node, float width, float height); 16 | } 17 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaBoxSizing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaBoxSizing { 13 | BORDER_BOX(0), 14 | CONTENT_BOX(1); 15 | 16 | private final int mIntValue; 17 | 18 | YogaBoxSizing(int intValue) { 19 | mIntValue = intValue; 20 | } 21 | 22 | public int intValue() { 23 | return mIntValue; 24 | } 25 | 26 | public static YogaBoxSizing fromInt(int value) { 27 | switch (value) { 28 | case 0: return BORDER_BOX; 29 | case 1: return CONTENT_BOX; 30 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public abstract class YogaConfig { 11 | 12 | public static int SPACING_TYPE = 1; 13 | 14 | public abstract void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled); 15 | 16 | public abstract void setUseWebDefaults(boolean useWebDefaults); 17 | 18 | public abstract void setPointScaleFactor(float pixelsInPoint); 19 | 20 | public abstract void setErrata(YogaErrata errata); 21 | 22 | public abstract YogaErrata getErrata(); 23 | 24 | public abstract void setLogger(YogaLogger logger); 25 | 26 | public abstract YogaLogger getLogger(); 27 | 28 | protected abstract long getNativePointer(); 29 | } 30 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaConfigFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public abstract class YogaConfigFactory { 11 | public static YogaConfig create() { 12 | return new YogaConfigJNIFinalizer(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaConfigJNIFinalizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public class YogaConfigJNIFinalizer extends YogaConfigJNIBase { 11 | public YogaConfigJNIFinalizer() { 12 | super(); 13 | } 14 | 15 | @Override 16 | protected void finalize() throws Throwable { 17 | try { 18 | freeNatives(); 19 | } finally { 20 | super.finalize(); 21 | } 22 | } 23 | 24 | public void freeNatives() { 25 | if (mNativePointer != 0) { 26 | long nativePointer = mNativePointer; 27 | mNativePointer = 0; 28 | YogaNative.jni_YGConfigFreeJNI(nativePointer); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public class YogaConstants { 11 | 12 | public static final float UNDEFINED = Float.NaN; 13 | 14 | public static boolean isUndefined(float value) { 15 | return Float.compare(value, UNDEFINED) == 0; 16 | } 17 | 18 | public static boolean isUndefined(YogaValue value) { 19 | return value.unit == YogaUnit.UNDEFINED; 20 | } 21 | 22 | public static float getUndefined() { 23 | return UNDEFINED; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaDimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaDimension { 13 | WIDTH(0), 14 | HEIGHT(1); 15 | 16 | private final int mIntValue; 17 | 18 | YogaDimension(int intValue) { 19 | mIntValue = intValue; 20 | } 21 | 22 | public int intValue() { 23 | return mIntValue; 24 | } 25 | 26 | public static YogaDimension fromInt(int value) { 27 | switch (value) { 28 | case 0: return WIDTH; 29 | case 1: return HEIGHT; 30 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaDirection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaDirection { 13 | INHERIT(0), 14 | LTR(1), 15 | RTL(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaDirection(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaDirection fromInt(int value) { 28 | switch (value) { 29 | case 0: return INHERIT; 30 | case 1: return LTR; 31 | case 2: return RTL; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaDisplay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaDisplay { 13 | FLEX(0), 14 | NONE(1), 15 | CONTENTS(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaDisplay(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaDisplay fromInt(int value) { 28 | switch (value) { 29 | case 0: return FLEX; 30 | case 1: return NONE; 31 | case 2: return CONTENTS; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaEdge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaEdge { 13 | LEFT(0), 14 | TOP(1), 15 | RIGHT(2), 16 | BOTTOM(3), 17 | START(4), 18 | END(5), 19 | HORIZONTAL(6), 20 | VERTICAL(7), 21 | ALL(8); 22 | 23 | private final int mIntValue; 24 | 25 | YogaEdge(int intValue) { 26 | mIntValue = intValue; 27 | } 28 | 29 | public int intValue() { 30 | return mIntValue; 31 | } 32 | 33 | public static YogaEdge fromInt(int value) { 34 | switch (value) { 35 | case 0: return LEFT; 36 | case 1: return TOP; 37 | case 2: return RIGHT; 38 | case 3: return BOTTOM; 39 | case 4: return START; 40 | case 5: return END; 41 | case 6: return HORIZONTAL; 42 | case 7: return VERTICAL; 43 | case 8: return ALL; 44 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaErrata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaErrata { 13 | NONE(0), 14 | STRETCH_FLEX_BASIS(1), 15 | ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING(2), 16 | ABSOLUTE_PERCENT_AGAINST_INNER_SIZE(4), 17 | ALL(2147483647), 18 | CLASSIC(2147483646); 19 | 20 | private final int mIntValue; 21 | 22 | YogaErrata(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static YogaErrata fromInt(int value) { 31 | switch (value) { 32 | case 0: return NONE; 33 | case 1: return STRETCH_FLEX_BASIS; 34 | case 2: return ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING; 35 | case 4: return ABSOLUTE_PERCENT_AGAINST_INNER_SIZE; 36 | case 2147483647: return ALL; 37 | case 2147483646: return CLASSIC; 38 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaExperimentalFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaExperimentalFeature { 13 | WEB_FLEX_BASIS(0); 14 | 15 | private final int mIntValue; 16 | 17 | YogaExperimentalFeature(int intValue) { 18 | mIntValue = intValue; 19 | } 20 | 21 | public int intValue() { 22 | return mIntValue; 23 | } 24 | 25 | public static YogaExperimentalFeature fromInt(int value) { 26 | switch (value) { 27 | case 0: return WEB_FLEX_BASIS; 28 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaFlexDirection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaFlexDirection { 13 | COLUMN(0), 14 | COLUMN_REVERSE(1), 15 | ROW(2), 16 | ROW_REVERSE(3); 17 | 18 | private final int mIntValue; 19 | 20 | YogaFlexDirection(int intValue) { 21 | mIntValue = intValue; 22 | } 23 | 24 | public int intValue() { 25 | return mIntValue; 26 | } 27 | 28 | public static YogaFlexDirection fromInt(int value) { 29 | switch (value) { 30 | case 0: return COLUMN; 31 | case 1: return COLUMN_REVERSE; 32 | case 2: return ROW; 33 | case 3: return ROW_REVERSE; 34 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaGutter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaGutter { 13 | COLUMN(0), 14 | ROW(1), 15 | ALL(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaGutter(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaGutter fromInt(int value) { 28 | switch (value) { 29 | case 0: return COLUMN; 30 | case 1: return ROW; 31 | case 2: return ALL; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaJustify.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaJustify { 13 | FLEX_START(0), 14 | CENTER(1), 15 | FLEX_END(2), 16 | SPACE_BETWEEN(3), 17 | SPACE_AROUND(4), 18 | SPACE_EVENLY(5); 19 | 20 | private final int mIntValue; 21 | 22 | YogaJustify(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static YogaJustify fromInt(int value) { 31 | switch (value) { 32 | case 0: return FLEX_START; 33 | case 1: return CENTER; 34 | case 2: return FLEX_END; 35 | case 3: return SPACE_BETWEEN; 36 | case 4: return SPACE_AROUND; 37 | case 5: return SPACE_EVENLY; 38 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaLayoutType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public enum YogaLayoutType { 11 | LAYOUT(0), 12 | MEASURE(1), 13 | CACHED_LAYOUT(2), 14 | CACHED_MEASURE(3); 15 | 16 | private final int mIntValue; 17 | 18 | YogaLayoutType(int intValue) { 19 | mIntValue = intValue; 20 | } 21 | 22 | public int intValue() { 23 | return mIntValue; 24 | } 25 | 26 | public static YogaLayoutType fromInt(int value) { 27 | switch (value) { 28 | case 0: return LAYOUT; 29 | case 1: return MEASURE; 30 | case 2: return CACHED_LAYOUT; 31 | case 3: return CACHED_MEASURE; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaLogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | import com.facebook.yoga.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum YogaLogLevel { 16 | ERROR(0), 17 | WARN(1), 18 | INFO(2), 19 | DEBUG(3), 20 | VERBOSE(4), 21 | FATAL(5); 22 | 23 | private final int mIntValue; 24 | 25 | YogaLogLevel(int intValue) { 26 | mIntValue = intValue; 27 | } 28 | 29 | public int intValue() { 30 | return mIntValue; 31 | } 32 | 33 | @DoNotStrip 34 | public static YogaLogLevel fromInt(int value) { 35 | switch (value) { 36 | case 0: return ERROR; 37 | case 1: return WARN; 38 | case 2: return INFO; 39 | case 3: return DEBUG; 40 | case 4: return VERBOSE; 41 | case 5: return FATAL; 42 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | import com.facebook.yoga.annotations.DoNotStrip; 11 | 12 | /** 13 | * Interface for receiving logs from native layer. Use by setting YogaNode.setLogger(myLogger); 14 | * See YogaLogLevel for the different log levels. 15 | */ 16 | @DoNotStrip 17 | public interface YogaLogger { 18 | @DoNotStrip 19 | void log(YogaLogLevel level, String message); 20 | } 21 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaMeasureFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public interface YogaMeasureFunction { 11 | /** 12 | * Return a value created by YogaMeasureOutput.make(width, height); 13 | */ 14 | long measure( 15 | YogaNode node, 16 | float width, 17 | YogaMeasureMode widthMode, 18 | float height, 19 | YogaMeasureMode heightMode); 20 | } 21 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaMeasureMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaMeasureMode { 13 | UNDEFINED(0), 14 | EXACTLY(1), 15 | AT_MOST(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaMeasureMode(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaMeasureMode fromInt(int value) { 28 | switch (value) { 29 | case 0: return UNDEFINED; 30 | case 1: return EXACTLY; 31 | case 2: return AT_MOST; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaMeasureOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | /** 11 | * Helpers for building measure output value. 12 | */ 13 | public class YogaMeasureOutput { 14 | 15 | public static long make(float width, float height) { 16 | final int wBits = Float.floatToRawIntBits(width); 17 | final int hBits = Float.floatToRawIntBits(height); 18 | return ((long) wBits) << 32 | ((long) hBits); 19 | } 20 | 21 | public static long make(int width, int height) { 22 | return make((float) width, (float) height); 23 | } 24 | 25 | public static float getWidth(long measureOutput) { 26 | return Float.intBitsToFloat((int) (0xFFFFFFFF & (measureOutput >> 32))); 27 | } 28 | 29 | public static float getHeight(long measureOutput) { 30 | return Float.intBitsToFloat((int) (0xFFFFFFFF & measureOutput)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaNodeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public abstract class YogaNodeFactory { 11 | public static YogaNode create() { 12 | return new YogaNodeJNIFinalizer(); 13 | } 14 | 15 | public static YogaNode create(YogaConfig config) { 16 | return new YogaNodeJNIFinalizer(config); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaNodeJNIFinalizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | public class YogaNodeJNIFinalizer extends YogaNodeJNIBase { 11 | public YogaNodeJNIFinalizer() { 12 | super(); 13 | } 14 | 15 | public YogaNodeJNIFinalizer(YogaConfig config) { 16 | super(config); 17 | } 18 | 19 | @Override 20 | protected void finalize() throws Throwable { 21 | try { 22 | freeNatives(); 23 | } finally { 24 | super.finalize(); 25 | } 26 | } 27 | 28 | public void freeNatives() { 29 | if (mNativePointer != 0) { 30 | long nativePointer = mNativePointer; 31 | mNativePointer = 0; 32 | YogaNative.jni_YGNodeFinalizeJNI(nativePointer); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaNodeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaNodeType { 13 | DEFAULT(0), 14 | TEXT(1); 15 | 16 | private final int mIntValue; 17 | 18 | YogaNodeType(int intValue) { 19 | mIntValue = intValue; 20 | } 21 | 22 | public int intValue() { 23 | return mIntValue; 24 | } 25 | 26 | public static YogaNodeType fromInt(int value) { 27 | switch (value) { 28 | case 0: return DEFAULT; 29 | case 1: return TEXT; 30 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaOverflow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaOverflow { 13 | VISIBLE(0), 14 | HIDDEN(1), 15 | SCROLL(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaOverflow(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaOverflow fromInt(int value) { 28 | switch (value) { 29 | case 0: return VISIBLE; 30 | case 1: return HIDDEN; 31 | case 2: return SCROLL; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaPositionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaPositionType { 13 | STATIC(0), 14 | RELATIVE(1), 15 | ABSOLUTE(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaPositionType(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaPositionType fromInt(int value) { 28 | switch (value) { 29 | case 0: return STATIC; 30 | case 1: return RELATIVE; 31 | case 2: return ABSOLUTE; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaUnit { 13 | UNDEFINED(0), 14 | POINT(1), 15 | PERCENT(2), 16 | AUTO(3), 17 | MAX_CONTENT(4), 18 | FIT_CONTENT(5), 19 | STRETCH(6); 20 | 21 | private final int mIntValue; 22 | 23 | YogaUnit(int intValue) { 24 | mIntValue = intValue; 25 | } 26 | 27 | public int intValue() { 28 | return mIntValue; 29 | } 30 | 31 | public static YogaUnit fromInt(int value) { 32 | switch (value) { 33 | case 0: return UNDEFINED; 34 | case 1: return POINT; 35 | case 2: return PERCENT; 36 | case 3: return AUTO; 37 | case 4: return MAX_CONTENT; 38 | case 5: return FIT_CONTENT; 39 | case 6: return STRETCH; 40 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/YogaWrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | 10 | package com.facebook.yoga; 11 | 12 | public enum YogaWrap { 13 | NO_WRAP(0), 14 | WRAP(1), 15 | WRAP_REVERSE(2); 16 | 17 | private final int mIntValue; 18 | 19 | YogaWrap(int intValue) { 20 | mIntValue = intValue; 21 | } 22 | 23 | public int intValue() { 24 | return mIntValue; 25 | } 26 | 27 | public static YogaWrap fromInt(int value) { 28 | switch (value) { 29 | case 0: return NO_WRAP; 30 | case 1: return WRAP; 31 | case 2: return WRAP_REVERSE; 32 | default: throw new IllegalArgumentException("Unknown enum value: " + value); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /java/com/facebook/yoga/annotations/DoNotStrip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga.annotations; 9 | 10 | import java.lang.annotation.ElementType; 11 | import java.lang.annotation.Retention; 12 | import java.lang.annotation.Target; 13 | 14 | import static java.lang.annotation.RetentionPolicy.CLASS; 15 | 16 | @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR }) 17 | @Retention(CLASS) 18 | public @interface DoNotStrip { } 19 | -------------------------------------------------------------------------------- /java/gen/com/facebook/yoga/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /*___Generated_by_IDEA___*/ 9 | 10 | package com.facebook.yoga; 11 | 12 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ 13 | public final class BuildConfig { 14 | public final static boolean DEBUG = Boolean.parseBoolean(null); 15 | } -------------------------------------------------------------------------------- /java/jni/LayoutContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "LayoutContext.h" 11 | 12 | namespace facebook::yoga::vanillajni { 13 | 14 | namespace { 15 | std::stack& getContexts() { 16 | static thread_local std::stack contexts; 17 | return contexts; 18 | } 19 | 20 | } // namespace 21 | 22 | LayoutContext::Provider::Provider(PtrJNodeMapVanilla* data) { 23 | getContexts().push(data); 24 | } 25 | 26 | LayoutContext::Provider::~Provider() { 27 | getContexts().pop(); 28 | } 29 | 30 | /*static*/ PtrJNodeMapVanilla* LayoutContext::getNodeMap() { 31 | return getContexts().empty() ? nullptr : getContexts().top(); 32 | } 33 | 34 | } // namespace facebook::yoga::vanillajni 35 | -------------------------------------------------------------------------------- /java/jni/LayoutContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "YGJTypesVanilla.h" 12 | 13 | namespace facebook::yoga::vanillajni { 14 | 15 | // TODO: This should not be exported or used outside of the JNI bindings 16 | class YG_EXPORT LayoutContext { 17 | public: 18 | // Sets a context on the current thread for the duration of the Provider's 19 | // lifetime. This context should be set during the layout process to allow 20 | // layout callbacks to access context-data specific to the layout pass. 21 | struct Provider { 22 | explicit Provider(PtrJNodeMapVanilla* data); 23 | ~Provider(); 24 | }; 25 | 26 | static PtrJNodeMapVanilla* getNodeMap(); 27 | }; 28 | 29 | } // namespace facebook::yoga::vanillajni 30 | -------------------------------------------------------------------------------- /java/jni/YGJNIVanilla.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "jni.h" 9 | 10 | namespace YGJNIVanilla { 11 | void registerNatives(JNIEnv* env); 12 | }; 13 | -------------------------------------------------------------------------------- /java/jni/YGJTypesVanilla.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "common.h" 16 | #include "jni.h" 17 | 18 | class PtrJNodeMapVanilla { 19 | std::map ptrsToIdxs_{}; 20 | jobjectArray javaNodes_{}; 21 | 22 | public: 23 | PtrJNodeMapVanilla() = default; 24 | 25 | PtrJNodeMapVanilla(jlongArray javaNativePointers, jobjectArray javaNodes) 26 | : javaNodes_{javaNodes} { 27 | using namespace facebook::yoga::vanillajni; 28 | 29 | JNIEnv* env = getCurrentEnv(); 30 | jsize nativePointersSize = env->GetArrayLength(javaNativePointers); 31 | std::vector nativePointers(static_cast(nativePointersSize)); 32 | env->GetLongArrayRegion( 33 | javaNativePointers, 0, nativePointersSize, nativePointers.data()); 34 | 35 | for (jsize i = 0; i < nativePointersSize; ++i) { 36 | ptrsToIdxs_[(YGNodeConstRef)nativePointers[static_cast(i)]] = i; 37 | } 38 | } 39 | 40 | facebook::yoga::vanillajni::ScopedLocalRef ref(YGNodeConstRef node) { 41 | using namespace facebook::yoga::vanillajni; 42 | 43 | JNIEnv* env = getCurrentEnv(); 44 | auto idx = ptrsToIdxs_.find(node); 45 | if (idx == ptrsToIdxs_.end()) { 46 | return ScopedLocalRef(env); 47 | } else { 48 | return make_local_ref( 49 | env, env->GetObjectArrayElement(javaNodes_, idx->second)); 50 | } 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /java/jni/YogaJniException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "YogaJniException.h" 9 | #include 10 | #include 11 | #include "common.h" 12 | 13 | namespace facebook::yoga::vanillajni { 14 | 15 | YogaJniException::YogaJniException() { 16 | jclass cl = getCurrentEnv()->FindClass("java/lang/RuntimeException"); 17 | static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId( 18 | getCurrentEnv(), cl, "", "()V"); 19 | auto throwable = getCurrentEnv()->NewObject(cl, methodId); 20 | throwable_ = 21 | newGlobalRef(getCurrentEnv(), static_cast(throwable)); 22 | } 23 | 24 | YogaJniException::YogaJniException(jthrowable throwable) { 25 | throwable_ = newGlobalRef(getCurrentEnv(), throwable); 26 | } 27 | 28 | YogaJniException::YogaJniException(YogaJniException&& rhs) noexcept 29 | : throwable_(std::move(rhs.throwable_)) {} 30 | 31 | YogaJniException::YogaJniException(const YogaJniException& rhs) { 32 | throwable_ = newGlobalRef(getCurrentEnv(), rhs.throwable_.get()); 33 | } 34 | 35 | YogaJniException::~YogaJniException() { 36 | try { 37 | throwable_.reset(); 38 | } catch (...) { 39 | std::terminate(); 40 | } 41 | } 42 | 43 | ScopedLocalRef YogaJniException::getThrowable() const noexcept { 44 | return make_local_ref( 45 | getCurrentEnv(), 46 | static_cast(getCurrentEnv()->NewLocalRef(throwable_.get()))); 47 | } 48 | 49 | } // namespace facebook::yoga::vanillajni 50 | -------------------------------------------------------------------------------- /java/jni/YogaJniException.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | #include "common.h" 11 | 12 | namespace facebook::yoga::vanillajni { 13 | /** 14 | * This class wraps a Java exception (jthrowable) into a C++ exception; A global 15 | * reference to Java exception (jthrowable) is made so that the exception object 16 | * does not gets cleared before jni call completion 17 | */ 18 | class YogaJniException : public std::exception { 19 | public: 20 | YogaJniException(); 21 | ~YogaJniException() override; 22 | 23 | explicit YogaJniException(jthrowable throwable); 24 | 25 | YogaJniException(YogaJniException&& rhs) noexcept; 26 | 27 | YogaJniException(const YogaJniException& rhs); 28 | 29 | ScopedLocalRef getThrowable() const noexcept; 30 | 31 | private: 32 | ScopedGlobalRef throwable_; 33 | }; 34 | 35 | } // namespace facebook::yoga::vanillajni 36 | -------------------------------------------------------------------------------- /java/jni/corefunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga::vanillajni { 14 | 15 | /** 16 | * This method has to be called before using the vanillajni library. This method 17 | * is typically called when doing initialization in the "on load" JNI hook of a 18 | * particular library. 19 | * 20 | * This method is thread safe, and after the first time it's called it has no 21 | * initialization effect. 22 | * 23 | * @param env use this output parameter to get a JNIEnv to use for things such 24 | * as registering native methods and such. 25 | * @param vm the VM instance passed by JNI. This is usually the VM instance 26 | * that is passed to the "on load" JNI hook. 27 | * @return an integer value to return from the "on load" hook. 28 | */ 29 | jint ensureInitialized(JNIEnv** env, JavaVM* vm); 30 | 31 | /** 32 | * Returns a JNIEnv* suitable for the current thread. If the current thread is 33 | * not attached to the Java VM, this method aborts execution. 34 | */ 35 | JNIEnv* getCurrentEnv(); 36 | 37 | /** 38 | * Logs an error message and aborts the current process. 39 | */ 40 | void logErrorMessageAndDie(const char* message); 41 | 42 | /** 43 | * Checks whether there is a pending JNI exception. If so, it logs an error 44 | * message and aborts the current process. Otherwise it does nothing. 45 | */ 46 | void assertNoPendingJniException(JNIEnv* env); 47 | 48 | void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition); 49 | 50 | } // namespace facebook::yoga::vanillajni 51 | -------------------------------------------------------------------------------- /java/jni/macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #ifdef __ANDROID__ 13 | #include 14 | #endif 15 | 16 | #ifdef __ANDROID__ 17 | #define VANILLAJNI_LOG_ERROR(tag, format, ...) \ 18 | __android_log_print(ANDROID_LOG_ERROR, tag, format, ##__VA_ARGS__) 19 | #else 20 | #define VANILLAJNI_LOG_ERROR(tag, format, ...) 21 | #endif 22 | 23 | #define VANILLAJNI_DIE() std::abort() 24 | -------------------------------------------------------------------------------- /java/jni/yogajni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include "YGJNIVanilla.h" 9 | #include "common.h" 10 | 11 | using namespace facebook::yoga; 12 | 13 | jint JNI_OnLoad(JavaVM* vm, void* /*unused*/) { 14 | JNIEnv* env = nullptr; 15 | jint ret = vanillajni::ensureInitialized(&env, vm); 16 | YGJNIVanilla::registerNatives(env); 17 | return ret; 18 | } 19 | -------------------------------------------------------------------------------- /java/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | -keep,allowobfuscation @interface com.facebook.yoga.annotations.DoNotStrip 7 | -keep @com.facebook.yoga.annotations.DoNotStrip class * 8 | -keepclassmembers class * { 9 | @com.facebook.yoga.annotations.DoNotStrip *; 10 | } 11 | -------------------------------------------------------------------------------- /java/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | Yoga 12 | 13 | -------------------------------------------------------------------------------- /java/tests/com/facebook/yoga/TestParametrization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class TestParametrization { 14 | public static Iterable nodeFactories() { 15 | NodeFactory nodeFactory = new NodeFactory() { 16 | @Override 17 | public YogaNode create() { 18 | return YogaNodeFactory.create(); 19 | } 20 | 21 | @Override 22 | public YogaNode create(YogaConfig config) { 23 | return YogaNodeFactory.create(config); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "JNI"; 29 | } 30 | }; 31 | return Arrays.asList(nodeFactory); 32 | } 33 | 34 | 35 | public interface NodeFactory { 36 | YogaNode create(); 37 | YogaNode create(YogaConfig config); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /java/tests/com/facebook/yoga/YogaValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | package com.facebook.yoga; 9 | 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | public class YogaValueTest { 15 | 16 | @Test 17 | public void testEquals() { 18 | assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(0, YogaUnit.UNDEFINED)); 19 | assertEquals(new YogaValue(0, YogaUnit.POINT), new YogaValue(0, YogaUnit.POINT)); 20 | assertEquals(new YogaValue(0, YogaUnit.PERCENT), new YogaValue(0, YogaUnit.PERCENT)); 21 | assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(1, YogaUnit.UNDEFINED)); 22 | assertEquals(new YogaValue(Float.NaN, YogaUnit.POINT), new YogaValue(Float.NaN, YogaUnit.POINT)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /java/yogajni.version: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | { 9 | global: 10 | JNI_OnLoad; 11 | local: 12 | *; 13 | }; 14 | -------------------------------------------------------------------------------- /javascript/.gitignore: -------------------------------------------------------------------------------- 1 | /.emsdk 2 | /binaries 3 | /build 4 | /dist 5 | -------------------------------------------------------------------------------- /javascript/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | cmake_minimum_required(VERSION 3.13...3.26) 7 | set(CMAKE_VERBOSE_MAKEFILE on) 8 | project(yoga) 9 | 10 | file(GLOB SOURCES CONFIGURE_DEPENDS 11 | ${CMAKE_CURRENT_SOURCE_DIR}/../yoga/*.cpp 12 | ${CMAKE_CURRENT_SOURCE_DIR}/../yoga/**/*.cpp 13 | ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 14 | 15 | include_directories(..) 16 | 17 | set(CMAKE_CXX_STANDARD 20) 18 | 19 | add_compile_definitions( 20 | EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0) 21 | 22 | set(COMPILE_OPTIONS 23 | -flto 24 | -fno-exceptions 25 | -fno-rtti 26 | -g0 27 | -Os 28 | "SHELL:-s STRICT=1") 29 | 30 | add_compile_options(${COMPILE_OPTIONS}) 31 | 32 | add_link_options( 33 | ${COMPILE_OPTIONS} 34 | "SHELL:--closure 1" 35 | "SHELL:--memory-init-file 0" 36 | "SHELL:--no-entry" 37 | "SHELL:-s ALLOW_MEMORY_GROWTH=1" 38 | "SHELL:-s ASSERTIONS=0" 39 | "SHELL:-s DYNAMIC_EXECUTION=0" 40 | "SHELL:-s EXPORT_NAME='loadYoga'" 41 | "SHELL:-s FETCH_SUPPORT_INDEXEDDB=0" 42 | "SHELL:-s FILESYSTEM=0" 43 | "SHELL:-s MALLOC='emmalloc'" 44 | "SHELL:-s MODULARIZE=1" 45 | "SHELL:-s EXPORT_ES6=1" 46 | "SHELL:-s WASM=1" 47 | "SHELL:-s TEXTDECODER=0" 48 | # SINGLE_FILE=1 combined with ENVIRONMENT='web' creates code that works on 49 | # both bundlders and Node. 50 | "SHELL:-s SINGLE_FILE=1" 51 | "SHELL:-s ENVIRONMENT='web'") 52 | 53 | link_libraries(embind) 54 | 55 | add_library(yogaObjLib OBJECT ${SOURCES}) 56 | 57 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries) 58 | 59 | add_executable(yoga-wasm-base64-esm $) 60 | -------------------------------------------------------------------------------- /javascript/README.md: -------------------------------------------------------------------------------- 1 | # yoga-layout 2 | 3 | This package provides prebuilt WebAssembly bindings for the Yoga layout engine. 4 | 5 | See more at https://yogalayout.dev 6 | 7 | ## Usage 8 | 9 | ```ts 10 | import {Yoga, Align} from 'yoga-layout'; 11 | 12 | const node = Yoga.Node.create(); 13 | node.setAlignContent(Align.Center); 14 | ``` 15 | 16 | Objects created by `Yoga.<>.create()` are not automatically garbage collected and should be freed once they are no longer in use. 17 | 18 | ```ts 19 | // Free a config 20 | config.free(); 21 | 22 | // Free a tree of Nodes 23 | node.freeRecursive(); 24 | 25 | // Free a single Node 26 | node.free(); 27 | ``` 28 | 29 | ## Requirements 30 | 31 | `yoga-layout` requires a toolchain that supports ES Modules and top-level await. 32 | 33 | If top-level-await is not supported, use the `yoga-layout/load` entry point instead. This requires to load yoga manually: 34 | 35 | ```ts 36 | import {loadYoga, Align} from 'yoga-layout/load'; 37 | 38 | const node = (await loadYoga).Node.create(); 39 | node.setAlignContent(Align.Center); 40 | ``` 41 | -------------------------------------------------------------------------------- /javascript/babel.config.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | module.exports = api => ({ 11 | presets: [ 12 | [ 13 | '@babel/preset-env', 14 | { 15 | targets: [ 16 | 'maintained node versions', 17 | '> 0.5%, last 2 versions, Firefox ESR, not dead', 18 | ], 19 | // Do not transform to another module system 20 | modules: false, 21 | }, 22 | ], 23 | [ 24 | '@babel/preset-typescript', 25 | { 26 | rewriteImportExtensions: api.env('dist'), 27 | }, 28 | ], 29 | ], 30 | }); 31 | -------------------------------------------------------------------------------- /javascript/jest.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | export default { 11 | setupFiles: ['./jest.setup.js'], 12 | testRegex: '/tests/.*\\.test\\.ts$', 13 | extensionsToTreatAsEsm: ['.ts'], 14 | }; 15 | -------------------------------------------------------------------------------- /javascript/jest.setup.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | Object.defineProperty(globalThis, 'YGBENCHMARK', { 11 | get: () => globalThis.test, 12 | }); 13 | -------------------------------------------------------------------------------- /javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yoga-layout", 3 | "version": "0.0.0", 4 | "description": "An embeddable and performant flexbox layout engine with bindings for multiple languages", 5 | "license": "MIT", 6 | "author": "Meta Open Source", 7 | "homepage": "https://yogalayout.dev/", 8 | "repository": { 9 | "type": "git", 10 | "url": "git@github.com:facebook/yoga.git" 11 | }, 12 | "type": "module", 13 | "main": "./src/index.ts", 14 | "types": "./src/index.ts", 15 | "exports": { 16 | ".": "./src/index.ts", 17 | "./load": "./src/load.ts" 18 | }, 19 | "files": [ 20 | "dist/binaries/**", 21 | "dist/src/**", 22 | "src/**" 23 | ], 24 | "scripts": { 25 | "benchmark": "just benchmark --config just.config.cjs", 26 | "build": "just build --config just.config.cjs", 27 | "clang-format": "just clang-format --config just.config.cjs", 28 | "clang-format:fix": "just clang-format --fix --config just.config.cjs", 29 | "clean": "just clean --config just.config.cjs", 30 | "lint": "eslint .", 31 | "lint:fix": "eslint . --fix", 32 | "prepack": "just prepack --config just.config.cjs", 33 | "test": "just test --config just.config.cjs", 34 | "tsc": "tsc --noEmit" 35 | }, 36 | "devDependencies": { 37 | "@babel/cli": "^7.23.0", 38 | "@babel/core": "^7.23.0", 39 | "@babel/preset-env": "^7.23.0", 40 | "@babel/preset-typescript": "^7.23.0", 41 | "@types/jest": "^29.5.1", 42 | "@types/node": "^16.18.25", 43 | "@types/which": "^3.0.0", 44 | "@yogalayout/cmake-bin": "3.28.0-1", 45 | "babel-register-esm": "^1.2.5", 46 | "clang-format": "^1.8.0", 47 | "glob": "^10.4.2", 48 | "jest": "^29.3.1", 49 | "just-scripts": "^2.1.0", 50 | "ninja-binaries": "^1.11.1", 51 | "which": "^3.0.0" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /javascript/src/Config.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include "./Config.h" 11 | 12 | /* static */ Config* Config::create(void) { 13 | return new Config(); 14 | } 15 | 16 | /* static */ void Config::destroy(Config* node) { 17 | delete node; 18 | } 19 | 20 | Config::Config(void) : m_config(YGConfigNew()) {} 21 | 22 | Config::~Config(void) { 23 | YGConfigFree(m_config); 24 | } 25 | 26 | void Config::setExperimentalFeatureEnabled(int feature, bool enabled) { 27 | YGConfigSetExperimentalFeatureEnabled( 28 | m_config, static_cast(feature), enabled); 29 | } 30 | 31 | void Config::setPointScaleFactor(float pixelsInPoint) { 32 | YGConfigSetPointScaleFactor(m_config, pixelsInPoint); 33 | } 34 | 35 | void Config::setErrata(int errata) { 36 | YGConfigSetErrata(m_config, static_cast(errata)); 37 | } 38 | 39 | void Config::setUseWebDefaults(bool useWebDefaults) { 40 | YGConfigSetUseWebDefaults(m_config, useWebDefaults); 41 | } 42 | 43 | bool Config::isExperimentalFeatureEnabled(int feature) const { 44 | return YGConfigIsExperimentalFeatureEnabled( 45 | m_config, static_cast(feature)); 46 | } 47 | 48 | int Config::getErrata() const { 49 | return static_cast(YGConfigGetErrata(m_config)); 50 | } 51 | 52 | bool Config::useWebDefaults() const { 53 | return YGConfigGetUseWebDefaults(m_config); 54 | } 55 | -------------------------------------------------------------------------------- /javascript/src/Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | class Config { 13 | friend class Node; 14 | 15 | public: 16 | static Config* create(void); 17 | 18 | static void destroy(Config* config); 19 | 20 | private: 21 | Config(void); 22 | 23 | public: 24 | ~Config(void); 25 | 26 | public: // Prevent accidental copy 27 | Config(Config const&) = delete; 28 | 29 | Config const& operator=(Config const&) = delete; 30 | 31 | public: // Setters 32 | void setExperimentalFeatureEnabled(int feature, bool enabled); 33 | void setPointScaleFactor(float pixelsInPoint); 34 | void setErrata(int errata); 35 | void setUseWebDefaults(bool useWebDefaults); 36 | 37 | public: // Getters 38 | bool isExperimentalFeatureEnabled(int feature) const; 39 | int getErrata() const; 40 | bool useWebDefaults() const; 41 | 42 | private: 43 | YGConfigRef m_config; 44 | }; 45 | -------------------------------------------------------------------------------- /javascript/src/Layout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | struct Layout { 11 | double left; 12 | double right; 13 | 14 | double top; 15 | double bottom; 16 | 17 | double width; 18 | double height; 19 | }; 20 | -------------------------------------------------------------------------------- /javascript/src/Size.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | struct Size { 11 | double width; 12 | double height; 13 | 14 | Size(void) : width(0.0), height(0.0) {} 15 | 16 | Size(double width, double height) : width(width), height(height) {} 17 | }; 18 | -------------------------------------------------------------------------------- /javascript/src/Value.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | struct Value { 13 | static Value fromYGValue(YGValue const& ygValue) { 14 | return Value(static_cast(ygValue.unit), ygValue.value); 15 | } 16 | 17 | int unit; 18 | double value; 19 | 20 | Value(void) : unit(YGUnitUndefined), value(0.0) {} 21 | 22 | Value(int unit, double value) : unit(unit), value(value) {} 23 | }; 24 | -------------------------------------------------------------------------------- /javascript/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | // @ts-ignore untyped from Emscripten 11 | import loadYoga from '../binaries/yoga-wasm-base64-esm.js'; 12 | import wrapAssembly from './wrapAssembly.ts'; 13 | 14 | export type { 15 | Config, 16 | DirtiedFunction, 17 | MeasureFunction, 18 | Node, 19 | } from './wrapAssembly.ts'; 20 | 21 | const Yoga = wrapAssembly(await loadYoga()); 22 | export default Yoga; 23 | export * from './generated/YGEnums.ts'; 24 | -------------------------------------------------------------------------------- /javascript/src/load.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | // @ts-ignore untyped from Emscripten 11 | import loadYogaImpl from '../binaries/yoga-wasm-base64-esm.js'; 12 | import wrapAssembly from './wrapAssembly.ts'; 13 | 14 | export type { 15 | Config, 16 | DirtiedFunction, 17 | MeasureFunction, 18 | Node, 19 | Yoga, 20 | } from './wrapAssembly.ts'; 21 | 22 | export async function loadYoga() { 23 | return wrapAssembly(await loadYogaImpl()); 24 | } 25 | export * from './generated/YGEnums.ts'; 26 | -------------------------------------------------------------------------------- /javascript/tests/YGComputedBorderTest.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | test('border_start', () => { 11 | const root = Yoga.Node.create(); 12 | root.setWidth(100); 13 | root.setHeight(100); 14 | root.setBorder(Yoga.EDGE_START, 10); 15 | 16 | root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); 17 | 18 | expect(root.getComputedBorder(Yoga.EDGE_LEFT)).toBe(10); 19 | expect(root.getComputedBorder(Yoga.EDGE_RIGHT)).toBe(0); 20 | 21 | root.calculateLayout(100, 100, Yoga.DIRECTION_RTL); 22 | 23 | expect(root.getComputedBorder(Yoga.EDGE_LEFT)).toBe(0); 24 | expect(root.getComputedBorder(Yoga.EDGE_RIGHT)).toBe(10); 25 | 26 | root.freeRecursive(); 27 | }); 28 | -------------------------------------------------------------------------------- /javascript/tests/YGComputedMarginTest.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | test('margin_start', () => { 11 | const root = Yoga.Node.create(); 12 | root.setWidth(100); 13 | root.setHeight(100); 14 | root.setMargin(Yoga.EDGE_START, `10%`); 15 | 16 | root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); 17 | 18 | expect(root.getComputedMargin(Yoga.EDGE_LEFT)).toBe(10); 19 | expect(root.getComputedMargin(Yoga.EDGE_RIGHT)).toBe(0); 20 | 21 | root.calculateLayout(100, 100, Yoga.DIRECTION_RTL); 22 | 23 | expect(root.getComputedMargin(Yoga.EDGE_LEFT)).toBe(0); 24 | expect(root.getComputedMargin(Yoga.EDGE_RIGHT)).toBe(10); 25 | 26 | root.freeRecursive(); 27 | }); 28 | -------------------------------------------------------------------------------- /javascript/tests/YGComputedPaddingTest.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | test('padding_start', () => { 11 | const root = Yoga.Node.create(); 12 | root.setWidth(100); 13 | root.setHeight(100); 14 | root.setPadding(Yoga.EDGE_START, `10%`); 15 | 16 | root.calculateLayout(100, 100, Yoga.DIRECTION_LTR); 17 | 18 | expect(root.getComputedPadding(Yoga.EDGE_LEFT)).toBe(10); 19 | expect(root.getComputedPadding(Yoga.EDGE_RIGHT)).toBe(0); 20 | 21 | root.calculateLayout(100, 100, Yoga.DIRECTION_RTL); 22 | 23 | expect(root.getComputedPadding(Yoga.EDGE_LEFT)).toBe(0); 24 | expect(root.getComputedPadding(Yoga.EDGE_RIGHT)).toBe(10); 25 | 26 | root.freeRecursive(); 27 | }); 28 | -------------------------------------------------------------------------------- /javascript/tests/YGErrataTest.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | test('errata_all_contains_example_errata', () => { 11 | const config = Yoga.Config.create(); 12 | config.setErrata(Yoga.ERRATA_ALL); 13 | 14 | expect(config.getErrata()).toBe(Yoga.ERRATA_ALL); 15 | expect(config.getErrata() & Yoga.ERRATA_STRETCH_FLEX_BASIS).not.toBe(0); 16 | 17 | config.free(); 18 | }); 19 | 20 | test('errata_none_omits_example_errata', () => { 21 | const config = Yoga.Config.create(); 22 | config.setErrata(Yoga.ERRATA_NONE); 23 | 24 | expect(config.getErrata()).toBe(Yoga.ERRATA_NONE); 25 | expect(config.getErrata() & Yoga.ERRATA_STRETCH_FLEX_BASIS).toBe(0); 26 | 27 | config.free(); 28 | }); 29 | 30 | test('errata_is_settable', () => { 31 | const config = Yoga.Config.create(); 32 | 33 | config.setErrata(Yoga.ERRATA_ALL); 34 | expect(config.getErrata()).toBe(Yoga.ERRATA_ALL); 35 | 36 | config.setErrata(Yoga.ERRATA_NONE); 37 | expect(config.getErrata()).toBe(Yoga.ERRATA_NONE); 38 | 39 | config.free(); 40 | }); 41 | -------------------------------------------------------------------------------- /javascript/tests/YGFlexBasisAuto.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | test('flex_basis_auto', () => { 11 | const root = Yoga.Node.create(); 12 | 13 | expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO); 14 | 15 | root.setFlexBasis(10); 16 | expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_POINT); 17 | expect(root.getFlexBasis().value).toBe(10); 18 | 19 | root.setFlexBasisAuto(); 20 | expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO); 21 | 22 | root.freeRecursive(); 23 | }); 24 | -------------------------------------------------------------------------------- /javascript/tests/YGMeasureCacheTest.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Yoga from 'yoga-layout'; 9 | 10 | import {getMeasureCounterMax} from './tools/MeasureCounter.ts'; 11 | 12 | test('measure_once_single_flexible_child', () => { 13 | const root = Yoga.Node.create(); 14 | root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); 15 | root.setAlignItems(Yoga.ALIGN_FLEX_START); 16 | root.setWidth(100); 17 | root.setHeight(100); 18 | 19 | const measureCounter = getMeasureCounterMax(); 20 | 21 | const root_child0 = Yoga.Node.create(); 22 | root_child0.setMeasureFunc(measureCounter.inc); 23 | root_child0.setFlexGrow(1); 24 | root.insertChild(root_child0, 0); 25 | 26 | root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); 27 | 28 | expect(measureCounter.get()).toBe(1); 29 | 30 | root.freeRecursive(); 31 | }); 32 | -------------------------------------------------------------------------------- /javascript/tests/bin/run-bench.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ts-node 2 | /** 3 | * Copyright (c) Meta Platforms, Inc. and affiliates. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | * 8 | * @format 9 | */ 10 | 11 | import path from 'path'; 12 | 13 | const WARMUP_ITERATIONS = 3; 14 | const BENCHMARK_ITERATIONS = 10; 15 | 16 | const testFiles = process.argv.slice(2); 17 | 18 | const testResults = new Map>(); 19 | 20 | for (const type of ['wasm']) { 21 | for (const file of testFiles) { 22 | globalThis.YGBENCHMARK = (name: string, fn: () => void) => { 23 | let testEntry = testResults.get(name); 24 | 25 | if (testEntry === undefined) 26 | testResults.set(name, (testEntry = new Map())); 27 | 28 | for (let t = 0; t < WARMUP_ITERATIONS; ++t) fn(); 29 | 30 | const start = Date.now(); 31 | 32 | for (let t = 0; t < BENCHMARK_ITERATIONS; ++t) fn(); 33 | 34 | const end = Date.now(); 35 | 36 | testEntry.set(type, (end - start) / BENCHMARK_ITERATIONS); 37 | }; 38 | 39 | const modulePath = path.resolve(file); 40 | await import(modulePath); 41 | } 42 | } 43 | 44 | console.log( 45 | `Note: those tests are independants; there is no time relation to be expected between them`, 46 | ); 47 | 48 | for (const [name, results] of testResults) { 49 | console.log(); 50 | 51 | const min = Math.min(Infinity, ...results.values()); 52 | 53 | console.log(name); 54 | 55 | for (const [type, result] of results) { 56 | console.log( 57 | ` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`, 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /javascript/tests/tools/globals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | declare global { 9 | // eslint-disable-next-line no-var 10 | var YGBENCHMARK: (title: string, fn: () => void) => void; 11 | } 12 | 13 | if (globalThis.YGBENCHMARK === undefined) { 14 | throw new Error('Expected "YGBENCHMARK" global to be set'); 15 | } 16 | 17 | const benchmark = globalThis.YGBENCHMARK; 18 | 19 | export {benchmark as YGBENCHMARK}; 20 | -------------------------------------------------------------------------------- /javascript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2020", 4 | "module": "esnext", 5 | "strict": true, 6 | "declaration": true, 7 | "esModuleInterop": true, 8 | "skipLibCheck": true, 9 | // TODO: moduleResolution: "nodenext" is buggy with this if the absolute 10 | // path contains any capital letters 11 | "forceConsistentCasingInFileNames": false, 12 | "baseUrl": ".", 13 | "moduleResolution": "nodenext", 14 | "allowImportingTsExtensions": true, 15 | "paths": { 16 | "yoga-layout": ["src"] 17 | } 18 | }, 19 | "include": [ 20 | "src/**/*", 21 | "tests/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /lib/jni/jni.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the LICENSE 5 | * file in the root directory of this source tree. 6 | */ 7 | #pragma once 8 | 9 | #ifdef __ANDROID__ 10 | #include_next 11 | #else 12 | #include "real/jni.h" 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/jsr-305/jsr305.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/lib/jsr-305/jsr305.jar -------------------------------------------------------------------------------- /lib/soloader/soloader-0.5.1.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/lib/soloader/soloader-0.5.1.aar -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yoga-repo", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "lint": "eslint .", 7 | "lint:fix": "eslint . --fix", 8 | "tsc": "yarn workspaces run tsc", 9 | "gentest": "yarn workspace gentest run gentest", 10 | "gentest-validate": "yarn workspace gentest run gentest-validate" 11 | }, 12 | "workspaces": [ 13 | "javascript", 14 | "gentest", 15 | "website" 16 | ], 17 | "devDependencies": { 18 | "@typescript-eslint/eslint-plugin": "^5.30.5", 19 | "@typescript-eslint/parser": "^5.30.5", 20 | "eslint": "^8.30.0", 21 | "eslint-config-prettier": "^8.5.0", 22 | "eslint-plugin-jest": "^27.1.7", 23 | "eslint-plugin-prettier": "^4.2.1", 24 | "prettier": "2.8.8", 25 | "typescript": "5.0.4" 26 | }, 27 | "resolutions": { 28 | "cliui/wrap-ansi": "7.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /set-version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | import os 8 | import re 9 | import sys 10 | 11 | os.chdir(os.path.dirname(__file__)) 12 | 13 | if len(sys.argv) != 2: 14 | print("usage: ./set-version ", file=sys.stderr) 15 | sys.exit(1) 16 | 17 | version = sys.argv[1] 18 | 19 | with open("gradle.properties", "r+") as f: 20 | new_contents = re.sub(r"VERSION_NAME=.*", f"VERSION_NAME={version}", f.read()) 21 | f.seek(0) 22 | f.truncate() 23 | f.write(new_contents) 24 | 25 | with open("javascript/package.json", "r+") as f: 26 | new_contents = re.sub(r'"version": ".*",', f'"version": "{version}",', f.read()) 27 | f.seek(0) 28 | f.truncate() 29 | f.write(new_contents) 30 | 31 | with open("website/package.json", "r+") as f: 32 | new_contents = re.sub( 33 | r'"yoga-layout": ".*"', f'"yoga-layout": "{version}"', f.read() 34 | ) 35 | f.seek(0) 36 | f.truncate() 37 | f.write(new_contents) 38 | 39 | with open("Yoga.podspec", "r+") as f: 40 | new_contents = re.sub( 41 | r"spec\.version = '.*'", f"spec.version = '{version}'", f.read() 42 | ) 43 | f.seek(0) 44 | f.truncate() 45 | f.write(new_contents) 46 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | pluginManagement { 9 | repositories { 10 | gradlePluginPortal() 11 | mavenCentral() 12 | google() 13 | } 14 | } 15 | 16 | plugins { id("com.gradle.enterprise").version("3.7.1") } 17 | 18 | include(":yoga") 19 | 20 | project(":yoga").projectDir = file("java") 21 | 22 | rootProject.name = "yoga-github" 23 | 24 | // If you specify a file inside gradle/gradle-enterprise.gradle.kts 25 | // you can configure your custom Gradle Enterprise instance 26 | if (file("./gradle/gradle-enterprise.gradle.kts").exists()) { 27 | apply(from = "./gradle/gradle-enterprise.gradle.kts") 28 | } 29 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | 7 | cmake_minimum_required(VERSION 3.13...3.26) 8 | project(tests) 9 | set(CMAKE_VERBOSE_MAKEFILE on) 10 | 11 | include(FetchContent) 12 | include(GoogleTest) 13 | 14 | set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 15 | include(${YOGA_ROOT}/cmake/project-defaults.cmake) 16 | 17 | # Fetch GTest 18 | FetchContent_Declare( 19 | googletest 20 | URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip 21 | ) 22 | FetchContent_MakeAvailable(googletest) 23 | 24 | add_subdirectory(${YOGA_ROOT}/yoga ${CMAKE_CURRENT_BINARY_DIR}/yoga) 25 | 26 | file(GLOB SOURCES CONFIGURE_DEPENDS 27 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 28 | ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) 29 | 30 | enable_testing() 31 | 32 | add_executable(yogatests ${SOURCES}) 33 | target_link_libraries(yogatests yogacore GTest::gtest_main) 34 | 35 | gtest_discover_tests(yogatests) 36 | -------------------------------------------------------------------------------- /tests/OrdinalsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga { 14 | 15 | TEST(Ordinals, iteration) { 16 | std::deque expectedEdges{ 17 | Edge::Left, 18 | Edge::Top, 19 | Edge::Right, 20 | Edge::Bottom, 21 | Edge::Start, 22 | Edge::End, 23 | Edge::Horizontal, 24 | Edge::Vertical, 25 | Edge::All}; 26 | 27 | for (auto edge : yoga::ordinals()) { 28 | ASSERT_EQ(edge, expectedEdges.front()); 29 | expectedEdges.pop_front(); 30 | } 31 | 32 | ASSERT_TRUE(expectedEdges.empty()); 33 | } 34 | 35 | } // namespace facebook::yoga 36 | -------------------------------------------------------------------------------- /tests/StyleTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | namespace facebook::yoga { 12 | 13 | TEST(Style, computed_padding_is_floored) { 14 | yoga::Style style; 15 | style.setPadding(Edge::All, StyleLength::points(-1.0f)); 16 | auto paddingStart = style.computeInlineStartPadding( 17 | FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); 18 | ASSERT_EQ(paddingStart, 0.0f); 19 | } 20 | 21 | TEST(Style, computed_border_is_floored) { 22 | yoga::Style style; 23 | style.setBorder(Edge::All, StyleLength::points(-1.0f)); 24 | auto borderStart = 25 | style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR); 26 | ASSERT_EQ(borderStart, 0.0f); 27 | } 28 | 29 | TEST(Style, computed_gap_is_floored) { 30 | yoga::Style style; 31 | style.setGap(Gutter::Column, StyleLength::points(-1.0f)); 32 | auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0); 33 | ASSERT_EQ(gapBetweenColumns, 0.0f); 34 | } 35 | 36 | TEST(Style, computed_margin_is_not_floored) { 37 | yoga::Style style; 38 | style.setMargin(Edge::All, StyleLength::points(-1.0f)); 39 | auto marginStart = style.computeInlineStartMargin( 40 | FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); 41 | ASSERT_EQ(marginStart, -1.0f); 42 | } 43 | 44 | } // namespace facebook::yoga 45 | -------------------------------------------------------------------------------- /tests/YGNodeChildTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | TEST(YogaTest, reset_layout_when_child_removed) { 12 | YGNodeRef root = YGNodeNew(); 13 | 14 | YGNodeRef root_child0 = YGNodeNew(); 15 | YGNodeStyleSetWidth(root_child0, 100); 16 | YGNodeStyleSetHeight(root_child0, 100); 17 | YGNodeInsertChild(root, root_child0, 0); 18 | 19 | YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); 20 | 21 | ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); 22 | ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); 23 | ASSERT_EQ(100, YGNodeLayoutGetWidth(root_child0)); 24 | ASSERT_EQ(100, YGNodeLayoutGetHeight(root_child0)); 25 | 26 | YGNodeRemoveChild(root, root_child0); 27 | 28 | ASSERT_EQ(0, YGNodeLayoutGetLeft(root_child0)); 29 | ASSERT_EQ(0, YGNodeLayoutGetTop(root_child0)); 30 | ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetWidth(root_child0))); 31 | ASSERT_TRUE(YGFloatIsUndefined(YGNodeLayoutGetHeight(root_child0))); 32 | 33 | YGNodeFreeRecursive(root); 34 | YGNodeFreeRecursive(root_child0); 35 | } 36 | -------------------------------------------------------------------------------- /tests/YGValueTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | TEST(YGValue, supports_equality) { 13 | ASSERT_EQ((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPercent})); 14 | ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{56.7f, YGUnitPercent})); 15 | ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitPoint})); 16 | ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitAuto})); 17 | ASSERT_NE((YGValue{12.5f, YGUnitPercent}), (YGValue{12.5f, YGUnitUndefined})); 18 | 19 | ASSERT_EQ( 20 | (YGValue{12.5f, YGUnitUndefined}), 21 | (YGValue{YGUndefined, YGUnitUndefined})); 22 | ASSERT_EQ((YGValue{0, YGUnitAuto}), (YGValue{-1, YGUnitAuto})); 23 | } 24 | -------------------------------------------------------------------------------- /tests/YGZeroOutLayoutRecursivelyTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | TEST(YogaTest, zero_out_layout) { 12 | YGNodeRef root = YGNodeNew(); 13 | YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); 14 | YGNodeStyleSetWidth(root, 200); 15 | YGNodeStyleSetHeight(root, 200); 16 | 17 | YGNodeRef child = YGNodeNew(); 18 | YGNodeInsertChild(root, child, 0); 19 | YGNodeStyleSetWidth(child, 100); 20 | YGNodeStyleSetHeight(child, 100); 21 | YGNodeStyleSetMargin(child, YGEdgeTop, 10); 22 | YGNodeStyleSetPadding(child, YGEdgeTop, 10); 23 | 24 | YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); 25 | 26 | ASSERT_FLOAT_EQ(10, YGNodeLayoutGetMargin(child, YGEdgeTop)); 27 | ASSERT_FLOAT_EQ(10, YGNodeLayoutGetPadding(child, YGEdgeTop)); 28 | 29 | YGNodeStyleSetDisplay(child, YGDisplayNone); 30 | 31 | YGNodeCalculateLayout(root, 100, 100, YGDirectionLTR); 32 | 33 | ASSERT_FLOAT_EQ(0, YGNodeLayoutGetMargin(child, YGEdgeTop)); 34 | ASSERT_FLOAT_EQ(0, YGNodeLayoutGetPadding(child, YGEdgeTop)); 35 | 36 | YGNodeFreeRecursive(root); 37 | } 38 | -------------------------------------------------------------------------------- /tests/util/TestUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook::yoga::test { 16 | 17 | struct TestUtil { 18 | static void startCountingNodes(); 19 | static int nodeCount(); 20 | static int stopCountingNodes(); 21 | }; 22 | 23 | struct ScopedEventSubscription { 24 | explicit ScopedEventSubscription(std::function&&); 25 | ~ScopedEventSubscription(); 26 | }; 27 | 28 | YGSize IntrinsicSizeMeasure( 29 | YGNodeConstRef node, 30 | float width, 31 | YGMeasureMode widthMode, 32 | float height, 33 | YGMeasureMode heightMode); 34 | 35 | float longestWordWidth(std::string_view text, float widthPerChar); 36 | 37 | float calculateHeight( 38 | std::string_view text, 39 | float measuredWidth, 40 | float widthPerChar, 41 | float heightPerChar); 42 | 43 | } // namespace facebook::yoga::test 44 | -------------------------------------------------------------------------------- /unit_tests: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # 4 | # This source code is licensed under the MIT license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | cd "$(dirname "$0")/tests" 8 | 9 | if [ "$#" -eq 0 ]; then 10 | build_type="Debug" 11 | else 12 | build_type="$1" 13 | fi 14 | 15 | if which ninja; then 16 | set -e 17 | cmake -B build -S . -D CMAKE_BUILD_TYPE="$build_type" -G Ninja 18 | else 19 | set -e 20 | cmake -B build -S . -D CMAKE_BUILD_TYPE="$build_type" 21 | fi 22 | 23 | cmake --build build 24 | 25 | ./build/yogatests 26 | -------------------------------------------------------------------------------- /unit_tests.bat: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Meta Platforms, Inc. and affiliates. 2 | @REM 3 | @REM This source code is licensed under the MIT license found in the 4 | @REM LICENSE file in the root directory of this source tree. 5 | 6 | @echo off 7 | SETLOCAL 8 | 9 | cd "%0\..\tests" 10 | 11 | if "%1" == "" ( 12 | set build_type="Debug" 13 | ) else ( 14 | set build_type="%1" 15 | ) 16 | 17 | where ninja 18 | if errorlevel 1 ( 19 | cmake -B build -S . -D CMAKE_BUILD_TYPE="%build_type%" 20 | ) else ( 21 | cmake -B build -S . -D CMAKE_BUILD_TYPE="%build_type%" -G Ninja 22 | ) 23 | if %errorlevel% neq 0 exit /b %errorlevel% 24 | 25 | cmake --build build 26 | if %errorlevel% neq 0 exit /b %errorlevel% 27 | 28 | .\build\yogatests.exe 29 | -------------------------------------------------------------------------------- /website/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | module.exports = { 11 | root: false, 12 | extends: [ 13 | 'plugin:react/recommended', 14 | 'plugin:react/jsx-runtime', 15 | 'plugin:react-hooks/recommended', 16 | ], 17 | settings: { 18 | react: { 19 | version: 'detect', 20 | }, 21 | }, 22 | rules: { 23 | 'react/prop-types': 'off', 24 | 'react/no-unstable-nested-components': 'error', 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Production 2 | /build 3 | 4 | # Generated files 5 | .docusaurus 6 | .cache-loader 7 | 8 | # Misc 9 | .DS_Store 10 | .env.local 11 | .env.development.local 12 | .env.test.local 13 | .env.production.local 14 | 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | Using SSH: 30 | 31 | ``` 32 | $ USE_SSH=true yarn deploy 33 | ``` 34 | 35 | Not using SSH: 36 | 37 | ``` 38 | $ GIT_USER= yarn deploy 39 | ``` 40 | 41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 42 | -------------------------------------------------------------------------------- /website/babel.config.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | module.exports = { 9 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 10 | }; 11 | -------------------------------------------------------------------------------- /website/blog/authors.yml: -------------------------------------------------------------------------------- 1 | NickGerleman: 2 | name: Nick Gerleman 3 | title: Yoga Maintainer 4 | url: https://github.com/NickGerleman 5 | image_url: https://github.com/NickGerleman.png 6 | joevilches: 7 | name: Joe Vilches 8 | title: Yoga Maintainer 9 | url: https://github.com/joevilches 10 | image_url: https://github.com/joevilches.png 11 | -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image1.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image10.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image11.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image12.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image13.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image14.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image15.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image16.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image17.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image2.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image3.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image4.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image5.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image6.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image7.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image8.png -------------------------------------------------------------------------------- /website/blog/yoga-3-release/img/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/blog/yoga-3-release/img/image9.png -------------------------------------------------------------------------------- /website/docs/about-yoga.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # About Yoga 6 | 7 | Yoga is an embeddable layout system used in popular UI frameworks like React Native. Yoga itself is not a UI framework, and does not do any drawing itself. Yoga's only responsibility is determining the size and position of boxes. 8 | 9 | ![layout wireframe](./img/wireframe-example.svg) 10 | 11 | Yoga supports a familiar subset of CSS, mostly focused on Flexbox. This gives users a familiar model, and enables sharing code between native platforms and the browser. 12 | 13 | Yoga is written in C++, with a public C API. This allows Yoga to be used by a wide variety of languages, via both official and unofficial bindings. 14 | -------------------------------------------------------------------------------- /website/docs/advanced/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Advanced", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /website/docs/getting-started/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Getting Started", 3 | "position": 2 4 | } 5 | -------------------------------------------------------------------------------- /website/docs/img/pixel-grid-after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/docs/img/pixel-grid-after.png -------------------------------------------------------------------------------- /website/docs/img/pixel-grid-before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/docs/img/pixel-grid-before.png -------------------------------------------------------------------------------- /website/docs/styling/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Styling", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /website/docs/styling/align-items-self.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Align Items 8 | 9 | Align items describes how to align children along the cross axis of their container. 10 | Align items is very similar to [justify content](/docs/styling/justify-content) but instead of 11 | applying to the main axis, align items applies to the cross axis. 12 | 13 | **Stretch (default)**: Stretch children of a container to match the [height](/docs/styling/width-height) of the container's cross axis. 14 | 15 | **Flex start**: Align children of a container to the start of the container's cross axis. 16 | 17 | **Flex end**: Align children of a container to the end of the container's cross axis. 18 | 19 | **Center**: Align children of a container in the center of the container's cross axis. 20 | 21 | **Baseline**: Align children of a container along a common baseline. Individual children can be set to be the reference baseline for their parents. 22 | 23 | # Align Self 24 | 25 | Align self has the same options and effect as align items but instead of 26 | affecting the children within a container, you can apply this property to 27 | a single child to change its alignment within its parent. Align self 28 | overrides any option set by the parent with align items. 29 | 30 | 31 | 38 | 46 | 47 | 48 | `} /> 49 | -------------------------------------------------------------------------------- /website/docs/styling/aspect-ratio.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Aspect Ratio 8 | 9 | The aspect ratio property in Yoga has the following properties: 10 | 11 | - Accepts any floating point value > 0, the default is undefined. 12 | - Defined as the ratio between the [width](/docs/styling/width-height) and the [height](/docs/styling/width-height) of a node e.g. if a node has an aspect ratio of 2 then its [width](/docs/styling/width-height) is twice the size of its [height](/docs/styling/width-height). 13 | - Respects the [min](/docs/styling/min-max-width-height) and [max](/docs/styling/min-max-width-height) dimensions of an item. 14 | - Has higher priority than [flex grow](/docs/styling/flex-basis-grow-shrink) 15 | - If aspect ratio, [width](/docs/styling/width-height), and [height](/docs/styling/width-height) are set then the cross axis dimension is overridden. 16 | 17 | 18 | 24 | 25 | 26 | 27 | `} /> 28 | -------------------------------------------------------------------------------- /website/docs/styling/display.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 4 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Display 8 | 9 | Display controls which layout specification to follow. 10 | 11 | **Flex (default)**: The CSS Flexible Box Model specification. 12 | 13 | **None**: The node is removed from the layout tree and will not be visible. 14 | 15 | 16 | 22 | 23 | 24 | 25 | `} /> 26 | -------------------------------------------------------------------------------- /website/docs/styling/flex-direction.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Flex Direction 8 | 9 | Flex direction controls the direction in which children of a node are laid out. 10 | This is also referred to as the main axis. The main axis is the direction in 11 | which children are laid out. The cross axis is the axis perpendicular to the 12 | main axis, or the axis which wrapping lines are laid out in. 13 | 14 | **Column (default)**: Align children from top to bottom. If [wrapping](/docs/styling/flex-wrap) is enabled then 15 | the next line will start to the left first item on the top of the container. 16 | 17 | **Row**: Align children from left to right. If [wrapping](/docs/styling/flex-wrap) is enabled then 18 | the next line will start under the first item on the left of the container. 19 | 20 | **Row reverse**: Align children from right to left. If [wrapping](/docs/styling/flex-wrap) is enabled then 21 | the next line will start under the first item on the right of the container. 22 | 23 | **Column reverse**: Align children from bottom to top. If [wrapping](/docs/styling/flex-wrap) is enabled then 24 | the next line will start to the left first item on the bottom of the container. 25 | 26 | 27 | 34 | 35 | 36 | 37 | `} /> 38 | -------------------------------------------------------------------------------- /website/docs/styling/flex-wrap.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Flex Wrap 8 | 9 | The flex wrap property is set on containers and controls what happens when 10 | children overflow the size of the container along the main axis. By default 11 | children are forced into a single line (which can shrink nodes). When wrapping lines [align content](/docs/styling/align-content) can be used to specify how the 12 | lines are placed in the container. 13 | 14 | **No wrap (default)**: No wrapping and children might shrink as a result. 15 | 16 | **Wrap**: Nodes are wrapped into multiple lines along the main axis if needed. 17 | 18 | **Wrap reverse**: Behaves the same as wrap but the order of the lines is reversed. 19 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | `} /> 34 | -------------------------------------------------------------------------------- /website/docs/styling/gap.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 8 3 | --- 4 | import Playground from '@site/src/components/Playground'; 5 | import Tabs from '@theme/Tabs'; 6 | import TabItem from '@theme/TabItem'; 7 | 8 | # Gap 9 | 10 | Gap will add spacing between the rows and columns of a flex container. You can 11 | specify if you want the gaps to be between only the rows, only the columns, or 12 | both. You can do this by passing in the corresponding gutter value to the API, 13 | for example 14 | 15 | 16 | 17 | ```cpp 18 | YGNodeStyleSetGap(node, YGGutterRow, amount); 19 | ``` 20 | 21 | 22 | ```java 23 | node.setGap(YogaGutter.ROW, amount); 24 | ``` 25 | 26 | 27 | ```typescript 28 | node.setGap(Gutter.Row, amount); 29 | ``` 30 | 31 | 32 | 33 | 34 | 35 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | `} /> 50 | -------------------------------------------------------------------------------- /website/docs/styling/justify-content.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 9 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Justify Content 8 | 9 | Justify content describes how to align children within the main axis of their container. 10 | For example, you can use this property to center a child horizontally within a container 11 | with [flex direction](/docs/styling/flex-direction) set to row or vertically within a container with [flex direction](/docs/styling/flex-direction) 12 | set to column. 13 | 14 | **Flex start (default)**: Align children of a container to the start of the container's main axis. 15 | 16 | **Flex end**: Align children of a container to the end of the container's main axis. 17 | 18 | **Center**: Align children of a container in the center of the container's main axis. 19 | 20 | **Space between**: Evenly space of children across the container's main axis, distributing 21 | remaining space between the children. 22 | 23 | **Space around**: Evenly space of children across the container's main axis, distributing 24 | remaining space around the children. Compared to space between using 25 | space around will result in space being distributed to the beginning of 26 | the first child and end of the last child. 27 | 28 | **Space evenly**: Evenly distributed within the alignment container along the main axis. 29 | The spacing between each pair of adjacent items, the main-start edge and the first item, 30 | and the main-end edge and the last item, are all exactly the same. 31 | 32 | 33 | 40 | 41 | 42 | 43 | `} /> 44 | -------------------------------------------------------------------------------- /website/docs/styling/layout-direction.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 10 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Layout Direction 8 | 9 | Layout direction specifies the direction in which children and text 10 | in a hierarchy should be laid out. Layout direction also effects what 11 | edge `start` and `end` refer to. By default Yoga lays out with left-to-right (LTR) 12 | layout direction. In this mode `start` refers to `left` and `end` 13 | refers to `right`. When localizing your apps for markets with right-to-left (RTL) languages 14 | you should customize this by either by passing a direction 15 | to the [CalculateLayout](/docs/getting-started/laying-out-a-tree) call or by setting the direction on the root node. 16 | 17 | **LTR (default)**: Text and children and laid out from left to right. Styles applied 18 | the start of an element are applied on the left side. 19 | 20 | **RTL**: Text and children and laid out from right to left. Styles applied the 21 | start of an element are applied on the right side. 22 | 23 | 24 | 31 | 32 | 33 | 34 | `} /> 35 | -------------------------------------------------------------------------------- /website/docs/styling/margin-padding-border.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 11 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Margin, Padding, and Border 8 | 9 | **Margin**: Affects the spacing around the outside of a node. A node with margin 10 | will offset itself from the bounds of its parent but also offset the 11 | location of any siblings. The margin of a node contributes to the total size 12 | of its parent if the parent is auto sized. 13 | 14 | **Padding**: Affects the size of the node it is applied to. Padding in Yoga acts as if 15 | `box-sizing: border-box;` was set. That is padding will not add to the total size 16 | of an element if it has an explicit size set. For auto sized nodes padding will increase 17 | the size of the node as well as offset the location of any children. 18 | 19 | **Border**: in Yoga acts exactly like padding and only exists as a separate property so 20 | that higher level frameworks get a hint as to how thick to draw a border. Yoga however 21 | does not do any drawing so just uses this information during layout where border 22 | acts exactly like padding. 23 | 24 | 25 | 31 | 39 | 40 | 41 | `} /> 42 | -------------------------------------------------------------------------------- /website/docs/styling/min-max-width-height.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 12 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Min/Max Width and Height 8 | 9 | These properties set the maximum and minimum size constraints of a node. 10 | They have higher priority than all other properties and will always be respected. 11 | Constraints can be specified as either absolute pixel values or as percentages of their 12 | [containing block's](/docs/advanced/containing-block) size. By default all these constraints are `undefined`. 13 | 14 | 15 | 21 | 22 | 29 | 36 | 43 | 51 | 52 | `} /> 53 | -------------------------------------------------------------------------------- /website/docs/styling/position.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 11 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Position 8 | 9 | **Relative (default)**: This node is laid out according to the specified flow of the flex container it is apart of. 10 | That is, it particpates in the flexbox algorithm and will take up space within the container, unlike absolute. 11 | [Insets](/docs/styling/insets) will offset the node from its normal position within its container. 12 | This node will always form a [containing block](/docs/advanced/containing-block). 13 | 14 | **Absolute**: This node is removed from the specified flow of the flex container it is apart of. 15 | Absolute nodes do not take up space in its flex container and will not affect the position of 16 | its siblings. [Insets](/docs/styling/insets) will offset the node from its [containing block](/docs/advanced/containing-block). 17 | 18 | **Static**: This node behaves like relative except it will ignore [insets](/docs/styling/insets) and will not 19 | form a [containing block](/docs/advanced/containing-block). 20 | 21 | 22 | 28 | 36 | 37 | `} /> 38 | -------------------------------------------------------------------------------- /website/docs/styling/width-height.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 14 3 | --- 4 | 5 | import Playground from '@site/src/components/Playground'; 6 | 7 | # Width and Height 8 | 9 | The width property specifies the width of the node's border box (the collective size of the node's content, padding, and border). 10 | Similarly height property specifies the height of the node's border box. 11 | 12 | Both width and height can take following values: 13 | 14 | **Auto**: The default Value, Yoga calculates the width/height for the node based 15 | on its content, whether that is other children, text, or an image. 16 | 17 | **Pixels**: Defines the width/height in absolute pixels. Depending on other properties set on 18 | the Yoga node this may or may not be the final dimension of the node. 19 | 20 | **Percentage**: Defines the width or height in percentage of its [containing block's](/docs/advanced/containing-block) width or height respectively. 21 | 22 | 23 | 29 | 36 | 37 | `} /> 38 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "website", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "yarn workspace yoga-layout build && docusaurus start", 8 | "build": "yarn workspace yoga-layout build && docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids", 15 | "typecheck": "tsc", 16 | "lint": "eslint .", 17 | "lint:fix": "eslint . --fix" 18 | }, 19 | "dependencies": { 20 | "@docusaurus/core": "3.6.0", 21 | "@docusaurus/preset-classic": "3.6.0", 22 | "@mdx-js/react": "^3.0.0", 23 | "clsx": "^2.0.0", 24 | "lz-string": "^1.5.0", 25 | "nullthrows": "^1.1.1", 26 | "prism-react-renderer": "^2.3.0", 27 | "react": "^18.3.0", 28 | "react-dom": "^18.3.0", 29 | "react-live": "^4.1.5", 30 | "yoga-layout": "0.0.0" 31 | }, 32 | "devDependencies": { 33 | "@docusaurus/module-type-aliases": "3.6.0", 34 | "@docusaurus/tsconfig": "3.6.0", 35 | "@docusaurus/types": "3.6.0", 36 | "eslint-plugin-react": "^7.33.2", 37 | "eslint-plugin-react-hooks": "^4.6.0" 38 | }, 39 | "browserslist": "> 0.5%, last 2 versions, Firefox ESR, not dead", 40 | "engines": { 41 | "node": ">=18.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /website/sidebars.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /** 9 | * Creating a sidebar enables you to: 10 | - create an ordered group of docs 11 | - render a sidebar for each doc of that group 12 | - provide next/previous navigation 13 | 14 | The sidebars can be generated from the filesystem, or explicitly defined here. 15 | 16 | Create as many sidebars as you want. 17 | */ 18 | 19 | // @ts-check 20 | 21 | /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ 22 | const sidebars = { 23 | // By default, Docusaurus generates a sidebar from the docs folder structure 24 | docsSidebar: [{type: 'autogenerated', dirName: '.'}], 25 | }; 26 | 27 | module.exports = sidebars; 28 | -------------------------------------------------------------------------------- /website/src/components/EditorToolbar.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | .toolbar { 9 | display: flex; 10 | column-gap: 8px; 11 | } 12 | 13 | .toolbar button { 14 | display: flex; 15 | align-items: center; 16 | background: var(--prism-background-color); 17 | color: var(--prism-color); 18 | border: 1px solid var(--ifm-color-emphasis-300); 19 | border-radius: var(--ifm-global-radius); 20 | padding: 0.4rem; 21 | line-height: 0; 22 | transition: opacity var(--ifm-transition-fast) ease-in-out; 23 | opacity: 0.4; 24 | } 25 | 26 | .toolbar button:focus-visible, 27 | .toolbar button:hover { 28 | opacity: 1 !important; 29 | } 30 | 31 | .icon { 32 | width: 24px; 33 | height: 24px; 34 | } 35 | 36 | .iconSwitcher { 37 | position: relative; 38 | width: 24px; 39 | height: 24px; 40 | } 41 | 42 | .actionIcon, 43 | .successIcon { 44 | position: absolute; 45 | top: 0; 46 | left: 0; 47 | fill: currentColor; 48 | opacity: inherit; 49 | width: inherit; 50 | height: inherit; 51 | transition: all var(--ifm-transition-fast) ease; 52 | } 53 | 54 | .successIcon { 55 | top: 50%; 56 | left: 50%; 57 | transform: translate(-50%, -50%) scale(0.33); 58 | opacity: 0; 59 | color: #00d600; 60 | } 61 | 62 | .clicked .actionIcon { 63 | transform: scale(0.33); 64 | opacity: 0; 65 | } 66 | 67 | .clicked .successIcon { 68 | transform: translate(-50%, -50%) scale(1); 69 | opacity: 1; 70 | transition-delay: 0.075s; 71 | } 72 | 73 | @media (max-width: 996px) { 74 | .toolbar { 75 | display: none; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /website/src/components/LayoutBox.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | */ 9 | 10 | import styles from './LayoutBox.module.css'; 11 | import clsx from 'clsx'; 12 | 13 | export type LayoutMetrics = { 14 | top: number; 15 | left: number; 16 | width: number; 17 | height: number; 18 | overflow?: 'visible' | 'hidden' | 'scroll'; 19 | display?: 'flex' | 'none' | 'contents'; 20 | children?: LayoutMetrics[]; 21 | }; 22 | 23 | export type Props = Readonly<{ 24 | metrics: LayoutMetrics; 25 | className?: string; 26 | depth: number; 27 | }>; 28 | 29 | export default function LayoutBox({metrics, depth, className}: Props) { 30 | const {children, ...style} = metrics; 31 | 32 | return ( 33 |
52 | {children?.map((child, i) => ( 53 | 58 | ))} 59 |
60 | ); 61 | } 62 | -------------------------------------------------------------------------------- /website/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | /** 9 | * Any CSS included here will be global. The classic template 10 | * bundles Infima by default. Infima is a CSS framework designed to 11 | * work well for content-centric websites. 12 | */ 13 | 14 | /* You can override the default Infima variables here. */ 15 | :root { 16 | --ifm-color-primary-lightest: rgb(99, 183, 168); 17 | --ifm-color-primary-lighter: rgb(70, 159, 143); 18 | --ifm-color-primary-light: rgb(48, 135, 119); 19 | --ifm-color-primary: rgb(33, 111, 97); 20 | --ifm-color-primary-dark: rgb(22, 87, 75); 21 | --ifm-color-primary-darker: rgb(14, 63, 54); 22 | --ifm-color-primary-darkest: rgb(8, 39, 33); 23 | --ifm-code-font-size: 95%; 24 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); 25 | } 26 | 27 | /* For readability concerns, you should choose a lighter palette in dark mode. */ 28 | [data-theme='dark'] { 29 | --ifm-color-primary-lightest: rgb(192, 231, 224); 30 | --ifm-color-primary-lighter: rgb(146, 207, 196); 31 | --ifm-color-primary-light: rgb(106, 183, 169); 32 | --ifm-color-primary: rgb(74, 159, 144); 33 | --ifm-color-primary-dark: rgb(51, 135, 120); 34 | --ifm-color-primary-darker: rgb(34, 111, 97); 35 | --ifm-color-primary-darkest: rgb(22, 87, 75); 36 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); 37 | } 38 | -------------------------------------------------------------------------------- /website/src/pages/index.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | .heroBanner { 9 | justify-content: center; 10 | } 11 | 12 | .heroRow { 13 | align-items: center; 14 | justify-content: center; 15 | } 16 | 17 | .heroLogo { 18 | width: 200px; 19 | height: 200px; 20 | } 21 | 22 | @media (max-width: 996px) { 23 | .heroLogo { 24 | display: none; 25 | } 26 | 27 | .playgroundSection :global(.playground-editor) { 28 | display: none; 29 | } 30 | } 31 | 32 | .bg { 33 | background-color: var(--yg-color-playground-background); 34 | } 35 | -------------------------------------------------------------------------------- /website/src/pages/markdown-page.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Markdown page example 3 | --- 4 | 5 | # Markdown page example 6 | 7 | You don't need React to write simple standalone pages. 8 | -------------------------------------------------------------------------------- /website/src/pages/playground.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | .playgroundContainer { 9 | display: flex; 10 | flex: 1; 11 | } 12 | -------------------------------------------------------------------------------- /website/src/pages/playground.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | import Layout from '@theme/Layout'; 9 | import {useLocation} from '@docusaurus/router'; 10 | import lzString from 'lz-string'; 11 | 12 | import Playground from '../components/Playground'; 13 | 14 | import clsx from 'clsx'; 15 | import styles from './playground.module.css'; 16 | import useIsBrowser from '@docusaurus/useIsBrowser'; 17 | 18 | const defaultCode = ` 19 | 20 | 21 | 22 | 23 | 24 | `.trim(); 25 | 26 | export default function PlaygroundPage(): JSX.Element { 27 | const code = useCodeFromQueryParam(); 28 | 29 | return ( 30 | // @ts-ignore missing prop for `wrapperClassName` 31 | 32 | 38 | 39 | ); 40 | } 41 | 42 | function useCodeFromQueryParam(): string { 43 | const location = useLocation(); 44 | 45 | // We don't know the query param ahead of time when doing SSR, so just render 46 | // blank to avoid the appearance of code changing. 47 | if (!useIsBrowser()) { 48 | return ''; 49 | } 50 | 51 | const params = new URLSearchParams(location.search); 52 | const codeParam = params.get('code'); 53 | return codeParam 54 | ? lzString.decompressFromEncodedURIComponent(codeParam) 55 | : defaultCode; 56 | } 57 | -------------------------------------------------------------------------------- /website/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/static/.nojekyll -------------------------------------------------------------------------------- /website/static/img/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/static/img/docusaurus.png -------------------------------------------------------------------------------- /website/static/img/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 11 | 13 | 14 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /website/static/img/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /website/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 11 | 13 | 14 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /website/static/img/opengraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/yoga/c935fd5e1067cf3e7e3543b8b5fb1ef53d7a0b62/website/static/img/opengraph.png -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // This file is not used in compilation. It is here just for a nice editor experience. 3 | "extends": "@docusaurus/tsconfig", 4 | "compilerOptions": { 5 | "baseUrl": ".", 6 | "target": "es2022", 7 | "allowImportingTsExtensions": true, 8 | "strict": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /yoga/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # 3 | # This source code is licensed under the MIT license found in the 4 | # LICENSE file in the root directory of this source tree. 5 | 6 | 7 | cmake_minimum_required(VERSION 3.13...3.26) 8 | project(yogacore) 9 | set(CMAKE_VERBOSE_MAKEFILE on) 10 | 11 | if(TARGET yogacore) 12 | return() 13 | endif() 14 | 15 | include(CheckIPOSupported) 16 | 17 | set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) 18 | include(${YOGA_ROOT}/cmake/project-defaults.cmake) 19 | 20 | 21 | file(GLOB SOURCES CONFIGURE_DEPENDS 22 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 23 | ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) 24 | 25 | add_library(yogacore STATIC ${SOURCES}) 26 | 27 | # Yoga conditionally uses when building for Android 28 | if (ANDROID) 29 | target_link_libraries(yogacore log) 30 | endif() 31 | 32 | check_ipo_supported(RESULT result) 33 | if(result) 34 | set_target_properties(yogacore PROPERTIES 35 | CMAKE_INTERPROCEDURAL_OPTIMIZATION true) 36 | endif() 37 | 38 | target_include_directories(yogacore 39 | PUBLIC 40 | $ 41 | $) 42 | -------------------------------------------------------------------------------- /yoga/YGNodeLayout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | YG_EXTERN_C_BEGIN 17 | 18 | YG_EXPORT float YGNodeLayoutGetLeft(YGNodeConstRef node); 19 | YG_EXPORT float YGNodeLayoutGetTop(YGNodeConstRef node); 20 | YG_EXPORT float YGNodeLayoutGetRight(YGNodeConstRef node); 21 | YG_EXPORT float YGNodeLayoutGetBottom(YGNodeConstRef node); 22 | YG_EXPORT float YGNodeLayoutGetWidth(YGNodeConstRef node); 23 | YG_EXPORT float YGNodeLayoutGetHeight(YGNodeConstRef node); 24 | YG_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeConstRef node); 25 | YG_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeConstRef node); 26 | 27 | // Get the computed values for these nodes after performing layout. If they were 28 | // set using point values then the returned value will be the same as 29 | // YGNodeStyleGetXXX. However if they were set using a percentage value then the 30 | // returned value is the computed value used during layout. 31 | YG_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge); 32 | YG_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge); 33 | YG_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge); 34 | 35 | /** 36 | * Return the measured height of the node, before layout rounding 37 | */ 38 | YG_EXPORT float YGNodeLayoutGetRawHeight(YGNodeConstRef node); 39 | 40 | /** 41 | * Return the measured width of the node, before layout rounding 42 | */ 43 | YG_EXPORT float YGNodeLayoutGetRawWidth(YGNodeConstRef node); 44 | 45 | YG_EXTERN_C_END 46 | -------------------------------------------------------------------------------- /yoga/YGPixelGrid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | using namespace facebook; 13 | using namespace facebook::yoga; 14 | 15 | float YGRoundValueToPixelGrid( 16 | const double value, 17 | const double pointScaleFactor, 18 | const bool forceCeil, 19 | const bool forceFloor) { 20 | return yoga::roundValueToPixelGrid( 21 | value, pointScaleFactor, forceCeil, forceFloor); 22 | } 23 | -------------------------------------------------------------------------------- /yoga/YGPixelGrid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | YG_EXTERN_C_BEGIN 17 | 18 | /** 19 | * Rounds a point value to the nearest whole pixel, given a pointScaleFactor 20 | * describing pixel density. 21 | * @returns the rounded value in points 22 | */ 23 | YG_EXPORT float YGRoundValueToPixelGrid( 24 | double value, 25 | double pointScaleFactor, 26 | bool forceCeil, 27 | bool forceFloor); 28 | 29 | YG_EXTERN_C_END 30 | -------------------------------------------------------------------------------- /yoga/YGValue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | using namespace facebook; 12 | using namespace facebook::yoga; 13 | 14 | const YGValue YGValueZero = {0, YGUnitPoint}; 15 | const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined}; 16 | const YGValue YGValueAuto = {YGUndefined, YGUnitAuto}; 17 | 18 | bool YGFloatIsUndefined(const float value) { 19 | return yoga::isUndefined(value); 20 | } 21 | -------------------------------------------------------------------------------- /yoga/Yoga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | /** 11 | * `#include ` includes all of Yoga's public headers. 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | -------------------------------------------------------------------------------- /yoga/algorithm/AbsoluteLayout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga { 14 | 15 | void layoutAbsoluteChild( 16 | const yoga::Node* containingNode, 17 | const yoga::Node* node, 18 | yoga::Node* child, 19 | float containingBlockWidth, 20 | float containingBlockHeight, 21 | SizingMode widthMode, 22 | Direction direction, 23 | LayoutData& layoutMarkerData, 24 | uint32_t depth, 25 | uint32_t generationCount); 26 | 27 | // Returns if some absolute descendant has new layout 28 | bool layoutAbsoluteDescendants( 29 | yoga::Node* containingNode, 30 | yoga::Node* currentNode, 31 | SizingMode widthSizingMode, 32 | Direction currentNodeDirection, 33 | LayoutData& layoutMarkerData, 34 | uint32_t currentDepth, 35 | uint32_t generationCount, 36 | float currentNodeMainOffsetFromContainingBlock, 37 | float currentNodeCrossOffsetFromContainingBlock, 38 | float containingNodeAvailableInnerWidth, 39 | float containingNodeAvailableInnerHeight); 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/algorithm/Baseline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga { 14 | 15 | // Calculate baseline represented as an offset from the top edge of the node. 16 | float calculateBaseline(const yoga::Node* node); 17 | 18 | // Whether any of the children of this node participate in baseline alignment 19 | bool isBaselineLayout(const yoga::Node* node); 20 | 21 | } // namespace facebook::yoga 22 | -------------------------------------------------------------------------------- /yoga/algorithm/Cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga { 14 | 15 | bool canUseCachedMeasurement( 16 | SizingMode widthMode, 17 | float availableWidth, 18 | SizingMode heightMode, 19 | float availableHeight, 20 | SizingMode lastWidthMode, 21 | float lastAvailableWidth, 22 | SizingMode lastHeightMode, 23 | float lastAvailableHeight, 24 | float lastComputedWidth, 25 | float lastComputedHeight, 26 | float marginRow, 27 | float marginColumn, 28 | const yoga::Config* config); 29 | 30 | } // namespace facebook::yoga 31 | -------------------------------------------------------------------------------- /yoga/algorithm/CalculateLayout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook::yoga { 16 | 17 | void calculateLayout( 18 | yoga::Node* node, 19 | float ownerWidth, 20 | float ownerHeight, 21 | Direction ownerDirection); 22 | 23 | bool calculateLayoutInternal( 24 | yoga::Node* node, 25 | float availableWidth, 26 | float availableHeight, 27 | Direction ownerDirection, 28 | SizingMode widthSizingMode, 29 | SizingMode heightSizingMode, 30 | float ownerWidth, 31 | float ownerHeight, 32 | bool performLayout, 33 | LayoutPassReason reason, 34 | LayoutData& layoutMarkerData, 35 | uint32_t depth, 36 | uint32_t generationCount); 37 | 38 | } // namespace facebook::yoga 39 | -------------------------------------------------------------------------------- /yoga/algorithm/PixelGrid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook::yoga { 14 | 15 | // Round a point value to the nearest physical pixel based on DPI 16 | // (pointScaleFactor) 17 | float roundValueToPixelGrid( 18 | double value, 19 | double pointScaleFactor, 20 | bool forceCeil, 21 | bool forceFloor); 22 | 23 | // Round the layout results of a node and its subtree to the pixel grid. 24 | void roundLayoutResultsToPixelGrid( 25 | yoga::Node* node, 26 | double absoluteLeft, 27 | double absoluteTop); 28 | 29 | } // namespace facebook::yoga 30 | -------------------------------------------------------------------------------- /yoga/algorithm/TrailingPosition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook::yoga { 16 | 17 | // Given an offset to an edge, returns the offset to the opposite edge on the 18 | // same axis. This assumes that the width/height of both nodes is determined at 19 | // this point. 20 | inline float getPositionOfOppositeEdge( 21 | float position, 22 | FlexDirection axis, 23 | const yoga::Node* const containingNode, 24 | const yoga::Node* const node) { 25 | return containingNode->getLayout().measuredDimension(dimension(axis)) - 26 | node->getLayout().measuredDimension(dimension(axis)) - position; 27 | } 28 | 29 | inline void setChildTrailingPosition( 30 | const yoga::Node* const node, 31 | yoga::Node* const child, 32 | const FlexDirection axis) { 33 | child->setLayoutPosition( 34 | getPositionOfOppositeEdge( 35 | child->getLayout().position(flexStartEdge(axis)), axis, node, child), 36 | flexEndEdge(axis)); 37 | } 38 | 39 | inline bool needsTrailingPosition(const FlexDirection axis) { 40 | return axis == FlexDirection::RowReverse || 41 | axis == FlexDirection::ColumnReverse; 42 | } 43 | 44 | } // namespace facebook::yoga 45 | -------------------------------------------------------------------------------- /yoga/debug/AssertFatal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | [[noreturn]] void fatalWithMessage(const char* message) { 19 | #if defined(__cpp_exceptions) 20 | throw std::logic_error(message); 21 | #else 22 | static_cast(message); // Unused 23 | std::terminate(); 24 | #endif 25 | } 26 | 27 | void assertFatal(const bool condition, const char* message) { 28 | if (!condition) { 29 | yoga::log(LogLevel::Fatal, "%s\n", message); 30 | fatalWithMessage(message); 31 | } 32 | } 33 | 34 | void assertFatalWithNode( 35 | const yoga::Node* const node, 36 | const bool condition, 37 | const char* message) { 38 | if (!condition) { 39 | yoga::log(node, LogLevel::Fatal, "%s\n", message); 40 | fatalWithMessage(message); 41 | } 42 | } 43 | 44 | void assertFatalWithConfig( 45 | const yoga::Config* const config, 46 | const bool condition, 47 | const char* message) { 48 | if (!condition) { 49 | yoga::log(config, LogLevel::Fatal, "%s\n", message); 50 | fatalWithMessage(message); 51 | } 52 | } 53 | 54 | } // namespace facebook::yoga 55 | -------------------------------------------------------------------------------- /yoga/debug/AssertFatal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook::yoga { 13 | 14 | class Node; 15 | class Config; 16 | 17 | [[noreturn]] void fatalWithMessage(const char* message); 18 | 19 | void assertFatal(bool condition, const char* message); 20 | void assertFatalWithNode( 21 | const yoga::Node* node, 22 | bool condition, 23 | const char* message); 24 | void assertFatalWithConfig( 25 | const yoga::Config* config, 26 | bool condition, 27 | const char* message); 28 | 29 | } // namespace facebook::yoga 30 | -------------------------------------------------------------------------------- /yoga/debug/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | void log(LogLevel level, const char* format, ...) noexcept; 19 | 20 | void log( 21 | const yoga::Node* node, 22 | LogLevel level, 23 | const char* format, 24 | ...) noexcept; 25 | 26 | void log( 27 | const yoga::Config* config, 28 | LogLevel level, 29 | const char* format, 30 | ...) noexcept; 31 | 32 | YGLogger getDefaultLogger(); 33 | 34 | } // namespace facebook::yoga 35 | -------------------------------------------------------------------------------- /yoga/enums/Align.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Align : uint8_t { 19 | Auto = YGAlignAuto, 20 | FlexStart = YGAlignFlexStart, 21 | Center = YGAlignCenter, 22 | FlexEnd = YGAlignFlexEnd, 23 | Stretch = YGAlignStretch, 24 | Baseline = YGAlignBaseline, 25 | SpaceBetween = YGAlignSpaceBetween, 26 | SpaceAround = YGAlignSpaceAround, 27 | SpaceEvenly = YGAlignSpaceEvenly, 28 | }; 29 | 30 | template <> 31 | constexpr int32_t ordinalCount() { 32 | return 9; 33 | } 34 | 35 | constexpr Align scopedEnum(YGAlign unscoped) { 36 | return static_cast(unscoped); 37 | } 38 | 39 | constexpr YGAlign unscopedEnum(Align scoped) { 40 | return static_cast(scoped); 41 | } 42 | 43 | inline const char* toString(Align e) { 44 | return YGAlignToString(unscopedEnum(e)); 45 | } 46 | 47 | } // namespace facebook::yoga 48 | -------------------------------------------------------------------------------- /yoga/enums/BoxSizing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class BoxSizing : uint8_t { 19 | BorderBox = YGBoxSizingBorderBox, 20 | ContentBox = YGBoxSizingContentBox, 21 | }; 22 | 23 | template <> 24 | constexpr int32_t ordinalCount() { 25 | return 2; 26 | } 27 | 28 | constexpr BoxSizing scopedEnum(YGBoxSizing unscoped) { 29 | return static_cast(unscoped); 30 | } 31 | 32 | constexpr YGBoxSizing unscopedEnum(BoxSizing scoped) { 33 | return static_cast(scoped); 34 | } 35 | 36 | inline const char* toString(BoxSizing e) { 37 | return YGBoxSizingToString(unscopedEnum(e)); 38 | } 39 | 40 | } // namespace facebook::yoga 41 | -------------------------------------------------------------------------------- /yoga/enums/Dimension.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Dimension : uint8_t { 19 | Width = YGDimensionWidth, 20 | Height = YGDimensionHeight, 21 | }; 22 | 23 | template <> 24 | constexpr int32_t ordinalCount() { 25 | return 2; 26 | } 27 | 28 | constexpr Dimension scopedEnum(YGDimension unscoped) { 29 | return static_cast(unscoped); 30 | } 31 | 32 | constexpr YGDimension unscopedEnum(Dimension scoped) { 33 | return static_cast(scoped); 34 | } 35 | 36 | inline const char* toString(Dimension e) { 37 | return YGDimensionToString(unscopedEnum(e)); 38 | } 39 | 40 | } // namespace facebook::yoga 41 | -------------------------------------------------------------------------------- /yoga/enums/Direction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Direction : uint8_t { 19 | Inherit = YGDirectionInherit, 20 | LTR = YGDirectionLTR, 21 | RTL = YGDirectionRTL, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr Direction scopedEnum(YGDirection unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGDirection unscopedEnum(Direction scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Direction e) { 38 | return YGDirectionToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/Display.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Display : uint8_t { 19 | Flex = YGDisplayFlex, 20 | None = YGDisplayNone, 21 | Contents = YGDisplayContents, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr Display scopedEnum(YGDisplay unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGDisplay unscopedEnum(Display scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Display e) { 38 | return YGDisplayToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/Edge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Edge : uint8_t { 19 | Left = YGEdgeLeft, 20 | Top = YGEdgeTop, 21 | Right = YGEdgeRight, 22 | Bottom = YGEdgeBottom, 23 | Start = YGEdgeStart, 24 | End = YGEdgeEnd, 25 | Horizontal = YGEdgeHorizontal, 26 | Vertical = YGEdgeVertical, 27 | All = YGEdgeAll, 28 | }; 29 | 30 | template <> 31 | constexpr int32_t ordinalCount() { 32 | return 9; 33 | } 34 | 35 | constexpr Edge scopedEnum(YGEdge unscoped) { 36 | return static_cast(unscoped); 37 | } 38 | 39 | constexpr YGEdge unscopedEnum(Edge scoped) { 40 | return static_cast(scoped); 41 | } 42 | 43 | inline const char* toString(Edge e) { 44 | return YGEdgeToString(unscopedEnum(e)); 45 | } 46 | 47 | } // namespace facebook::yoga 48 | -------------------------------------------------------------------------------- /yoga/enums/Errata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Errata : uint32_t { 19 | None = YGErrataNone, 20 | StretchFlexBasis = YGErrataStretchFlexBasis, 21 | AbsolutePositionWithoutInsetsExcludesPadding = YGErrataAbsolutePositionWithoutInsetsExcludesPadding, 22 | AbsolutePercentAgainstInnerSize = YGErrataAbsolutePercentAgainstInnerSize, 23 | All = YGErrataAll, 24 | Classic = YGErrataClassic, 25 | }; 26 | 27 | YG_DEFINE_ENUM_FLAG_OPERATORS(Errata) 28 | 29 | constexpr Errata scopedEnum(YGErrata unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGErrata unscopedEnum(Errata scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Errata e) { 38 | return YGErrataToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/ExperimentalFeature.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class ExperimentalFeature : uint8_t { 19 | WebFlexBasis = YGExperimentalFeatureWebFlexBasis, 20 | }; 21 | 22 | template <> 23 | constexpr int32_t ordinalCount() { 24 | return 1; 25 | } 26 | 27 | constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) { 28 | return static_cast(unscoped); 29 | } 30 | 31 | constexpr YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) { 32 | return static_cast(scoped); 33 | } 34 | 35 | inline const char* toString(ExperimentalFeature e) { 36 | return YGExperimentalFeatureToString(unscopedEnum(e)); 37 | } 38 | 39 | } // namespace facebook::yoga 40 | -------------------------------------------------------------------------------- /yoga/enums/FlexDirection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class FlexDirection : uint8_t { 19 | Column = YGFlexDirectionColumn, 20 | ColumnReverse = YGFlexDirectionColumnReverse, 21 | Row = YGFlexDirectionRow, 22 | RowReverse = YGFlexDirectionRowReverse, 23 | }; 24 | 25 | template <> 26 | constexpr int32_t ordinalCount() { 27 | return 4; 28 | } 29 | 30 | constexpr FlexDirection scopedEnum(YGFlexDirection unscoped) { 31 | return static_cast(unscoped); 32 | } 33 | 34 | constexpr YGFlexDirection unscopedEnum(FlexDirection scoped) { 35 | return static_cast(scoped); 36 | } 37 | 38 | inline const char* toString(FlexDirection e) { 39 | return YGFlexDirectionToString(unscopedEnum(e)); 40 | } 41 | 42 | } // namespace facebook::yoga 43 | -------------------------------------------------------------------------------- /yoga/enums/Gutter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Gutter : uint8_t { 19 | Column = YGGutterColumn, 20 | Row = YGGutterRow, 21 | All = YGGutterAll, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr Gutter scopedEnum(YGGutter unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGGutter unscopedEnum(Gutter scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Gutter e) { 38 | return YGGutterToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/Justify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Justify : uint8_t { 19 | FlexStart = YGJustifyFlexStart, 20 | Center = YGJustifyCenter, 21 | FlexEnd = YGJustifyFlexEnd, 22 | SpaceBetween = YGJustifySpaceBetween, 23 | SpaceAround = YGJustifySpaceAround, 24 | SpaceEvenly = YGJustifySpaceEvenly, 25 | }; 26 | 27 | template <> 28 | constexpr int32_t ordinalCount() { 29 | return 6; 30 | } 31 | 32 | constexpr Justify scopedEnum(YGJustify unscoped) { 33 | return static_cast(unscoped); 34 | } 35 | 36 | constexpr YGJustify unscopedEnum(Justify scoped) { 37 | return static_cast(scoped); 38 | } 39 | 40 | inline const char* toString(Justify e) { 41 | return YGJustifyToString(unscopedEnum(e)); 42 | } 43 | 44 | } // namespace facebook::yoga 45 | -------------------------------------------------------------------------------- /yoga/enums/LogLevel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class LogLevel : uint8_t { 19 | Error = YGLogLevelError, 20 | Warn = YGLogLevelWarn, 21 | Info = YGLogLevelInfo, 22 | Debug = YGLogLevelDebug, 23 | Verbose = YGLogLevelVerbose, 24 | Fatal = YGLogLevelFatal, 25 | }; 26 | 27 | template <> 28 | constexpr int32_t ordinalCount() { 29 | return 6; 30 | } 31 | 32 | constexpr LogLevel scopedEnum(YGLogLevel unscoped) { 33 | return static_cast(unscoped); 34 | } 35 | 36 | constexpr YGLogLevel unscopedEnum(LogLevel scoped) { 37 | return static_cast(scoped); 38 | } 39 | 40 | inline const char* toString(LogLevel e) { 41 | return YGLogLevelToString(unscopedEnum(e)); 42 | } 43 | 44 | } // namespace facebook::yoga 45 | -------------------------------------------------------------------------------- /yoga/enums/MeasureMode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class MeasureMode : uint8_t { 19 | Undefined = YGMeasureModeUndefined, 20 | Exactly = YGMeasureModeExactly, 21 | AtMost = YGMeasureModeAtMost, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr MeasureMode scopedEnum(YGMeasureMode unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGMeasureMode unscopedEnum(MeasureMode scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(MeasureMode e) { 38 | return YGMeasureModeToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/NodeType.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class NodeType : uint8_t { 19 | Default = YGNodeTypeDefault, 20 | Text = YGNodeTypeText, 21 | }; 22 | 23 | template <> 24 | constexpr int32_t ordinalCount() { 25 | return 2; 26 | } 27 | 28 | constexpr NodeType scopedEnum(YGNodeType unscoped) { 29 | return static_cast(unscoped); 30 | } 31 | 32 | constexpr YGNodeType unscopedEnum(NodeType scoped) { 33 | return static_cast(scoped); 34 | } 35 | 36 | inline const char* toString(NodeType e) { 37 | return YGNodeTypeToString(unscopedEnum(e)); 38 | } 39 | 40 | } // namespace facebook::yoga 41 | -------------------------------------------------------------------------------- /yoga/enums/Overflow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Overflow : uint8_t { 19 | Visible = YGOverflowVisible, 20 | Hidden = YGOverflowHidden, 21 | Scroll = YGOverflowScroll, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr Overflow scopedEnum(YGOverflow unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGOverflow unscopedEnum(Overflow scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Overflow e) { 38 | return YGOverflowToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/PhysicalEdge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace facebook::yoga { 13 | 14 | enum class PhysicalEdge : uint32_t { 15 | Left = yoga::to_underlying(Edge::Left), 16 | Top = yoga::to_underlying(Edge::Top), 17 | Right = yoga::to_underlying(Edge::Right), 18 | Bottom = yoga::to_underlying(Edge::Bottom), 19 | }; 20 | 21 | } // namespace facebook::yoga 22 | -------------------------------------------------------------------------------- /yoga/enums/PositionType.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class PositionType : uint8_t { 19 | Static = YGPositionTypeStatic, 20 | Relative = YGPositionTypeRelative, 21 | Absolute = YGPositionTypeAbsolute, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr PositionType scopedEnum(YGPositionType unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGPositionType unscopedEnum(PositionType scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(PositionType e) { 38 | return YGPositionTypeToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/enums/Unit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Unit : uint8_t { 19 | Undefined = YGUnitUndefined, 20 | Point = YGUnitPoint, 21 | Percent = YGUnitPercent, 22 | Auto = YGUnitAuto, 23 | MaxContent = YGUnitMaxContent, 24 | FitContent = YGUnitFitContent, 25 | Stretch = YGUnitStretch, 26 | }; 27 | 28 | template <> 29 | constexpr int32_t ordinalCount() { 30 | return 7; 31 | } 32 | 33 | constexpr Unit scopedEnum(YGUnit unscoped) { 34 | return static_cast(unscoped); 35 | } 36 | 37 | constexpr YGUnit unscopedEnum(Unit scoped) { 38 | return static_cast(scoped); 39 | } 40 | 41 | inline const char* toString(Unit e) { 42 | return YGUnitToString(unscopedEnum(e)); 43 | } 44 | 45 | } // namespace facebook::yoga 46 | -------------------------------------------------------------------------------- /yoga/enums/Wrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | // @generated by enums.py 9 | // clang-format off 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace facebook::yoga { 17 | 18 | enum class Wrap : uint8_t { 19 | NoWrap = YGWrapNoWrap, 20 | Wrap = YGWrapWrap, 21 | WrapReverse = YGWrapWrapReverse, 22 | }; 23 | 24 | template <> 25 | constexpr int32_t ordinalCount() { 26 | return 3; 27 | } 28 | 29 | constexpr Wrap scopedEnum(YGWrap unscoped) { 30 | return static_cast(unscoped); 31 | } 32 | 33 | constexpr YGWrap unscopedEnum(Wrap scoped) { 34 | return static_cast(scoped); 35 | } 36 | 37 | inline const char* toString(Wrap e) { 38 | return YGWrapToString(unscopedEnum(e)); 39 | } 40 | 41 | } // namespace facebook::yoga 42 | -------------------------------------------------------------------------------- /yoga/module.modulemap: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | module yoga [system] { 9 | module core { 10 | header "YGConfig.h" 11 | header "YGEnums.h" 12 | header "YGMacros.h" 13 | header "YGNode.h" 14 | header "YGNodeLayout.h" 15 | header "YGNodeStyle.h" 16 | header "YGPixelGrid.h" 17 | header "YGValue.h" 18 | header "Yoga.h" 19 | export * 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /yoga/node/CachedMeasurement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace facebook::yoga { 18 | 19 | struct CachedMeasurement { 20 | float availableWidth{-1}; 21 | float availableHeight{-1}; 22 | SizingMode widthSizingMode{SizingMode::MaxContent}; 23 | SizingMode heightSizingMode{SizingMode::MaxContent}; 24 | 25 | float computedWidth{-1}; 26 | float computedHeight{-1}; 27 | 28 | bool operator==(CachedMeasurement measurement) const { 29 | bool isEqual = widthSizingMode == measurement.widthSizingMode && 30 | heightSizingMode == measurement.heightSizingMode; 31 | 32 | if (!yoga::isUndefined(availableWidth) || 33 | !yoga::isUndefined(measurement.availableWidth)) { 34 | isEqual = isEqual && availableWidth == measurement.availableWidth; 35 | } 36 | if (!yoga::isUndefined(availableHeight) || 37 | !yoga::isUndefined(measurement.availableHeight)) { 38 | isEqual = isEqual && availableHeight == measurement.availableHeight; 39 | } 40 | if (!yoga::isUndefined(computedWidth) || 41 | !yoga::isUndefined(measurement.computedWidth)) { 42 | isEqual = isEqual && computedWidth == measurement.computedWidth; 43 | } 44 | if (!yoga::isUndefined(computedHeight) || 45 | !yoga::isUndefined(measurement.computedHeight)) { 46 | isEqual = isEqual && computedHeight == measurement.computedHeight; 47 | } 48 | 49 | return isEqual; 50 | } 51 | }; 52 | 53 | } // namespace facebook::yoga 54 | --------------------------------------------------------------------------------