Enable Clang Tidy #1586
217
.clang-tidy
Normal file
217
.clang-tidy
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
---
|
||||||
|
InheritParentConfig: true
|
||||||
|
Checks: '>
|
||||||
|
bugprone-argument-comment,
|
||||||
|
bugprone-assert-side-effect,
|
||||||
|
bugprone-bool-pointer-implicit-conversion,
|
||||||
|
bugprone-copy-constructor-init,
|
||||||
|
bugprone-dangling-handle,
|
||||||
|
bugprone-exception-escape,
|
||||||
|
bugprone-fold-init-type,
|
||||||
|
bugprone-forward-declaration-namespace,
|
||||||
|
bugprone-forwarding-reference-overload,
|
||||||
|
bugprone-incorrect-enable-if,
|
||||||
|
bugprone-inaccurate-erase,
|
||||||
|
bugprone-incorrect-roundings,
|
||||||
|
bugprone-infinite-loop,
|
||||||
|
bugprone-integer-division,
|
||||||
|
bugprone-macro-parentheses,
|
||||||
|
bugprone-macro-repeated-side-effects,
|
||||||
|
bugprone-misplaced-operator-in-strlen-in-alloc,
|
||||||
|
bugprone-misplaced-widening-cast,
|
||||||
|
bugprone-move-forwarding-reference,
|
||||||
|
bugprone-multiple-statement-macro,
|
||||||
|
bugprone-optional-value-conversion,
|
||||||
|
bugprone-parent-virtual-call,
|
||||||
|
bugprone-redundant-branch-condition,
|
||||||
|
bugprone-shared-ptr-array-mismatch,
|
||||||
|
bugprone-signed-char-misuse,
|
||||||
|
bugprone-sizeof-container,
|
||||||
|
bugprone-sizeof-expression,
|
||||||
|
bugprone-string-constructor,
|
||||||
|
bugprone-string-integer-assignment,
|
||||||
|
bugprone-string-literal-with-embedded-nul,
|
||||||
|
bugprone-suspicious-enum-usage,
|
||||||
|
bugprone-suspicious-memset-usage,
|
||||||
|
bugprone-suspicious-missing-comma,
|
||||||
|
bugprone-suspicious-semicolon,
|
||||||
|
bugprone-suspicious-string-compare,
|
||||||
|
bugprone-swapped-arguments,
|
||||||
|
bugprone-terminating-continue,
|
||||||
|
bugprone-throw-keyword-missing,
|
||||||
|
bugprone-too-small-loop-variable,
|
||||||
|
bugprone-undefined-memory-manipulation,
|
||||||
|
bugprone-undelegated-constructor,
|
||||||
|
bugprone-unique-ptr-array-mismatch,
|
||||||
|
bugprone-unsafe-functions,
|
||||||
|
bugprone-unused-raii,
|
||||||
|
bugprone-unused-return-value,
|
||||||
|
bugprone-use-after-move,
|
||||||
|
bugprone-virtual-near-miss,
|
||||||
|
clang-analyzer-apiModeling.google.GTest,
|
||||||
|
clang-analyzer-apiModeling.StdCLibraryFunctions,
|
||||||
|
clang-analyzer-apiModeling.TrustNonnull,
|
||||||
|
clang-analyzer-core.builtin.BuiltinFunctions,
|
||||||
|
clang-analyzer-core.builtin.NoReturnFunctions,
|
||||||
|
clang-analyzer-core.CallAndMessage,
|
||||||
|
clang-analyzer-core.DivideZero,
|
||||||
|
clang-analyzer-core.DynamicTypePropagation,
|
||||||
|
clang-analyzer-core.NonnilStringConstants,
|
||||||
|
clang-analyzer-core.NonNullParamChecker,
|
||||||
|
clang-analyzer-core.NullDereference,
|
||||||
|
clang-analyzer-core.StackAddressEscape,
|
||||||
|
clang-analyzer-core.UndefinedBinaryOperatorResult,
|
||||||
|
clang-analyzer-core.uninitialized.ArraySubscript,
|
||||||
|
clang-analyzer-core.uninitialized.Assign,
|
||||||
|
clang-analyzer-core.uninitialized.Branch,
|
||||||
|
clang-analyzer-core.uninitialized.CapturedBlockVariable,
|
||||||
|
clang-analyzer-core.uninitialized.UndefReturn,
|
||||||
|
clang-analyzer-core.VLASize,
|
||||||
|
clang-analyzer-cplusplus.InnerPointer,
|
||||||
|
clang-analyzer-cplusplus.Move,
|
||||||
|
clang-analyzer-cplusplus.NewDelete,
|
||||||
|
clang-analyzer-cplusplus.NewDeleteLeaks,
|
||||||
|
clang-analyzer-cplusplus.SelfAssignment,
|
||||||
|
clang-analyzer-deadcode.DeadStores,
|
||||||
|
clang-analyzer-nullability.NullableDereferenced,
|
||||||
|
clang-analyzer-nullability.NullablePassedToNonnull,
|
||||||
|
clang-analyzer-nullability.NullableReturnedFromNonnull,
|
||||||
|
clang-analyzer-nullability.NullPassedToNonnull,
|
||||||
|
clang-analyzer-nullability.NullReturnedFromNonnull,
|
||||||
|
clang-analyzer-optin.cplusplus.VirtualCall,
|
||||||
|
clang-analyzer-optin.mpi.MPI-Checker,
|
||||||
|
clang-analyzer-optin.performance.GCDAntipattern,
|
||||||
|
clang-analyzer-optin.performance.Padding,
|
||||||
|
clang-analyzer-optin.portability.UnixAPI,
|
||||||
|
clang-analyzer-security.FloatLoopCounter,
|
||||||
|
clang-analyzer-security.insecureAPI.bcmp,
|
||||||
|
clang-analyzer-security.insecureAPI.bcopy,
|
||||||
|
clang-analyzer-security.insecureAPI.bzero,
|
||||||
|
clang-analyzer-security.insecureAPI.getpw,
|
||||||
|
clang-analyzer-security.insecureAPI.gets,
|
||||||
|
clang-analyzer-security.insecureAPI.mkstemp,
|
||||||
|
clang-analyzer-security.insecureAPI.mktemp,
|
||||||
|
clang-analyzer-security.insecureAPI.rand,
|
||||||
|
clang-analyzer-security.insecureAPI.strcpy,
|
||||||
|
clang-analyzer-security.insecureAPI.UncheckedReturn,
|
||||||
|
clang-analyzer-security.insecureAPI.vfork,
|
||||||
|
clang-analyzer-unix.API,
|
||||||
|
clang-analyzer-unix.cstring.BadSizeArg,
|
||||||
|
clang-analyzer-unix.cstring.NullArg,
|
||||||
|
clang-analyzer-unix.Malloc,
|
||||||
|
clang-analyzer-unix.MallocSizeof,
|
||||||
|
clang-analyzer-unix.MismatchedDeallocator,
|
||||||
|
clang-analyzer-unix.Vfork,
|
||||||
|
clang-analyzer-valist.CopyToSelf,
|
||||||
|
clang-analyzer-valist.Uninitialized,
|
||||||
|
clang-analyzer-valist.Unterminated,
|
||||||
|
clang-diagnostic-*,
|
||||||
|
cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||||
|
cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
|
cppcoreguidelines-init-variables,
|
||||||
|
cppcoreguidelines-interfaces-global-init,
|
||||||
|
cppcoreguidelines-macro-usage,
|
||||||
|
cppcoreguidelines-missing-std-forward,
|
||||||
|
cppcoreguidelines-narrowing-conversions,
|
||||||
|
cppcoreguidelines-no-malloc,
|
||||||
|
cppcoreguidelines-prefer-member-initializer,
|
||||||
|
cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
|
cppcoreguidelines-pro-type-const-cast,
|
||||||
|
cppcoreguidelines-pro-type-cstyle-cast,
|
||||||
|
cppcoreguidelines-pro-type-member-init,
|
||||||
|
cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
|
cppcoreguidelines-pro-type-union-access,
|
||||||
|
cppcoreguidelines-pro-type-vararg,
|
||||||
|
cppcoreguidelines-slicing,
|
||||||
|
cppcoreguidelines-special-member-functions,
|
||||||
|
facebook-hte-BadEnum,
|
||||||
|
facebook-hte-MissingStatic,
|
||||||
|
google-build-using-namespace,
|
||||||
|
misc-definitions-in-headers,
|
||||||
|
misc-header-include-cycle,
|
||||||
|
misc-misplaced-const,
|
||||||
|
misc-new-delete-overloads,
|
||||||
|
misc-non-copyable-objects,
|
||||||
|
misc-static-assert,
|
||||||
|
misc-throw-by-value-catch-by-reference,
|
||||||
|
misc-unconventional-assign-operator,
|
||||||
|
misc-uniqueptr-reset-release,
|
||||||
|
misc-unused-alias-decls,
|
||||||
|
misc-unused-parameters,
|
||||||
|
misc-unused-using-decls,
|
||||||
|
modernize-avoid-bind,
|
||||||
|
modernize-avoid-c-arrays,
|
||||||
|
modernize-concat-nested-namespaces,
|
||||||
|
modernize-deprecated-headers,
|
||||||
|
modernize-deprecated-ios-base-aliases,
|
||||||
|
modernize-loop-convert,
|
||||||
|
modernize-make-shared,
|
||||||
|
modernize-make-unique,
|
||||||
|
modernize-pass-by-value,
|
||||||
|
modernize-raw-string-literal,
|
||||||
|
modernize-redundant-void-arg,
|
||||||
|
modernize-replace-auto-ptr,
|
||||||
|
modernize-replace-random-shuffle,
|
||||||
|
modernize-return-braced-init-list,
|
||||||
|
modernize-shrink-to-fit,
|
||||||
|
modernize-unary-static-assert,
|
||||||
|
modernize-use-auto,
|
||||||
|
modernize-use-bool-literals,
|
||||||
|
modernize-use-constraints,
|
||||||
|
modernize-use-default-member-init,
|
||||||
|
modernize-use-designated-initializers,
|
||||||
|
modernize-use-emplace,
|
||||||
|
modernize-use-equals-default,
|
||||||
|
modernize-use-equals-delete,
|
||||||
|
modernize-use-noexcept,
|
||||||
|
modernize-use-nullptr,
|
||||||
|
modernize-use-override,
|
||||||
|
modernize-use-starts-ends-with,
|
||||||
|
modernize-use-transparent-functors,
|
||||||
|
modernize-use-using,
|
||||||
|
performance-faster-string-find,
|
||||||
|
performance-for-range-copy,
|
||||||
|
performance-implicit-conversion-in-loop,
|
||||||
|
performance-inefficient-algorithm,
|
||||||
|
performance-inefficient-string-concatenation,
|
||||||
|
performance-inefficient-vector-operation,
|
||||||
|
performance-move-const-arg,
|
||||||
|
performance-move-constructor-init,
|
||||||
|
performance-noexcept-move-constructor,
|
||||||
|
performance-type-promotion-in-math-fn,
|
||||||
|
performance-unnecessary-copy-initialization,
|
||||||
|
performance-unnecessary-value-param,
|
||||||
|
readability-avoid-const-params-in-decls,
|
||||||
|
readability-braces-around-statements,
|
||||||
|
readability-const-return-type,
|
||||||
|
readability-container-size-empty,
|
||||||
|
readability-delete-null-pointer,
|
||||||
|
readability-deleted-default,
|
||||||
|
readability-implicit-bool-conversion,
|
||||||
|
readability-inconsistent-declaration-parameter-name,
|
||||||
|
readability-isolate-declaration,
|
||||||
|
readability-misplaced-array-index,
|
||||||
|
readability-named-parameter,
|
||||||
|
readability-non-const-parameter,
|
||||||
|
readability-redundant-control-flow,
|
||||||
|
readability-redundant-declaration,
|
||||||
|
readability-redundant-function-ptr-dereference,
|
||||||
|
readability-redundant-preprocessor,
|
||||||
|
readability-redundant-smartptr-get,
|
||||||
|
readability-redundant-string-cstr,
|
||||||
|
readability-redundant-string-init,
|
||||||
|
readability-simplify-boolean-expr,
|
||||||
|
readability-simplify-subscript-expr,
|
||||||
|
readability-static-accessed-through-instance,
|
||||||
|
readability-static-definition-in-anonymous-namespace,
|
||||||
|
readability-string-compare,
|
||||||
|
readability-uniqueptr-delete-release,
|
||||||
|
'
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
- key: performance-unnecessary-value-param.AllowedTypes
|
||||||
|
value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;'
|
||||||
|
- key: performance-unnecessary-copy-initialization.AllowedTypes
|
||||||
|
value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$'
|
||||||
|
|
||||||
|
...
|
@@ -113,8 +113,8 @@ std::shared_ptr<const YGConfig> buildConfigFromJson(const json& j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string edgeStringFromPropertyName(
|
std::string edgeStringFromPropertyName(
|
||||||
std::string key,
|
const std::string& key,
|
||||||
std::string propertyName) {
|
const std::string& propertyName) {
|
||||||
return key.substr(propertyName.length() + 1);
|
return key.substr(propertyName.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ std::shared_ptr<YogaNodeAndConfig> buildTreeFromJson(
|
|||||||
if (j.contains("children")) {
|
if (j.contains("children")) {
|
||||||
json children = j["children"];
|
json children = j["children"];
|
||||||
size_t childIndex = 0;
|
size_t childIndex = 0;
|
||||||
for (json child : children) {
|
for (const json& child : children) {
|
||||||
buildTreeFromJson(child, fns, wrapper, childIndex);
|
buildTreeFromJson(child, fns, wrapper, childIndex);
|
||||||
childIndex++;
|
childIndex++;
|
||||||
}
|
}
|
||||||
@@ -331,9 +331,9 @@ BenchmarkResult generateBenchmark(json& capture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void printBenchmarkResult(
|
static void printBenchmarkResult(
|
||||||
std::string name,
|
const std::string& name,
|
||||||
SteadyClockDurations& durations) {
|
SteadyClockDurations& durations) {
|
||||||
std::array<double, kNumRepititions> timesInMs;
|
std::array<double, kNumRepititions> timesInMs{};
|
||||||
double mean = 0;
|
double mean = 0;
|
||||||
for (uint32_t i = 0; i < kNumRepititions; i++) {
|
for (uint32_t i = 0; i < kNumRepititions; i++) {
|
||||||
auto ms = duration<double, std::milli>(durations[i]).count();
|
auto ms = duration<double, std::milli>(durations[i]).count();
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
@@ -21,7 +22,9 @@ struct YogaNodeAndConfig {
|
|||||||
std::shared_ptr<YGNode> node,
|
std::shared_ptr<YGNode> node,
|
||||||
std::shared_ptr<const YGConfig> config,
|
std::shared_ptr<const YGConfig> config,
|
||||||
std::vector<std::shared_ptr<YogaNodeAndConfig>> children)
|
std::vector<std::shared_ptr<YogaNodeAndConfig>> children)
|
||||||
: node_(node), config_(config), children_(children) {}
|
: node_(std::move(node)),
|
||||||
|
config_(std::move(config)),
|
||||||
|
children_(std::move(children)) {}
|
||||||
|
|
||||||
std::shared_ptr<YGNode> node_;
|
std::shared_ptr<YGNode> node_;
|
||||||
std::shared_ptr<const YGConfig> config_;
|
std::shared_ptr<const YGConfig> config_;
|
||||||
|
@@ -22,8 +22,8 @@ static inline bool isAuto(json& j) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string invalidArgumentMessage(
|
static inline std::string invalidArgumentMessage(
|
||||||
std::string arg,
|
const std::string& arg,
|
||||||
std::string enumName) {
|
const std::string& enumName) {
|
||||||
return arg + " does not represent any " + enumName + " values";
|
return arg + " does not represent any " + enumName + " values";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ static inline float floatFromJson(json& j) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFlexDirection flexDirectionFromString(std::string str) {
|
YGFlexDirection flexDirectionFromString(const std::string& str) {
|
||||||
if (str == "row") {
|
if (str == "row") {
|
||||||
return YGFlexDirectionRow;
|
return YGFlexDirectionRow;
|
||||||
} else if (str == "row-reverse") {
|
} else if (str == "row-reverse") {
|
||||||
@@ -50,7 +50,7 @@ YGFlexDirection flexDirectionFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGJustify justifyContentFromString(std::string str) {
|
YGJustify justifyContentFromString(const std::string& str) {
|
||||||
if (str == "flex-start") {
|
if (str == "flex-start") {
|
||||||
return YGJustifyFlexStart;
|
return YGJustifyFlexStart;
|
||||||
} else if (str == "center") {
|
} else if (str == "center") {
|
||||||
@@ -68,7 +68,7 @@ YGJustify justifyContentFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGAlign alignFromString(std::string str) {
|
YGAlign alignFromString(const std::string& str) {
|
||||||
if (str == "auto") {
|
if (str == "auto") {
|
||||||
return YGAlignAuto;
|
return YGAlignAuto;
|
||||||
} else if (str == "flex-start") {
|
} else if (str == "flex-start") {
|
||||||
@@ -92,7 +92,7 @@ YGAlign alignFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGWrap wrapFromString(std::string str) {
|
YGWrap wrapFromString(const std::string& str) {
|
||||||
if (str == "no-wrap") {
|
if (str == "no-wrap") {
|
||||||
return YGWrapNoWrap;
|
return YGWrapNoWrap;
|
||||||
} else if (str == "wrap") {
|
} else if (str == "wrap") {
|
||||||
@@ -104,7 +104,7 @@ YGWrap wrapFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGOverflow overflowFromString(std::string str) {
|
YGOverflow overflowFromString(const std::string& str) {
|
||||||
if (str == "visible") {
|
if (str == "visible") {
|
||||||
return YGOverflowVisible;
|
return YGOverflowVisible;
|
||||||
} else if (str == "hidden") {
|
} else if (str == "hidden") {
|
||||||
@@ -116,7 +116,7 @@ YGOverflow overflowFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGDisplay displayFromString(std::string str) {
|
YGDisplay displayFromString(const std::string& str) {
|
||||||
if (str == "flex") {
|
if (str == "flex") {
|
||||||
return YGDisplayFlex;
|
return YGDisplayFlex;
|
||||||
} else if (str == "none") {
|
} else if (str == "none") {
|
||||||
@@ -126,7 +126,7 @@ YGDisplay displayFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGPositionType positionTypeFromString(std::string str) {
|
YGPositionType positionTypeFromString(const std::string& str) {
|
||||||
if (str == "static") {
|
if (str == "static") {
|
||||||
return YGPositionTypeStatic;
|
return YGPositionTypeStatic;
|
||||||
} else if (str == "relative") {
|
} else if (str == "relative") {
|
||||||
@@ -153,7 +153,7 @@ YGUnit unitFromJson(json& j) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGEdge edgeFromString(std::string str) {
|
YGEdge edgeFromString(const std::string& str) {
|
||||||
if (str == "left") {
|
if (str == "left") {
|
||||||
return YGEdgeLeft;
|
return YGEdgeLeft;
|
||||||
} else if (str == "top") {
|
} else if (str == "top") {
|
||||||
@@ -177,7 +177,7 @@ YGEdge edgeFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGErrata errataFromString(std::string str) {
|
YGErrata errataFromString(const std::string& str) {
|
||||||
if (str == "none") {
|
if (str == "none") {
|
||||||
return YGErrataNone;
|
return YGErrataNone;
|
||||||
} else if (str == "all") {
|
} else if (str == "all") {
|
||||||
@@ -189,7 +189,7 @@ YGErrata errataFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGExperimentalFeature experimentalFeatureFromString(std::string str) {
|
YGExperimentalFeature experimentalFeatureFromString(const std::string& str) {
|
||||||
if (str == "web-flex-basis") {
|
if (str == "web-flex-basis") {
|
||||||
return YGExperimentalFeatureWebFlexBasis;
|
return YGExperimentalFeatureWebFlexBasis;
|
||||||
} else {
|
} else {
|
||||||
@@ -199,12 +199,12 @@ YGExperimentalFeature experimentalFeatureFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string edgeStringFromPropertyName(
|
std::string edgeStringFromPropertyName(
|
||||||
json::iterator it,
|
const json::iterator& it,
|
||||||
std::string propertyName) {
|
const std::string& propertyName) {
|
||||||
return it.key().substr(propertyName.length() + 1);
|
return it.key().substr(propertyName.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGDirection directionFromString(std::string str) {
|
YGDirection directionFromString(const std::string& str) {
|
||||||
if (str == "ltr") {
|
if (str == "ltr") {
|
||||||
return YGDirectionLTR;
|
return YGDirectionLTR;
|
||||||
} else if (str == "rtl") {
|
} else if (str == "rtl") {
|
||||||
@@ -216,7 +216,7 @@ YGDirection directionFromString(std::string str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGMeasureMode measureModeFromString(std::string str) {
|
YGMeasureMode measureModeFromString(const std::string& str) {
|
||||||
if (str == "at-most") {
|
if (str == "at-most") {
|
||||||
return YGMeasureModeAtMost;
|
return YGMeasureModeAtMost;
|
||||||
} else if (str == "exactly") {
|
} else if (str == "exactly") {
|
||||||
|
@@ -18,35 +18,35 @@ namespace facebook::yoga {
|
|||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
YGFlexDirection flexDirectionFromString(std::string str);
|
YGFlexDirection flexDirectionFromString(const std::string& str);
|
||||||
|
|
||||||
YGJustify justifyContentFromString(std::string str);
|
YGJustify justifyContentFromString(const std::string& str);
|
||||||
|
|
||||||
YGAlign alignFromString(std::string str);
|
YGAlign alignFromString(const std::string& str);
|
||||||
|
|
||||||
YGWrap wrapFromString(std::string str);
|
YGWrap wrapFromString(const std::string& str);
|
||||||
|
|
||||||
YGOverflow overflowFromString(std::string str);
|
YGOverflow overflowFromString(const std::string& str);
|
||||||
|
|
||||||
YGDisplay displayFromString(std::string str);
|
YGDisplay displayFromString(const std::string& str);
|
||||||
|
|
||||||
YGPositionType positionTypeFromString(std::string str);
|
YGPositionType positionTypeFromString(const std::string& str);
|
||||||
|
|
||||||
YGUnit unitFromJson(json& j);
|
YGUnit unitFromJson(json& j);
|
||||||
|
|
||||||
YGEdge edgeFromString(std::string str);
|
YGEdge edgeFromString(const std::string& str);
|
||||||
|
|
||||||
YGErrata errataFromString(std::string str);
|
YGErrata errataFromString(const std::string& str);
|
||||||
|
|
||||||
YGExperimentalFeature experimentalFeatureFromString(std::string str);
|
YGExperimentalFeature experimentalFeatureFromString(const std::string& str);
|
||||||
|
|
||||||
std::string edgeStringFromPropertyName(
|
std::string edgeStringFromPropertyName(
|
||||||
json::iterator it,
|
const json::iterator& it,
|
||||||
std::string propertyName);
|
const std::string& propertyName);
|
||||||
|
|
||||||
YGDirection directionFromString(std::string str);
|
YGDirection directionFromString(const std::string& str);
|
||||||
|
|
||||||
YGMeasureMode measureModeFromString(std::string str);
|
YGMeasureMode measureModeFromString(const std::string& str);
|
||||||
|
|
||||||
SerializedMeasureFunc serializedMeasureFuncFromJson(json& j);
|
SerializedMeasureFunc serializedMeasureFuncFromJson(json& j);
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -22,7 +22,7 @@ struct SerializedMeasureFunc {
|
|||||||
YGMeasureMode heightMode{YGMeasureModeUndefined};
|
YGMeasureMode heightMode{YGMeasureModeUndefined};
|
||||||
float outputWidth{0.0f};
|
float outputWidth{0.0f};
|
||||||
float outputHeight{0.0f};
|
float outputHeight{0.0f};
|
||||||
std::chrono::steady_clock::duration::rep durationNs;
|
std::chrono::steady_clock::duration::rep durationNs{};
|
||||||
};
|
};
|
||||||
|
|
||||||
using SerializedMeasureFuncMap =
|
using SerializedMeasureFuncMap =
|
||||||
|
@@ -28,7 +28,7 @@ YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions);
|
|||||||
void serializeTree(
|
void serializeTree(
|
||||||
nlohmann::json& j,
|
nlohmann::json& j,
|
||||||
SerializedMeasureFuncMap& nodesToMeasureFuncs,
|
SerializedMeasureFuncMap& nodesToMeasureFuncs,
|
||||||
YGNodeRef root,
|
YGNodeRef node,
|
||||||
PrintOptions options);
|
PrintOptions options);
|
||||||
|
|
||||||
void serializeLayoutInputs(
|
void serializeLayoutInputs(
|
||||||
|
@@ -62,7 +62,7 @@ class ScopedGlobalRef {
|
|||||||
*
|
*
|
||||||
* @param globalRef the global reference to wrap. Can be NULL.
|
* @param globalRef the global reference to wrap. Can be NULL.
|
||||||
*/
|
*/
|
||||||
ScopedGlobalRef(T globalRef) : mGlobalRef(globalRef) {}
|
explicit ScopedGlobalRef(T globalRef) : mGlobalRef(globalRef) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Equivalent to ScopedGlobalRef(NULL)
|
* Equivalent to ScopedGlobalRef(NULL)
|
||||||
@@ -72,12 +72,12 @@ class ScopedGlobalRef {
|
|||||||
/**
|
/**
|
||||||
* Move construction is allowed.
|
* Move construction is allowed.
|
||||||
*/
|
*/
|
||||||
ScopedGlobalRef(ScopedGlobalRef&& s) : mGlobalRef(s.release()) {}
|
ScopedGlobalRef(ScopedGlobalRef&& s) noexcept : mGlobalRef(s.release()) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move assignment is allowed.
|
* Move assignment is allowed.
|
||||||
*/
|
*/
|
||||||
ScopedGlobalRef& operator=(ScopedGlobalRef&& s) {
|
ScopedGlobalRef& operator=(ScopedGlobalRef&& s) noexcept {
|
||||||
reset(s.release());
|
reset(s.release());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@@ -70,12 +70,13 @@ class ScopedLocalRef {
|
|||||||
/**
|
/**
|
||||||
* Move construction is allowed.
|
* Move construction is allowed.
|
||||||
*/
|
*/
|
||||||
ScopedLocalRef(ScopedLocalRef&& s) : mEnv(s.mEnv), mLocalRef(s.release()) {}
|
ScopedLocalRef(ScopedLocalRef&& s) noexcept
|
||||||
|
: mEnv(s.mEnv), mLocalRef(s.release()) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move assignment is allowed.
|
* Move assignment is allowed.
|
||||||
*/
|
*/
|
||||||
ScopedLocalRef& operator=(ScopedLocalRef&& s) {
|
ScopedLocalRef& operator=(ScopedLocalRef&& s) noexcept {
|
||||||
reset(s.release());
|
reset(s.release());
|
||||||
mEnv = s.mEnv;
|
mEnv = s.mEnv;
|
||||||
return *this;
|
return *this;
|
||||||
|
@@ -36,7 +36,7 @@ class YGNodeEdges {
|
|||||||
BORDER = 4,
|
BORDER = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
YGNodeEdges(YGNodeRef node) {
|
explicit YGNodeEdges(YGNodeRef node) {
|
||||||
auto context = YGNodeContext{};
|
auto context = YGNodeContext{};
|
||||||
context.asVoidPtr = YGNodeGetContext(node);
|
context.asVoidPtr = YGNodeGetContext(node);
|
||||||
edges_ = context.edgesSet;
|
edges_ = context.edgesSet;
|
||||||
|
@@ -54,7 +54,9 @@ static void jni_YGConfigSetExperimentalFeatureEnabledJNI(
|
|||||||
jboolean enabled) {
|
jboolean enabled) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetExperimentalFeatureEnabled(
|
YGConfigSetExperimentalFeatureEnabled(
|
||||||
config, static_cast<YGExperimentalFeature>(feature), enabled);
|
config,
|
||||||
|
static_cast<YGExperimentalFeature>(feature),
|
||||||
|
static_cast<bool>(enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jni_YGConfigSetUseWebDefaultsJNI(
|
static void jni_YGConfigSetUseWebDefaultsJNI(
|
||||||
@@ -63,7 +65,7 @@ static void jni_YGConfigSetUseWebDefaultsJNI(
|
|||||||
jlong nativePointer,
|
jlong nativePointer,
|
||||||
jboolean useWebDefaults) {
|
jboolean useWebDefaults) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetUseWebDefaults(config, useWebDefaults);
|
YGConfigSetUseWebDefaults(config, static_cast<bool>(useWebDefaults));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jni_YGConfigSetPointScaleFactorJNI(
|
static void jni_YGConfigSetPointScaleFactorJNI(
|
||||||
@@ -161,7 +163,7 @@ static void jni_YGConfigSetLoggerJNI(
|
|||||||
auto context =
|
auto context =
|
||||||
reinterpret_cast<ScopedGlobalRef<jobject>*>(YGConfigGetContext(config));
|
reinterpret_cast<ScopedGlobalRef<jobject>*>(YGConfigGetContext(config));
|
||||||
|
|
||||||
if (logger) {
|
if (logger != nullptr) {
|
||||||
if (context == nullptr) {
|
if (context == nullptr) {
|
||||||
context = new ScopedGlobalRef<jobject>();
|
context = new ScopedGlobalRef<jobject>();
|
||||||
YGConfigSetContext(config, context);
|
YGConfigSetContext(config, context);
|
||||||
@@ -225,14 +227,15 @@ static void jni_YGNodeSetIsReferenceBaselineJNI(
|
|||||||
jlong nativePointer,
|
jlong nativePointer,
|
||||||
jboolean isReferenceBaseline) {
|
jboolean isReferenceBaseline) {
|
||||||
YGNodeSetIsReferenceBaseline(
|
YGNodeSetIsReferenceBaseline(
|
||||||
_jlong2YGNodeRef(nativePointer), isReferenceBaseline);
|
_jlong2YGNodeRef(nativePointer), static_cast<bool>(isReferenceBaseline));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jboolean jni_YGNodeIsReferenceBaselineJNI(
|
static jboolean jni_YGNodeIsReferenceBaselineJNI(
|
||||||
JNIEnv* /*env*/,
|
JNIEnv* /*env*/,
|
||||||
jobject /*obj*/,
|
jobject /*obj*/,
|
||||||
jlong nativePointer) {
|
jlong nativePointer) {
|
||||||
return YGNodeIsReferenceBaseline(_jlong2YGNodeRef(nativePointer));
|
return static_cast<jboolean>(
|
||||||
|
YGNodeIsReferenceBaseline(_jlong2YGNodeRef(nativePointer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jni_YGNodeRemoveAllChildrenJNI(
|
static void jni_YGNodeRemoveAllChildrenJNI(
|
||||||
@@ -340,7 +343,7 @@ static void jni_YGNodeCalculateLayoutJNI(
|
|||||||
try {
|
try {
|
||||||
PtrJNodeMapVanilla* layoutContext = nullptr;
|
PtrJNodeMapVanilla* layoutContext = nullptr;
|
||||||
auto map = PtrJNodeMapVanilla{};
|
auto map = PtrJNodeMapVanilla{};
|
||||||
if (nativePointers) {
|
if (nativePointers != nullptr) {
|
||||||
map = PtrJNodeMapVanilla{nativePointers, javaNodes};
|
map = PtrJNodeMapVanilla{nativePointers, javaNodes};
|
||||||
layoutContext = ↦
|
layoutContext = ↦
|
||||||
}
|
}
|
||||||
@@ -356,7 +359,7 @@ static void jni_YGNodeCalculateLayoutJNI(
|
|||||||
YGTransferLayoutOutputsRecursive(env, obj, root);
|
YGTransferLayoutOutputsRecursive(env, obj, root);
|
||||||
} catch (const YogaJniException& jniException) {
|
} catch (const YogaJniException& jniException) {
|
||||||
ScopedLocalRef<jthrowable> throwable = jniException.getThrowable();
|
ScopedLocalRef<jthrowable> throwable = jniException.getThrowable();
|
||||||
if (throwable.get()) {
|
if (throwable.get() != nullptr) {
|
||||||
env->Throw(throwable.get());
|
env->Throw(throwable.get());
|
||||||
}
|
}
|
||||||
} catch (const std::logic_error& ex) {
|
} catch (const std::logic_error& ex) {
|
||||||
@@ -626,8 +629,8 @@ static YGSize YGJNIMeasureFunc(
|
|||||||
|
|
||||||
uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
|
uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
|
||||||
uint32_t hBits = 0xFFFFFFFF & measureResult;
|
uint32_t hBits = 0xFFFFFFFF & measureResult;
|
||||||
float measuredWidth = std::bit_cast<float>(wBits);
|
auto measuredWidth = std::bit_cast<float>(wBits);
|
||||||
float measuredHeight = std::bit_cast<float>(hBits);
|
auto measuredHeight = std::bit_cast<float>(hBits);
|
||||||
|
|
||||||
return YGSize{measuredWidth, measuredHeight};
|
return YGSize{measuredWidth, measuredHeight};
|
||||||
} else {
|
} else {
|
||||||
@@ -645,7 +648,7 @@ static void jni_YGNodeSetHasMeasureFuncJNI(
|
|||||||
jboolean hasMeasureFunc) {
|
jboolean hasMeasureFunc) {
|
||||||
YGNodeSetMeasureFunc(
|
YGNodeSetMeasureFunc(
|
||||||
_jlong2YGNodeRef(nativePointer),
|
_jlong2YGNodeRef(nativePointer),
|
||||||
hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
|
static_cast<bool>(hasMeasureFunc) ? YGJNIMeasureFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float YGJNIBaselineFunc(YGNodeConstRef node, float width, float height) {
|
static float YGJNIBaselineFunc(YGNodeConstRef node, float width, float height) {
|
||||||
@@ -669,7 +672,7 @@ static void jni_YGNodeSetHasBaselineFuncJNI(
|
|||||||
jboolean hasBaselineFunc) {
|
jboolean hasBaselineFunc) {
|
||||||
YGNodeSetBaselineFunc(
|
YGNodeSetBaselineFunc(
|
||||||
_jlong2YGNodeRef(nativePointer),
|
_jlong2YGNodeRef(nativePointer),
|
||||||
hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
static_cast<bool>(hasBaselineFunc) ? YGJNIBaselineFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void jni_YGNodeSetAlwaysFormsContainingBlockJNI(
|
static void jni_YGNodeSetAlwaysFormsContainingBlockJNI(
|
||||||
@@ -678,7 +681,8 @@ static void jni_YGNodeSetAlwaysFormsContainingBlockJNI(
|
|||||||
jlong nativePointer,
|
jlong nativePointer,
|
||||||
jboolean alwaysFormsContainingBlock) {
|
jboolean alwaysFormsContainingBlock) {
|
||||||
YGNodeSetAlwaysFormsContainingBlock(
|
YGNodeSetAlwaysFormsContainingBlock(
|
||||||
_jlong2YGNodeRef(nativePointer), alwaysFormsContainingBlock);
|
_jlong2YGNodeRef(nativePointer),
|
||||||
|
static_cast<bool>(alwaysFormsContainingBlock));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jlong
|
static jlong
|
||||||
|
@@ -25,7 +25,7 @@ YogaJniException::YogaJniException(jthrowable throwable) {
|
|||||||
throwable_ = newGlobalRef(getCurrentEnv(), throwable);
|
throwable_ = newGlobalRef(getCurrentEnv(), throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
YogaJniException::YogaJniException(YogaJniException&& rhs)
|
YogaJniException::YogaJniException(YogaJniException&& rhs) noexcept
|
||||||
: throwable_(std::move(rhs.throwable_)) {}
|
: throwable_(std::move(rhs.throwable_)) {}
|
||||||
|
|
||||||
YogaJniException::YogaJniException(const YogaJniException& rhs) {
|
YogaJniException::YogaJniException(const YogaJniException& rhs) {
|
||||||
|
@@ -22,9 +22,9 @@ class YogaJniException : public std::exception {
|
|||||||
|
|
||||||
explicit YogaJniException(jthrowable throwable);
|
explicit YogaJniException(jthrowable throwable);
|
||||||
|
|
||||||
YogaJniException(YogaJniException&& rhs);
|
YogaJniException(YogaJniException&& rhs) noexcept;
|
||||||
|
|
||||||
YogaJniException(const YogaJniException& other);
|
YogaJniException(const YogaJniException& rhs);
|
||||||
|
|
||||||
ScopedLocalRef<jthrowable> getThrowable() const noexcept;
|
ScopedLocalRef<jthrowable> getThrowable() const noexcept;
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ void registerNatives(
|
|||||||
size_t numMethods) {
|
size_t numMethods) {
|
||||||
jclass clazz = env->FindClass(className);
|
jclass clazz = env->FindClass(className);
|
||||||
|
|
||||||
assertNoPendingJniExceptionIf(env, !clazz);
|
assertNoPendingJniExceptionIf(env, clazz == nullptr);
|
||||||
|
|
||||||
auto result =
|
auto result =
|
||||||
env->RegisterNatives(clazz, methods, static_cast<int32_t>(numMethods));
|
env->RegisterNatives(clazz, methods, static_cast<int32_t>(numMethods));
|
||||||
@@ -31,7 +31,7 @@ jmethodID getStaticMethodId(
|
|||||||
const char* methodDescriptor) {
|
const char* methodDescriptor) {
|
||||||
jmethodID methodId =
|
jmethodID methodId =
|
||||||
env->GetStaticMethodID(clazz, methodName, methodDescriptor);
|
env->GetStaticMethodID(clazz, methodName, methodDescriptor);
|
||||||
assertNoPendingJniExceptionIf(env, !methodId);
|
assertNoPendingJniExceptionIf(env, methodId == nullptr);
|
||||||
return methodId;
|
return methodId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ jmethodID getMethodId(
|
|||||||
const char* methodName,
|
const char* methodName,
|
||||||
const char* methodDescriptor) {
|
const char* methodDescriptor) {
|
||||||
jmethodID methodId = env->GetMethodID(clazz, methodName, methodDescriptor);
|
jmethodID methodId = env->GetMethodID(clazz, methodName, methodDescriptor);
|
||||||
assertNoPendingJniExceptionIf(env, !methodId);
|
assertNoPendingJniExceptionIf(env, methodId == nullptr);
|
||||||
return methodId;
|
return methodId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ jfieldID getFieldId(
|
|||||||
const char* fieldName,
|
const char* fieldName,
|
||||||
const char* fieldSignature) {
|
const char* fieldSignature) {
|
||||||
jfieldID fieldId = env->GetFieldID(clazz, fieldName, fieldSignature);
|
jfieldID fieldId = env->GetFieldID(clazz, fieldName, fieldSignature);
|
||||||
assertNoPendingJniExceptionIf(env, !fieldId);
|
assertNoPendingJniExceptionIf(env, fieldId == nullptr);
|
||||||
return fieldId;
|
return fieldId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,14 +82,14 @@ callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...) {
|
|||||||
va_start(args, methodId);
|
va_start(args, methodId);
|
||||||
jobject result = env->CallStaticObjectMethodV(clazz, methodId, args);
|
jobject result = env->CallStaticObjectMethodV(clazz, methodId, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
assertNoPendingJniExceptionIf(env, !result);
|
assertNoPendingJniExceptionIf(env, result == nullptr);
|
||||||
return make_local_ref(env, result);
|
return make_local_ref(env, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj) {
|
ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj) {
|
||||||
jobject result = env->NewGlobalRef(obj);
|
jobject result = env->NewGlobalRef(obj);
|
||||||
|
|
||||||
if (!result) {
|
if (result == nullptr) {
|
||||||
logErrorMessageAndDie("Could not obtain global reference from object");
|
logErrorMessageAndDie("Could not obtain global reference from object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +97,9 @@ ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj) {
|
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj) {
|
||||||
jthrowable result = static_cast<jthrowable>(env->NewGlobalRef(obj));
|
auto result = static_cast<jthrowable>(env->NewGlobalRef(obj));
|
||||||
|
|
||||||
if (!result) {
|
if (result == nullptr) {
|
||||||
logErrorMessageAndDie("Could not obtain global reference from object");
|
logErrorMessageAndDie("Could not obtain global reference from object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
namespace facebook::yoga::vanillajni {
|
namespace facebook::yoga::vanillajni {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
JavaVM* globalVm = NULL;
|
JavaVM* globalVm = nullptr;
|
||||||
struct JavaVMInitializer {
|
struct JavaVMInitializer {
|
||||||
JavaVMInitializer(JavaVM* vm) {
|
explicit JavaVMInitializer(JavaVM* vm) {
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
logErrorMessageAndDie(
|
logErrorMessageAndDie(
|
||||||
"You cannot pass a NULL JavaVM to ensureInitialized");
|
"You cannot pass a NULL JavaVM to ensureInitialized");
|
||||||
@@ -27,7 +27,7 @@ struct JavaVMInitializer {
|
|||||||
jint ensureInitialized(JNIEnv** env, JavaVM* vm) {
|
jint ensureInitialized(JNIEnv** env, JavaVM* vm) {
|
||||||
static JavaVMInitializer init(vm);
|
static JavaVMInitializer init(vm);
|
||||||
|
|
||||||
if (!env) {
|
if (env == nullptr) {
|
||||||
logErrorMessageAndDie(
|
logErrorMessageAndDie(
|
||||||
"Need to pass a valid JNIEnv pointer to vanillajni initialization "
|
"Need to pass a valid JNIEnv pointer to vanillajni initialization "
|
||||||
"routine");
|
"routine");
|
||||||
@@ -43,7 +43,7 @@ jint ensureInitialized(JNIEnv** env, JavaVM* vm) {
|
|||||||
|
|
||||||
// TODO why we need JNIEXPORT for getCurrentEnv ?
|
// TODO why we need JNIEXPORT for getCurrentEnv ?
|
||||||
JNIEXPORT JNIEnv* getCurrentEnv() {
|
JNIEXPORT JNIEnv* getCurrentEnv() {
|
||||||
JNIEnv* env;
|
JNIEnv* env = nullptr;
|
||||||
jint ret = globalVm->GetEnv((void**)&env, JNI_VERSION_1_6);
|
jint ret = globalVm->GetEnv((void**)&env, JNI_VERSION_1_6);
|
||||||
if (ret != JNI_OK) {
|
if (ret != JNI_OK) {
|
||||||
logErrorMessageAndDie(
|
logErrorMessageAndDie(
|
||||||
@@ -68,7 +68,7 @@ void assertNoPendingJniException(JNIEnv* env) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto throwable = env->ExceptionOccurred();
|
auto throwable = env->ExceptionOccurred();
|
||||||
if (!throwable) {
|
if (throwable == nullptr) {
|
||||||
logErrorMessageAndDie("Unable to get pending JNI exception.");
|
logErrorMessageAndDie("Unable to get pending JNI exception.");
|
||||||
}
|
}
|
||||||
env->ExceptionClear();
|
env->ExceptionClear();
|
||||||
|
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
using namespace facebook::yoga;
|
using namespace facebook::yoga;
|
||||||
|
|
||||||
jint JNI_OnLoad(JavaVM* vm, void*) {
|
jint JNI_OnLoad(JavaVM* vm, void* /*unused*/) {
|
||||||
JNIEnv* env;
|
JNIEnv* env = nullptr;
|
||||||
jint ret = vanillajni::ensureInitialized(&env, vm);
|
jint ret = vanillajni::ensureInitialized(&env, vm);
|
||||||
YGJNIVanilla::registerNatives(env);
|
YGJNIVanilla::registerNatives(env);
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -45,8 +45,11 @@ struct EventArgs {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class EventTest : public ::testing::Test {
|
class EventTest : public ::testing::Test {
|
||||||
ScopedEventSubscription subscription = {&EventTest::listen};
|
ScopedEventSubscription subscription{&EventTest::listen};
|
||||||
static void listen(YGNodeConstRef, Event::Type, Event::Data);
|
static void listen(
|
||||||
|
YGNodeConstRef /*node*/,
|
||||||
|
Event::Type /*type*/,
|
||||||
|
Event::Data /*data*/);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::vector<EventArgs> events;
|
static std::vector<EventArgs> events;
|
||||||
|
@@ -13,7 +13,7 @@ namespace facebook::yoga {
|
|||||||
constexpr size_t kBufferSize = 4;
|
constexpr size_t kBufferSize = 4;
|
||||||
|
|
||||||
TEST(SmallValueBuffer, copy_assignment_with_overflow) {
|
TEST(SmallValueBuffer, copy_assignment_with_overflow) {
|
||||||
std::array<uint16_t, kBufferSize + 1> handles;
|
std::array<uint16_t, kBufferSize + 1> handles{};
|
||||||
|
|
||||||
SmallValueBuffer<kBufferSize> buffer1;
|
SmallValueBuffer<kBufferSize> buffer1;
|
||||||
for (size_t i = 0; i < kBufferSize + 1; ++i) {
|
for (size_t i = 0; i < kBufferSize + 1; ++i) {
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
static float
|
static float
|
||||||
_baseline(YGNodeConstRef node, const float /*width*/, const float /*height*/) {
|
_baseline(YGNodeConstRef node, const float /*width*/, const float /*height*/) {
|
||||||
float* baseline = (float*)YGNodeGetContext(node);
|
auto* baseline = (float*)YGNodeGetContext(node);
|
||||||
return *baseline;
|
return *baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,10 +21,16 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
void TearDown() override;
|
void TearDown() override;
|
||||||
|
|
||||||
static yoga::Node clonedNode;
|
static yoga::Node clonedNode;
|
||||||
static YGNodeRef cloneNode(YGNodeConstRef, YGNodeConstRef, size_t) {
|
static YGNodeRef cloneNode(
|
||||||
|
YGNodeConstRef /*unused*/,
|
||||||
|
YGNodeConstRef /*unused*/,
|
||||||
|
size_t /*unused*/) {
|
||||||
return &clonedNode;
|
return &clonedNode;
|
||||||
}
|
}
|
||||||
static YGNodeRef doNotClone(YGNodeConstRef, YGNodeConstRef, size_t) {
|
static YGNodeRef doNotClone(
|
||||||
|
YGNodeConstRef /*unused*/,
|
||||||
|
YGNodeConstRef /*unused*/,
|
||||||
|
size_t /*unused*/) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -32,7 +38,8 @@ struct ConfigCloningTest : public ::testing::Test {
|
|||||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||||
config->setCloneNodeCallback(cloneNode);
|
config->setCloneNodeCallback(cloneNode);
|
||||||
|
|
||||||
yoga::Node node{}, owner{};
|
yoga::Node node{};
|
||||||
|
yoga::Node owner{};
|
||||||
auto clone = config->cloneNode(&node, &owner, 0);
|
auto clone = config->cloneNode(&node, &owner, 0);
|
||||||
|
|
||||||
ASSERT_EQ(clone, &clonedNode);
|
ASSERT_EQ(clone, &clonedNode);
|
||||||
@@ -43,7 +50,8 @@ TEST_F(
|
|||||||
falls_back_to_regular_cloning_if_callback_returns_null) {
|
falls_back_to_regular_cloning_if_callback_returns_null) {
|
||||||
config->setCloneNodeCallback(doNotClone);
|
config->setCloneNodeCallback(doNotClone);
|
||||||
|
|
||||||
yoga::Node node{}, owner{};
|
yoga::Node node{};
|
||||||
|
yoga::Node owner{};
|
||||||
auto clone = config->cloneNode(&node, &owner, 0);
|
auto clone = config->cloneNode(&node, &owner, 0);
|
||||||
|
|
||||||
ASSERT_NE(clone, nullptr);
|
ASSERT_NE(clone, nullptr);
|
||||||
|
@@ -12,7 +12,7 @@ TEST(YogaTest, assert_default_values) {
|
|||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
|
||||||
ASSERT_EQ(0u, YGNodeGetChildCount(root));
|
ASSERT_EQ(0u, YGNodeGetChildCount(root));
|
||||||
ASSERT_EQ(NULL, YGNodeGetChild(root, 1));
|
ASSERT_EQ(nullptr, YGNodeGetChild(root, 1));
|
||||||
|
|
||||||
ASSERT_EQ(YGDirectionInherit, YGNodeStyleGetDirection(root));
|
ASSERT_EQ(YGDirectionInherit, YGNodeStyleGetDirection(root));
|
||||||
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(root));
|
ASSERT_EQ(YGFlexDirectionColumn, YGNodeStyleGetFlexDirection(root));
|
||||||
|
@@ -12,8 +12,7 @@ using namespace ::testing;
|
|||||||
|
|
||||||
class YogaTest_HadOverflowTests : public Test {
|
class YogaTest_HadOverflowTests : public Test {
|
||||||
protected:
|
protected:
|
||||||
YogaTest_HadOverflowTests() {
|
YogaTest_HadOverflowTests() : config(YGConfigNew()) {
|
||||||
config = YGConfigNew();
|
|
||||||
root = YGNodeNewWithConfig(config);
|
root = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetWidth(root, 200);
|
YGNodeStyleSetWidth(root, 200);
|
||||||
YGNodeStyleSetHeight(root, 100);
|
YGNodeStyleSetHeight(root, 100);
|
||||||
@@ -21,7 +20,7 @@ class YogaTest_HadOverflowTests : public Test {
|
|||||||
YGNodeStyleSetFlexWrap(root, YGWrapNoWrap);
|
YGNodeStyleSetFlexWrap(root, YGWrapNoWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
~YogaTest_HadOverflowTests() {
|
~YogaTest_HadOverflowTests() override {
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@ static YGSize _measure_84_49(
|
|||||||
float /*height*/,
|
float /*height*/,
|
||||||
YGMeasureMode /*heightMode*/) {
|
YGMeasureMode /*heightMode*/) {
|
||||||
int* measureCount = (int*)YGNodeGetContext(node);
|
int* measureCount = (int*)YGNodeGetContext(node);
|
||||||
if (measureCount) {
|
if (measureCount != nullptr) {
|
||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,8 +26,7 @@ static YGSize _measure(
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
struct _MeasureConstraintList* constraintList =
|
auto* constraintList = (struct _MeasureConstraintList*)YGNodeGetContext(node);
|
||||||
(struct _MeasureConstraintList*)YGNodeGetContext(node);
|
|
||||||
struct _MeasureConstraint* constraints = constraintList->constraints;
|
struct _MeasureConstraint* constraints = constraintList->constraints;
|
||||||
uint32_t currentIndex = constraintList->length;
|
uint32_t currentIndex = constraintList->length;
|
||||||
(&constraints[currentIndex])->width = width;
|
(&constraints[currentIndex])->width = width;
|
||||||
@@ -43,7 +42,7 @@ static YGSize _measure(
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, exactly_measure_stretched_child_column) {
|
TEST(YogaTest, exactly_measure_stretched_child_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -70,7 +69,7 @@ TEST(YogaTest, exactly_measure_stretched_child_column) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, exactly_measure_stretched_child_row) {
|
TEST(YogaTest, exactly_measure_stretched_child_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -98,7 +97,7 @@ TEST(YogaTest, exactly_measure_stretched_child_row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, at_most_main_axis_column) {
|
TEST(YogaTest, at_most_main_axis_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -125,7 +124,7 @@ TEST(YogaTest, at_most_main_axis_column) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, at_most_cross_axis_column) {
|
TEST(YogaTest, at_most_cross_axis_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -153,7 +152,7 @@ TEST(YogaTest, at_most_cross_axis_column) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, at_most_main_axis_row) {
|
TEST(YogaTest, at_most_main_axis_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -181,7 +180,7 @@ TEST(YogaTest, at_most_main_axis_row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, at_most_cross_axis_row) {
|
TEST(YogaTest, at_most_cross_axis_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -210,7 +209,7 @@ TEST(YogaTest, at_most_cross_axis_row) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, flex_child) {
|
TEST(YogaTest, flex_child) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -240,7 +239,7 @@ TEST(YogaTest, flex_child) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, flex_child_with_flex_basis) {
|
TEST(YogaTest, flex_child_with_flex_basis) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -268,7 +267,7 @@ TEST(YogaTest, flex_child_with_flex_basis) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, overflow_scroll_column) {
|
TEST(YogaTest, overflow_scroll_column) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
@@ -300,7 +299,7 @@ TEST(YogaTest, overflow_scroll_column) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, overflow_scroll_row) {
|
TEST(YogaTest, overflow_scroll_row) {
|
||||||
struct _MeasureConstraintList constraintList = _MeasureConstraintList{
|
auto constraintList = _MeasureConstraintList{
|
||||||
0,
|
0,
|
||||||
(struct _MeasureConstraint*)malloc(
|
(struct _MeasureConstraint*)malloc(
|
||||||
10 * sizeof(struct _MeasureConstraint)),
|
10 * sizeof(struct _MeasureConstraint)),
|
||||||
|
@@ -15,7 +15,7 @@ static YGSize _measure(
|
|||||||
float /*height*/,
|
float /*height*/,
|
||||||
YGMeasureMode /*heightMode*/) {
|
YGMeasureMode /*heightMode*/) {
|
||||||
int* measureCount = (int*)YGNodeGetContext(node);
|
int* measureCount = (int*)YGNodeGetContext(node);
|
||||||
if (measureCount) {
|
if (measureCount != nullptr) {
|
||||||
(*measureCount)++;
|
(*measureCount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ struct TestUtil {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ScopedEventSubscription {
|
struct ScopedEventSubscription {
|
||||||
ScopedEventSubscription(std::function<Event::Subscriber>&&);
|
explicit ScopedEventSubscription(std::function<Event::Subscriber>&&);
|
||||||
~ScopedEventSubscription();
|
~ScopedEventSubscription();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -216,12 +216,12 @@ void YGNodeSetChildren(
|
|||||||
auto owner = resolveRef(ownerRef);
|
auto owner = resolveRef(ownerRef);
|
||||||
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
auto children = reinterpret_cast<yoga::Node* const*>(childrenRefs);
|
||||||
|
|
||||||
if (!owner) {
|
if (owner == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<yoga::Node*> childrenVector = {children, children + count};
|
const std::vector<yoga::Node*> childrenVector = {children, children + count};
|
||||||
if (childrenVector.size() == 0) {
|
if (childrenVector.empty()) {
|
||||||
if (owner->getChildCount() > 0) {
|
if (owner->getChildCount() > 0) {
|
||||||
for (auto* child : owner->getChildren()) {
|
for (auto* child : owner->getChildren()) {
|
||||||
child->setLayout({});
|
child->setLayout({});
|
||||||
|
@@ -13,16 +13,16 @@
|
|||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
void layoutAbsoluteChild(
|
void layoutAbsoluteChild(
|
||||||
const yoga::Node* const containingNode,
|
const yoga::Node* containingNode,
|
||||||
const yoga::Node* const node,
|
const yoga::Node* node,
|
||||||
yoga::Node* const child,
|
yoga::Node* child,
|
||||||
const float containingBlockWidth,
|
float containingBlockWidth,
|
||||||
const float containingBlockHeight,
|
float containingBlockHeight,
|
||||||
const SizingMode widthMode,
|
SizingMode widthMode,
|
||||||
const Direction direction,
|
Direction direction,
|
||||||
LayoutData& layoutMarkerData,
|
LayoutData& layoutMarkerData,
|
||||||
const uint32_t depth,
|
uint32_t depth,
|
||||||
const uint32_t generationCount);
|
uint32_t generationCount);
|
||||||
|
|
||||||
void layoutAbsoluteDescendants(
|
void layoutAbsoluteDescendants(
|
||||||
yoga::Node* containingNode,
|
yoga::Node* containingNode,
|
||||||
|
@@ -80,8 +80,8 @@ static void computeFlexBasisForChild(
|
|||||||
const float mainAxisSize = isMainAxisRow ? width : height;
|
const float mainAxisSize = isMainAxisRow ? width : height;
|
||||||
const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight;
|
const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight;
|
||||||
|
|
||||||
float childWidth;
|
float childWidth = YGUndefined;
|
||||||
float childHeight;
|
float childHeight = YGUndefined;
|
||||||
SizingMode childWidthSizingMode;
|
SizingMode childWidthSizingMode;
|
||||||
SizingMode childHeightSizingMode;
|
SizingMode childHeightSizingMode;
|
||||||
|
|
||||||
@@ -120,8 +120,6 @@ static void computeFlexBasisForChild(
|
|||||||
} else {
|
} else {
|
||||||
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
||||||
// basis).
|
// basis).
|
||||||
childWidth = YGUndefined;
|
|
||||||
childHeight = YGUndefined;
|
|
||||||
childWidthSizingMode = SizingMode::MaxContent;
|
childWidthSizingMode = SizingMode::MaxContent;
|
||||||
childHeightSizingMode = SizingMode::MaxContent;
|
childHeightSizingMode = SizingMode::MaxContent;
|
||||||
|
|
||||||
@@ -606,7 +604,7 @@ static float distributeFreeSpaceSecondPass(
|
|||||||
-currentLineChild->resolveFlexShrink() * childFlexBasis;
|
-currentLineChild->resolveFlexShrink() * childFlexBasis;
|
||||||
// Is this child able to shrink?
|
// Is this child able to shrink?
|
||||||
if (flexShrinkScaledFactor != 0) {
|
if (flexShrinkScaledFactor != 0) {
|
||||||
float childSize;
|
float childSize = YGUndefined;
|
||||||
|
|
||||||
if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
|
if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
|
||||||
flexLine.layout.totalFlexShrinkScaledFactors == 0) {
|
flexLine.layout.totalFlexShrinkScaledFactors == 0) {
|
||||||
@@ -650,7 +648,7 @@ static float distributeFreeSpaceSecondPass(
|
|||||||
const float marginCross = currentLineChild->style().computeMarginForAxis(
|
const float marginCross = currentLineChild->style().computeMarginForAxis(
|
||||||
crossAxis, availableInnerWidth);
|
crossAxis, availableInnerWidth);
|
||||||
|
|
||||||
float childCrossSize;
|
float childCrossSize = YGUndefined;
|
||||||
float childMainSize = updatedMainSize + marginMain;
|
float childMainSize = updatedMainSize + marginMain;
|
||||||
SizingMode childCrossSizingMode;
|
SizingMode childCrossSizingMode;
|
||||||
SizingMode childMainSizingMode = SizingMode::StretchFit;
|
SizingMode childMainSizingMode = SizingMode::StretchFit;
|
||||||
@@ -1794,13 +1792,13 @@ static void calculateLayoutImpl(
|
|||||||
size_t endIndex = 0;
|
size_t endIndex = 0;
|
||||||
for (size_t i = 0; i < lineCount; i++) {
|
for (size_t i = 0; i < lineCount; i++) {
|
||||||
const size_t startIndex = endIndex;
|
const size_t startIndex = endIndex;
|
||||||
size_t ii;
|
size_t ii = startIndex;
|
||||||
|
|
||||||
// compute the line's height and find the endIndex
|
// compute the line's height and find the endIndex
|
||||||
float lineHeight = 0;
|
float lineHeight = 0;
|
||||||
float maxAscentForCurrentLine = 0;
|
float maxAscentForCurrentLine = 0;
|
||||||
float maxDescentForCurrentLine = 0;
|
float maxDescentForCurrentLine = 0;
|
||||||
for (ii = startIndex; ii < childCount; ii++) {
|
for (; ii < childCount; ii++) {
|
||||||
const auto child = node->getChild(ii);
|
const auto child = node->getChild(ii);
|
||||||
if (child->style().display() == Display::None) {
|
if (child->style().display() == Display::None) {
|
||||||
continue;
|
continue;
|
||||||
@@ -1837,113 +1835,110 @@ static void calculateLayoutImpl(
|
|||||||
endIndex = ii;
|
endIndex = ii;
|
||||||
currentLead += i != 0 ? crossAxisGap : 0;
|
currentLead += i != 0 ? crossAxisGap : 0;
|
||||||
|
|
||||||
if (performLayout) {
|
for (ii = startIndex; ii < endIndex; ii++) {
|
||||||
for (ii = startIndex; ii < endIndex; ii++) {
|
const auto child = node->getChild(ii);
|
||||||
const auto child = node->getChild(ii);
|
if (child->style().display() == Display::None) {
|
||||||
if (child->style().display() == Display::None) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if (child->style().positionType() != PositionType::Absolute) {
|
||||||
if (child->style().positionType() != PositionType::Absolute) {
|
switch (resolveChildAlignment(node, child)) {
|
||||||
switch (resolveChildAlignment(node, child)) {
|
case Align::FlexStart: {
|
||||||
case Align::FlexStart: {
|
child->setLayoutPosition(
|
||||||
child->setLayoutPosition(
|
currentLead +
|
||||||
currentLead +
|
child->style().computeFlexStartPosition(
|
||||||
child->style().computeFlexStartPosition(
|
crossAxis, direction, availableInnerWidth),
|
||||||
crossAxis, direction, availableInnerWidth),
|
flexStartEdge(crossAxis));
|
||||||
flexStartEdge(crossAxis));
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Align::FlexEnd: {
|
|
||||||
child->setLayoutPosition(
|
|
||||||
currentLead + lineHeight -
|
|
||||||
child->style().computeFlexEndMargin(
|
|
||||||
crossAxis, direction, availableInnerWidth) -
|
|
||||||
child->getLayout().measuredDimension(
|
|
||||||
dimension(crossAxis)),
|
|
||||||
flexStartEdge(crossAxis));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Align::Center: {
|
|
||||||
float childHeight =
|
|
||||||
child->getLayout().measuredDimension(dimension(crossAxis));
|
|
||||||
|
|
||||||
child->setLayoutPosition(
|
|
||||||
currentLead + (lineHeight - childHeight) / 2,
|
|
||||||
flexStartEdge(crossAxis));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Align::Stretch: {
|
|
||||||
child->setLayoutPosition(
|
|
||||||
currentLead +
|
|
||||||
child->style().computeFlexStartMargin(
|
|
||||||
crossAxis, direction, availableInnerWidth),
|
|
||||||
flexStartEdge(crossAxis));
|
|
||||||
|
|
||||||
// Remeasure child with the line height as it as been only
|
|
||||||
// measured with the owners height yet.
|
|
||||||
if (!child->hasDefiniteLength(
|
|
||||||
dimension(crossAxis), availableInnerCrossDim)) {
|
|
||||||
const float childWidth = isMainAxisRow
|
|
||||||
? (child->getLayout().measuredDimension(
|
|
||||||
Dimension::Width) +
|
|
||||||
child->style().computeMarginForAxis(
|
|
||||||
mainAxis, availableInnerWidth))
|
|
||||||
: leadPerLine + lineHeight;
|
|
||||||
|
|
||||||
const float childHeight = !isMainAxisRow
|
|
||||||
? (child->getLayout().measuredDimension(
|
|
||||||
Dimension::Height) +
|
|
||||||
child->style().computeMarginForAxis(
|
|
||||||
crossAxis, availableInnerWidth))
|
|
||||||
: leadPerLine + lineHeight;
|
|
||||||
|
|
||||||
if (!(yoga::inexactEquals(
|
|
||||||
childWidth,
|
|
||||||
child->getLayout().measuredDimension(
|
|
||||||
Dimension::Width)) &&
|
|
||||||
yoga::inexactEquals(
|
|
||||||
childHeight,
|
|
||||||
child->getLayout().measuredDimension(
|
|
||||||
Dimension::Height)))) {
|
|
||||||
calculateLayoutInternal(
|
|
||||||
child,
|
|
||||||
childWidth,
|
|
||||||
childHeight,
|
|
||||||
direction,
|
|
||||||
SizingMode::StretchFit,
|
|
||||||
SizingMode::StretchFit,
|
|
||||||
availableInnerWidth,
|
|
||||||
availableInnerHeight,
|
|
||||||
true,
|
|
||||||
LayoutPassReason::kMultilineStretch,
|
|
||||||
layoutMarkerData,
|
|
||||||
depth,
|
|
||||||
generationCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Align::Baseline: {
|
|
||||||
child->setLayoutPosition(
|
|
||||||
currentLead + maxAscentForCurrentLine -
|
|
||||||
calculateBaseline(child) +
|
|
||||||
child->style().computeFlexStartPosition(
|
|
||||||
FlexDirection::Column,
|
|
||||||
direction,
|
|
||||||
availableInnerCrossDim),
|
|
||||||
PhysicalEdge::Top);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Align::Auto:
|
|
||||||
case Align::SpaceBetween:
|
|
||||||
case Align::SpaceAround:
|
|
||||||
case Align::SpaceEvenly:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
case Align::FlexEnd: {
|
||||||
|
child->setLayoutPosition(
|
||||||
|
currentLead + lineHeight -
|
||||||
|
child->style().computeFlexEndMargin(
|
||||||
|
crossAxis, direction, availableInnerWidth) -
|
||||||
|
child->getLayout().measuredDimension(
|
||||||
|
dimension(crossAxis)),
|
||||||
|
flexStartEdge(crossAxis));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Align::Center: {
|
||||||
|
float childHeight =
|
||||||
|
child->getLayout().measuredDimension(dimension(crossAxis));
|
||||||
|
|
||||||
|
child->setLayoutPosition(
|
||||||
|
currentLead + (lineHeight - childHeight) / 2,
|
||||||
|
flexStartEdge(crossAxis));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Align::Stretch: {
|
||||||
|
child->setLayoutPosition(
|
||||||
|
currentLead +
|
||||||
|
child->style().computeFlexStartMargin(
|
||||||
|
crossAxis, direction, availableInnerWidth),
|
||||||
|
flexStartEdge(crossAxis));
|
||||||
|
|
||||||
|
// Remeasure child with the line height as it as been only
|
||||||
|
// measured with the owners height yet.
|
||||||
|
if (!child->hasDefiniteLength(
|
||||||
|
dimension(crossAxis), availableInnerCrossDim)) {
|
||||||
|
const float childWidth = isMainAxisRow
|
||||||
|
? (child->getLayout().measuredDimension(Dimension::Width) +
|
||||||
|
child->style().computeMarginForAxis(
|
||||||
|
mainAxis, availableInnerWidth))
|
||||||
|
: leadPerLine + lineHeight;
|
||||||
|
|
||||||
|
const float childHeight = !isMainAxisRow
|
||||||
|
? (child->getLayout().measuredDimension(Dimension::Height) +
|
||||||
|
child->style().computeMarginForAxis(
|
||||||
|
crossAxis, availableInnerWidth))
|
||||||
|
: leadPerLine + lineHeight;
|
||||||
|
|
||||||
|
if (!(yoga::inexactEquals(
|
||||||
|
childWidth,
|
||||||
|
child->getLayout().measuredDimension(
|
||||||
|
Dimension::Width)) &&
|
||||||
|
yoga::inexactEquals(
|
||||||
|
childHeight,
|
||||||
|
child->getLayout().measuredDimension(
|
||||||
|
Dimension::Height)))) {
|
||||||
|
calculateLayoutInternal(
|
||||||
|
child,
|
||||||
|
childWidth,
|
||||||
|
childHeight,
|
||||||
|
direction,
|
||||||
|
SizingMode::StretchFit,
|
||||||
|
SizingMode::StretchFit,
|
||||||
|
availableInnerWidth,
|
||||||
|
availableInnerHeight,
|
||||||
|
true,
|
||||||
|
LayoutPassReason::kMultilineStretch,
|
||||||
|
layoutMarkerData,
|
||||||
|
depth,
|
||||||
|
generationCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Align::Baseline: {
|
||||||
|
child->setLayoutPosition(
|
||||||
|
currentLead + maxAscentForCurrentLine -
|
||||||
|
calculateBaseline(child) +
|
||||||
|
child->style().computeFlexStartPosition(
|
||||||
|
FlexDirection::Column,
|
||||||
|
direction,
|
||||||
|
availableInnerCrossDim),
|
||||||
|
PhysicalEdge::Top);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Align::Auto:
|
||||||
|
case Align::SpaceBetween:
|
||||||
|
case Align::SpaceAround:
|
||||||
|
case Align::SpaceEvenly:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLead = currentLead + leadPerLine + lineHeight;
|
currentLead = currentLead + leadPerLine + lineHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2244,7 +2239,7 @@ bool calculateLayoutInternal(
|
|||||||
layout->nextCachedMeasurementsIndex = 0;
|
layout->nextCachedMeasurementsIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedMeasurement* newCacheEntry;
|
CachedMeasurement* newCacheEntry = nullptr;
|
||||||
if (performLayout) {
|
if (performLayout) {
|
||||||
// Use the single layout cache entry.
|
// Use the single layout cache entry.
|
||||||
newCacheEntry = &layout->cachedLayout;
|
newCacheEntry = &layout->cachedLayout;
|
||||||
|
@@ -15,24 +15,24 @@
|
|||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
void calculateLayout(
|
void calculateLayout(
|
||||||
yoga::Node* const node,
|
yoga::Node* node,
|
||||||
const float ownerWidth,
|
float ownerWidth,
|
||||||
const float ownerHeight,
|
float ownerHeight,
|
||||||
const Direction ownerDirection);
|
Direction ownerDirection);
|
||||||
|
|
||||||
bool calculateLayoutInternal(
|
bool calculateLayoutInternal(
|
||||||
yoga::Node* const node,
|
yoga::Node* node,
|
||||||
const float availableWidth,
|
float availableWidth,
|
||||||
const float availableHeight,
|
float availableHeight,
|
||||||
const Direction ownerDirection,
|
Direction ownerDirection,
|
||||||
const SizingMode widthSizingMode,
|
SizingMode widthSizingMode,
|
||||||
const SizingMode heightSizingMode,
|
SizingMode heightSizingMode,
|
||||||
const float ownerWidth,
|
float ownerWidth,
|
||||||
const float ownerHeight,
|
float ownerHeight,
|
||||||
const bool performLayout,
|
bool performLayout,
|
||||||
const LayoutPassReason reason,
|
LayoutPassReason reason,
|
||||||
LayoutData& layoutMarkerData,
|
LayoutData& layoutMarkerData,
|
||||||
const uint32_t depth,
|
uint32_t depth,
|
||||||
const uint32_t generationCount);
|
uint32_t generationCount);
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -69,7 +69,7 @@ FlexLine calculateFlexLine(
|
|||||||
if (sizeConsumedIncludingMinConstraint + flexBasisWithMinAndMaxConstraints +
|
if (sizeConsumedIncludingMinConstraint + flexBasisWithMinAndMaxConstraints +
|
||||||
childMarginMainAxis + childLeadingGapMainAxis >
|
childMarginMainAxis + childLeadingGapMainAxis >
|
||||||
availableInnerMainDim &&
|
availableInnerMainDim &&
|
||||||
isNodeFlexWrap && itemsInFlow.size() > 0) {
|
isNodeFlexWrap && !itemsInFlow.empty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ struct FlexLine {
|
|||||||
// computedFlexBasis properly computed(To do this use
|
// computedFlexBasis properly computed(To do this use
|
||||||
// computeFlexBasisForChildren function).
|
// computeFlexBasisForChildren function).
|
||||||
FlexLine calculateFlexLine(
|
FlexLine calculateFlexLine(
|
||||||
yoga::Node* const node,
|
yoga::Node* node,
|
||||||
Direction ownerDirection,
|
Direction ownerDirection,
|
||||||
float mainAxisownerSize,
|
float mainAxisownerSize,
|
||||||
float availableInnerWidth,
|
float availableInnerWidth,
|
||||||
|
@@ -15,15 +15,15 @@ namespace facebook::yoga {
|
|||||||
// Round a point value to the nearest physical pixel based on DPI
|
// Round a point value to the nearest physical pixel based on DPI
|
||||||
// (pointScaleFactor)
|
// (pointScaleFactor)
|
||||||
float roundValueToPixelGrid(
|
float roundValueToPixelGrid(
|
||||||
const double value,
|
double value,
|
||||||
const double pointScaleFactor,
|
double pointScaleFactor,
|
||||||
const bool forceCeil,
|
bool forceCeil,
|
||||||
const bool forceFloor);
|
bool forceFloor);
|
||||||
|
|
||||||
// Round the layout results of a node and its subtree to the pixel grid.
|
// Round the layout results of a node and its subtree to the pixel grid.
|
||||||
void roundLayoutResultsToPixelGrid(
|
void roundLayoutResultsToPixelGrid(
|
||||||
yoga::Node* const node,
|
yoga::Node* node,
|
||||||
const double absoluteLeft,
|
double absoluteLeft,
|
||||||
const double absoluteTop);
|
double absoluteTop);
|
||||||
|
|
||||||
} // namespace facebook::yoga
|
} // namespace facebook::yoga
|
||||||
|
@@ -20,7 +20,7 @@ bool configUpdateInvalidatesLayout(
|
|||||||
oldConfig.useWebDefaults() != newConfig.useWebDefaults();
|
oldConfig.useWebDefaults() != newConfig.useWebDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::Config(YGLogger logger) : cloneNodeCallback_{nullptr} {
|
Config::Config(YGLogger logger) {
|
||||||
setLogger(logger);
|
setLogger(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ bool configUpdateInvalidatesLayout(
|
|||||||
|
|
||||||
class YG_EXPORT Config : public ::YGConfig {
|
class YG_EXPORT Config : public ::YGConfig {
|
||||||
public:
|
public:
|
||||||
Config(YGLogger logger);
|
explicit Config(YGLogger logger);
|
||||||
|
|
||||||
void setUseWebDefaults(bool useWebDefaults);
|
void setUseWebDefaults(bool useWebDefaults);
|
||||||
bool useWebDefaults() const;
|
bool useWebDefaults() const;
|
||||||
@@ -67,8 +67,8 @@ class YG_EXPORT Config : public ::YGConfig {
|
|||||||
static const Config& getDefault();
|
static const Config& getDefault();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
YGCloneNodeFunc cloneNodeCallback_;
|
YGCloneNodeFunc cloneNodeCallback_{nullptr};
|
||||||
YGLogger logger_;
|
YGLogger logger_{};
|
||||||
|
|
||||||
bool useWebDefaults_ : 1 = false;
|
bool useWebDefaults_ : 1 = false;
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ void log(LogLevel level, const char* format, ...) noexcept;
|
|||||||
void log(
|
void log(
|
||||||
const yoga::Node* node,
|
const yoga::Node* node,
|
||||||
LogLevel level,
|
LogLevel level,
|
||||||
const char* message,
|
const char* format,
|
||||||
...) noexcept;
|
...) noexcept;
|
||||||
|
|
||||||
void log(
|
void log(
|
||||||
|
@@ -40,14 +40,14 @@ struct Node {
|
|||||||
std::function<Event::Subscriber> subscriber = nullptr;
|
std::function<Event::Subscriber> subscriber = nullptr;
|
||||||
Node* next = nullptr;
|
Node* next = nullptr;
|
||||||
|
|
||||||
Node(std::function<Event::Subscriber>&& subscriber)
|
explicit Node(std::function<Event::Subscriber>&& subscriber)
|
||||||
: subscriber{std::move(subscriber)} {}
|
: subscriber{std::move(subscriber)} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::atomic<Node*> subscribers{nullptr};
|
std::atomic<Node*> subscribers{nullptr};
|
||||||
|
|
||||||
Node* push(Node* newHead) {
|
Node* push(Node* newHead) {
|
||||||
Node* oldHead;
|
Node* oldHead = nullptr;
|
||||||
do {
|
do {
|
||||||
oldHead = subscribers.load(std::memory_order_relaxed);
|
oldHead = subscribers.load(std::memory_order_relaxed);
|
||||||
if (newHead != nullptr) {
|
if (newHead != nullptr) {
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ struct LayoutData {
|
|||||||
measureCallbackReasonsCount;
|
measureCallbackReasonsCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* LayoutPassReasonToString(const LayoutPassReason value);
|
const char* LayoutPassReasonToString(LayoutPassReason value);
|
||||||
|
|
||||||
struct YG_EXPORT Event {
|
struct YG_EXPORT Event {
|
||||||
enum Type {
|
enum Type {
|
||||||
@@ -72,7 +72,7 @@ struct YG_EXPORT Event {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template <Type E>
|
template <Type E>
|
||||||
Data(const TypedData<E>& data) : data_{&data} {}
|
explicit Data(const TypedData<E>& data) : data_{&data} {}
|
||||||
|
|
||||||
template <Type E>
|
template <Type E>
|
||||||
const TypedData<E>& get() const {
|
const TypedData<E>& get() const {
|
||||||
@@ -90,7 +90,10 @@ struct YG_EXPORT Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void publish(YGNodeConstRef, Type, const Data&);
|
static void publish(
|
||||||
|
YGNodeConstRef /*node*/,
|
||||||
|
Type /*eventType*/,
|
||||||
|
const Data& /*eventData*/);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@@ -26,23 +26,23 @@ Node::Node(const yoga::Config* config) : config_{config} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node::Node(Node&& node) {
|
Node::Node(Node&& node) noexcept
|
||||||
hasNewLayout_ = node.hasNewLayout_;
|
: hasNewLayout_(node.hasNewLayout_),
|
||||||
isReferenceBaseline_ = node.isReferenceBaseline_;
|
isReferenceBaseline_(node.isReferenceBaseline_),
|
||||||
isDirty_ = node.isDirty_;
|
isDirty_(node.isDirty_),
|
||||||
alwaysFormsContainingBlock_ = node.alwaysFormsContainingBlock_;
|
alwaysFormsContainingBlock_(node.alwaysFormsContainingBlock_),
|
||||||
nodeType_ = node.nodeType_;
|
nodeType_(node.nodeType_),
|
||||||
context_ = node.context_;
|
context_(node.context_),
|
||||||
measureFunc_ = node.measureFunc_;
|
measureFunc_(node.measureFunc_),
|
||||||
baselineFunc_ = node.baselineFunc_;
|
baselineFunc_(node.baselineFunc_),
|
||||||
dirtiedFunc_ = node.dirtiedFunc_;
|
dirtiedFunc_(node.dirtiedFunc_),
|
||||||
style_ = node.style_;
|
style_(std::move(node.style_)),
|
||||||
layout_ = node.layout_;
|
layout_(node.layout_),
|
||||||
lineIndex_ = node.lineIndex_;
|
lineIndex_(node.lineIndex_),
|
||||||
owner_ = node.owner_;
|
owner_(node.owner_),
|
||||||
children_ = std::move(node.children_);
|
children_(std::move(node.children_)),
|
||||||
config_ = node.config_;
|
config_(node.config_),
|
||||||
resolvedDimensions_ = node.resolvedDimensions_;
|
resolvedDimensions_(node.resolvedDimensions_) {
|
||||||
for (auto c : children_) {
|
for (auto c : children_) {
|
||||||
c->setOwner(this);
|
c->setOwner(this);
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
|
|||||||
} else {
|
} else {
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
this,
|
this,
|
||||||
children_.size() == 0,
|
children_.empty(),
|
||||||
"Cannot set measure function: Nodes with measure functions cannot have "
|
"Cannot set measure function: Nodes with measure functions cannot have "
|
||||||
"children.");
|
"children.");
|
||||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
||||||
@@ -122,18 +122,17 @@ void Node::setConfig(yoga::Config* config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Node::setDirty(bool isDirty) {
|
void Node::setDirty(bool isDirty) {
|
||||||
if (isDirty == isDirty_) {
|
if (static_cast<int>(isDirty) == isDirty_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isDirty_ = isDirty;
|
isDirty_ = isDirty;
|
||||||
if (isDirty && dirtiedFunc_) {
|
if (isDirty && (dirtiedFunc_ != nullptr)) {
|
||||||
dirtiedFunc_(this);
|
dirtiedFunc_(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::removeChild(Node* child) {
|
bool Node::removeChild(Node* child) {
|
||||||
std::vector<Node*>::iterator p =
|
auto p = std::find(children_.begin(), children_.end(), child);
|
||||||
std::find(children_.begin(), children_.end(), child);
|
|
||||||
if (p != children_.end()) {
|
if (p != children_.end()) {
|
||||||
children_.erase(p);
|
children_.erase(p);
|
||||||
return true;
|
return true;
|
||||||
@@ -307,7 +306,7 @@ void Node::markDirtyAndPropagate() {
|
|||||||
if (!isDirty_) {
|
if (!isDirty_) {
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
setLayoutComputedFlexBasis(FloatOptional());
|
setLayoutComputedFlexBasis(FloatOptional());
|
||||||
if (owner_) {
|
if (owner_ != nullptr) {
|
||||||
owner_->markDirtyAndPropagate();
|
owner_->markDirtyAndPropagate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,7 +350,7 @@ bool Node::isNodeFlexible() {
|
|||||||
void Node::reset() {
|
void Node::reset() {
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
this,
|
this,
|
||||||
children_.size() == 0,
|
children_.empty(),
|
||||||
"Cannot reset a node which still has children attached");
|
"Cannot reset a node which still has children attached");
|
||||||
yoga::assertFatalWithNode(
|
yoga::assertFatalWithNode(
|
||||||
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
||||||
|
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
@@ -34,7 +34,7 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
Node();
|
Node();
|
||||||
explicit Node(const Config* config);
|
explicit Node(const Config* config);
|
||||||
|
|
||||||
Node(Node&&);
|
Node(Node&& node) noexcept;
|
||||||
|
|
||||||
// Does not expose true value semantics, as children are not cloned eagerly.
|
// Does not expose true value semantics, as children are not cloned eagerly.
|
||||||
// Should we remove this?
|
// Should we remove this?
|
||||||
@@ -65,7 +65,11 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
return measureFunc_ != nullptr;
|
return measureFunc_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
YGSize measure(float, MeasureMode, float, MeasureMode);
|
YGSize measure(
|
||||||
|
float width,
|
||||||
|
MeasureMode widthMode,
|
||||||
|
float height,
|
||||||
|
MeasureMode heightMode);
|
||||||
|
|
||||||
bool hasBaselineFunc() const noexcept {
|
bool hasBaselineFunc() const noexcept {
|
||||||
return baselineFunc_ != nullptr;
|
return baselineFunc_ != nullptr;
|
||||||
@@ -73,9 +77,9 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
|
|
||||||
float baseline(float width, float height) const;
|
float baseline(float width, float height) const;
|
||||||
|
|
||||||
float dimensionWithMargin(const FlexDirection axis, const float widthSize);
|
float dimensionWithMargin(FlexDirection axis, float widthSize);
|
||||||
|
|
||||||
bool isLayoutDimensionDefined(const FlexDirection axis);
|
bool isLayoutDimensionDefined(FlexDirection axis);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the node has a "definite length" along the given axis.
|
* Whether the node has a "definite length" along the given axis.
|
||||||
@@ -214,7 +218,7 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(Direction direction);
|
void setLayoutLastOwnerDirection(Direction direction);
|
||||||
void setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis);
|
void setLayoutComputedFlexBasis(FloatOptional computedFlexBasis);
|
||||||
void setLayoutComputedFlexBasisGeneration(
|
void setLayoutComputedFlexBasisGeneration(
|
||||||
uint32_t computedFlexBasisGeneration);
|
uint32_t computedFlexBasisGeneration);
|
||||||
void setLayoutMeasuredDimension(float measuredDimension, Dimension dimension);
|
void setLayoutMeasuredDimension(float measuredDimension, Dimension dimension);
|
||||||
@@ -226,15 +230,15 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
void setLayoutPadding(float padding, PhysicalEdge edge);
|
void setLayoutPadding(float padding, PhysicalEdge edge);
|
||||||
void setLayoutPosition(float position, PhysicalEdge edge);
|
void setLayoutPosition(float position, PhysicalEdge edge);
|
||||||
void setPosition(
|
void setPosition(
|
||||||
const Direction direction,
|
Direction direction,
|
||||||
const float mainSize,
|
float mainSize,
|
||||||
const float crossSize,
|
float crossSize,
|
||||||
const float ownerWidth);
|
float ownerWidth);
|
||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
Style::Length resolveFlexBasisPtr() const;
|
Style::Length resolveFlexBasisPtr() const;
|
||||||
void resolveDimension();
|
void resolveDimension();
|
||||||
Direction resolveDirection(const Direction ownerDirection);
|
Direction resolveDirection(Direction ownerDirection);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
/// Replaces the occurrences of oldChild with newChild
|
/// Replaces the occurrences of oldChild with newChild
|
||||||
void replaceChild(Node* oldChild, Node* newChild);
|
void replaceChild(Node* oldChild, Node* newChild);
|
||||||
@@ -253,12 +257,12 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Used to allow resetting the node
|
// Used to allow resetting the node
|
||||||
Node& operator=(Node&&) = default;
|
Node& operator=(Node&&) noexcept = default;
|
||||||
|
|
||||||
float relativePosition(
|
float relativePosition(
|
||||||
FlexDirection axis,
|
FlexDirection axis,
|
||||||
Direction direction,
|
Direction direction,
|
||||||
const float axisSize) const;
|
float axisSize) const;
|
||||||
|
|
||||||
void useWebDefaults() {
|
void useWebDefaults() {
|
||||||
style_.setFlexDirection(FlexDirection::Row);
|
style_.setFlexDirection(FlexDirection::Row);
|
||||||
|
@@ -26,7 +26,7 @@ class SmallValueBuffer {
|
|||||||
SmallValueBuffer(const SmallValueBuffer& other) {
|
SmallValueBuffer(const SmallValueBuffer& other) {
|
||||||
*this = other;
|
*this = other;
|
||||||
}
|
}
|
||||||
SmallValueBuffer(SmallValueBuffer&& other) = default;
|
SmallValueBuffer(SmallValueBuffer&& other) noexcept = default;
|
||||||
|
|
||||||
// Add a new element to the buffer, returning the index of the element
|
// Add a new element to the buffer, returning the index of the element
|
||||||
uint16_t push(uint32_t value) {
|
uint16_t push(uint32_t value) {
|
||||||
@@ -116,7 +116,7 @@ class SmallValueBuffer {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SmallValueBuffer& operator=(SmallValueBuffer&& other) = default;
|
SmallValueBuffer& operator=(SmallValueBuffer&& other) noexcept = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Overflow {
|
struct Overflow {
|
||||||
@@ -125,7 +125,7 @@ class SmallValueBuffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint16_t count_{0};
|
uint16_t count_{0};
|
||||||
std::array<uint32_t, BufferSize> buffer_;
|
std::array<uint32_t, BufferSize> buffer_{};
|
||||||
std::bitset<BufferSize> wideElements_;
|
std::bitset<BufferSize> wideElements_;
|
||||||
std::unique_ptr<Overflow> overflow_;
|
std::unique_ptr<Overflow> overflow_;
|
||||||
};
|
};
|
||||||
|
@@ -101,7 +101,7 @@ class StyleValuePool {
|
|||||||
static constexpr bool isIntegerPackable(float f) {
|
static constexpr bool isIntegerPackable(float f) {
|
||||||
constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1;
|
constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1;
|
||||||
|
|
||||||
int32_t i = static_cast<int32_t>(f);
|
auto i = static_cast<int32_t>(f);
|
||||||
return static_cast<float>(i) == f && i >= -kMaxInlineAbsValue &&
|
return static_cast<float>(i) == f && i >= -kMaxInlineAbsValue &&
|
||||||
i <= +kMaxInlineAbsValue;
|
i <= +kMaxInlineAbsValue;
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ class StyleValuePool {
|
|||||||
uint16_t isNegative = value < 0 ? 1 : 0;
|
uint16_t isNegative = value < 0 ? 1 : 0;
|
||||||
return static_cast<uint16_t>(
|
return static_cast<uint16_t>(
|
||||||
(isNegative << 11) |
|
(isNegative << 11) |
|
||||||
(static_cast<int32_t>(value) * (isNegative ? -1 : 1)));
|
(static_cast<int32_t>(value) * (isNegative != 0u ? -1 : 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr float unpackInlineInteger(uint16_t value) {
|
static constexpr float unpackInlineInteger(uint16_t value) {
|
||||||
|
Reference in New Issue
Block a user