Modularize and document public API (#1449)

Summary:
X-link: https://github.com/facebook/react-native/pull/41317

Pull Request resolved: https://github.com/facebook/yoga/pull/1449

This aims to clean up the public Yoga C API, by:
1. Documenting public YGNode, YGValue, YGConfig APIs
2. Splitting APIs for specific objects into different header files (because Yoga.h was big enough without documentation)
3. Reordering headers and definitions for consistent grouping

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D50963424

fbshipit-source-id: 45124b7370256fc63aefd6d5b7641466e9a79d3b
This commit is contained in:
Nick Gerleman
2023-11-10 16:31:46 -08:00
committed by Facebook GitHub Bot
parent 12a8d16b62
commit c46ea9c6f5
15 changed files with 1717 additions and 1287 deletions

102
yoga/YGConfig.cpp Normal file
View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <yoga/Yoga.h>
#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
using namespace facebook;
using namespace facebook::yoga;
YGConfigRef YGConfigNew(void) {
return new yoga::Config(getDefaultLogger());
}
void YGConfigFree(const YGConfigRef config) {
delete resolveRef(config);
}
YGConfigConstRef YGConfigGetDefault() {
return &yoga::Config::getDefault();
}
void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
resolveRef(config)->setUseWebDefaults(enabled);
}
bool YGConfigGetUseWebDefaults(const YGConfigConstRef config) {
return resolveRef(config)->useWebDefaults();
}
void YGConfigSetPointScaleFactor(
const YGConfigRef config,
const float pixelsInPoint) {
yoga::assertFatalWithConfig(
resolveRef(config),
pixelsInPoint >= 0.0f,
"Scale factor should not be less than zero");
// We store points for Pixel as we will use it for rounding
if (pixelsInPoint == 0.0f) {
// Zero is used to skip rounding
resolveRef(config)->setPointScaleFactor(0.0f);
} else {
resolveRef(config)->setPointScaleFactor(pixelsInPoint);
}
}
float YGConfigGetPointScaleFactor(const YGConfigConstRef config) {
return resolveRef(config)->getPointScaleFactor();
}
void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
resolveRef(config)->setErrata(scopedEnum(errata));
}
YGErrata YGConfigGetErrata(YGConfigConstRef config) {
return unscopedEnum(resolveRef(config)->getErrata());
}
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
if (logger != nullptr) {
resolveRef(config)->setLogger(logger);
} else {
resolveRef(config)->setLogger(getDefaultLogger());
}
}
void YGConfigSetContext(const YGConfigRef config, void* context) {
resolveRef(config)->setContext(context);
}
void* YGConfigGetContext(const YGConfigConstRef config) {
return resolveRef(config)->getContext();
}
void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature,
const bool enabled) {
resolveRef(config)->setExperimentalFeatureEnabled(
scopedEnum(feature), enabled);
}
bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigConstRef config,
const YGExperimentalFeature feature) {
return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature));
}
void YGConfigSetCloneNodeFunc(
const YGConfigRef config,
const YGCloneNodeFunc callback) {
resolveRef(config)->setCloneNodeCallback(callback);
}
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) {
resolveRef(config)->setShouldPrintTree(enabled);
}