YGConfig.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the LICENSE
  5. * file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include "YGMarker.h"
  9. #include "Yoga-internal.h"
  10. #include "Yoga.h"
  11. struct YGConfig {
  12. using LogWithContextFn = int (*)(
  13. YGConfigRef config,
  14. YGNodeRef node,
  15. YGLogLevel level,
  16. void* context,
  17. const char* format,
  18. va_list args);
  19. using CloneWithContextFn = YGNodeRef (*)(
  20. YGNodeRef node,
  21. YGNodeRef owner,
  22. int childIndex,
  23. void* cloneContext);
  24. private:
  25. union {
  26. CloneWithContextFn withContext;
  27. YGCloneNodeFunc noContext;
  28. } cloneNodeCallback_;
  29. union {
  30. LogWithContextFn withContext;
  31. YGLogger noContext;
  32. } logger_;
  33. bool cloneNodeUsesContext_;
  34. bool loggerUsesContext_;
  35. public:
  36. bool useWebDefaults = false;
  37. bool useLegacyStretchBehaviour = false;
  38. bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
  39. bool printTree = false;
  40. float pointScaleFactor = 1.0f;
  41. std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
  42. experimentalFeatures = {};
  43. void* context = nullptr;
  44. YGMarkerCallbacks markerCallbacks = {nullptr, nullptr};
  45. YGConfig(YGLogger logger);
  46. void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list);
  47. void setLogger(YGLogger logger) {
  48. logger_.noContext = logger;
  49. loggerUsesContext_ = false;
  50. }
  51. void setLogger(LogWithContextFn logger) {
  52. logger_.withContext = logger;
  53. loggerUsesContext_ = true;
  54. }
  55. void setLogger(std::nullptr_t) {
  56. setLogger(YGLogger{nullptr});
  57. }
  58. YGNodeRef cloneNode(
  59. YGNodeRef node,
  60. YGNodeRef owner,
  61. int childIndex,
  62. void* cloneContext);
  63. void setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
  64. cloneNodeCallback_.noContext = cloneNode;
  65. cloneNodeUsesContext_ = false;
  66. }
  67. void setCloneNodeCallback(CloneWithContextFn cloneNode) {
  68. cloneNodeCallback_.withContext = cloneNode;
  69. cloneNodeUsesContext_ = true;
  70. }
  71. void setCloneNodeCallback(std::nullptr_t) {
  72. setCloneNodeCallback(YGCloneNodeFunc{nullptr});
  73. }
  74. };