Skip to content

Commit

Permalink
C++ style enums 6/N: PrintOptions (#39449)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39449

X-link: facebook/yoga#1385

This converts usages of YGPrintOptions to PrintOptions

Reviewed By: rozele

Differential Revision: D49270929

fbshipit-source-id: ad98dd25865138808d25b48eff22fbe81ccdd352
  • Loading branch information
NickGerleman authored and pull[bot] committed Dec 13, 2023
1 parent 9bf6c35 commit e5a7551
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
7 changes: 2 additions & 5 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,8 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border)
YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding)

#ifdef DEBUG
void YGNodePrint(const YGNodeConstRef nodeRef, const YGPrintOptions options) {
const auto node = resolveRef(nodeRef);
std::string str;
yoga::nodeToString(str, node, options, 0);
yoga::log(node, LogLevel::Debug, str.c_str());
void YGNodePrint(const YGNodeConstRef node, const YGPrintOptions options) {
yoga::print(resolveRef(node), scopedEnum(options));
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <yoga/algorithm/ResolveValue.h>
#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
#include <yoga/debug/NodeToString.h>
#include <yoga/event/event.h>
#include <yoga/node/Node.h>
#include <yoga/numeric/Comparison.h>
Expand Down Expand Up @@ -2737,9 +2738,9 @@ void calculateLayout(

#ifdef DEBUG
if (node->getConfig()->shouldPrintTree()) {
YGNodePrint(
yoga::print(
node,
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
PrintOptions::Layout | PrintOptions::Children | PrintOptions::Style);
}
#endif
}
Expand Down
16 changes: 12 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <yoga/YGEnums.h>

#include <yoga/debug/Log.h>
#include <yoga/debug/NodeToString.h>
#include <yoga/numeric/Comparison.h>

Expand Down Expand Up @@ -118,12 +119,12 @@ static void appendEdgeIfNotUndefined(
void nodeToString(
std::string& str,
const yoga::Node* node,
YGPrintOptions options,
PrintOptions options,
uint32_t level) {
indent(str, level);
appendFormattedString(str, "<div ");

if (options & YGPrintOptionsLayout) {
if ((options & PrintOptions::Layout) == PrintOptions::Layout) {
appendFormattedString(str, "layout=\"");
appendFormattedString(
str, "width: %g; ", node->getLayout().dimensions[YGDimensionWidth]);
Expand All @@ -136,7 +137,7 @@ void nodeToString(
appendFormattedString(str, "\" ");
}

if (options & YGPrintOptionsStyle) {
if ((options & PrintOptions::Style) == PrintOptions::Style) {
appendFormattedString(str, "style=\"");
const auto& style = node->getStyle();
if (style.flexDirection() != yoga::Node{}.getStyle().flexDirection()) {
Expand Down Expand Up @@ -228,7 +229,8 @@ void nodeToString(
appendFormattedString(str, ">");

const size_t childCount = node->getChildCount();
if (options & YGPrintOptionsChildren && childCount > 0) {
if ((options & PrintOptions::Children) == PrintOptions::Children &&
childCount > 0) {
for (size_t i = 0; i < childCount; i++) {
appendFormattedString(str, "\n");
nodeToString(str, node->getChild(i), options, level + 1);
Expand All @@ -239,5 +241,11 @@ void nodeToString(
appendFormattedString(str, "</div>");
}

void print(const yoga::Node* node, PrintOptions options) {
std::string str;
yoga::nodeToString(str, node, options, 0);
yoga::log(node, LogLevel::Debug, str.c_str());
}

} // namespace facebook::yoga
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

#include <string>

#include <yoga/Yoga.h>
#include <yoga/enums/PrintOptions.h>
#include <yoga/node/Node.h>

namespace facebook::yoga {

void nodeToString(
std::string& str,
const yoga::Node* node,
YGPrintOptions options,
PrintOptions options,
uint32_t level);

void print(const yoga::Node* node, PrintOptions options);

} // namespace facebook::yoga

#endif

0 comments on commit e5a7551

Please sign in to comment.