YGConfig.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "YGConfig.h"
  8. YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
  9. logger_.noContext = logger;
  10. loggerUsesContext_ = false;
  11. }
  12. void YGConfig::log(
  13. YGConfig* config,
  14. YGNode* node,
  15. YGLogLevel logLevel,
  16. void* logContext,
  17. const char* format,
  18. va_list args) {
  19. if (loggerUsesContext_) {
  20. logger_.withContext(config, node, logLevel, logContext, format, args);
  21. } else {
  22. logger_.noContext(config, node, logLevel, format, args);
  23. }
  24. }
  25. YGNodeRef YGConfig::cloneNode(
  26. YGNodeRef node,
  27. YGNodeRef owner,
  28. int childIndex,
  29. void* cloneContext) {
  30. YGNodeRef clone = nullptr;
  31. if (cloneNodeCallback_.noContext != nullptr) {
  32. clone = cloneNodeUsesContext_
  33. ? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext)
  34. : cloneNodeCallback_.noContext(node, owner, childIndex);
  35. }
  36. if (clone == nullptr) {
  37. clone = YGNodeClone(node);
  38. }
  39. return clone;
  40. }