YGMarker.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "YGMacros.h"
  9. YG_EXTERN_C_BEGIN
  10. typedef struct YGNode* YGNodeRef;
  11. typedef struct YGConfig* YGConfigRef;
  12. typedef YG_ENUM_BEGIN(YGMarker){
  13. YGMarkerLayout,
  14. YGMarkerMeasure,
  15. YGMarkerBaselineFn,
  16. } YG_ENUM_END(YGMarker);
  17. typedef struct {
  18. int layouts;
  19. int measures;
  20. int maxMeasureCache;
  21. int cachedLayouts;
  22. int cachedMeasures;
  23. } YGMarkerLayoutData;
  24. typedef struct {
  25. bool _unused;
  26. } YGMarkerNoData;
  27. typedef union {
  28. YGMarkerLayoutData* layout;
  29. YGMarkerNoData* noData;
  30. } YGMarkerData;
  31. typedef struct {
  32. // accepts marker type, a node ref, and marker data (depends on marker type)
  33. // can return a handle or id that Yoga will pass to endMarker
  34. void* (*startMarker)(YGMarker, YGNodeRef, YGMarkerData);
  35. // accepts marker type, a node ref, marker data, and marker id as returned by
  36. // startMarker
  37. void (*endMarker)(YGMarker, YGNodeRef, YGMarkerData, void* id);
  38. } YGMarkerCallbacks;
  39. void YGConfigSetMarkerCallbacks(YGConfigRef, YGMarkerCallbacks);
  40. YG_EXTERN_C_END
  41. #ifdef __cplusplus
  42. namespace facebook {
  43. namespace yoga {
  44. namespace marker {
  45. namespace detail {
  46. template <YGMarker M>
  47. struct MarkerData;
  48. template <>
  49. struct MarkerData<YGMarkerLayout> {
  50. using type = YGMarkerLayoutData;
  51. static type*& get(YGMarkerData& d) {
  52. return d.layout;
  53. }
  54. };
  55. struct NoMarkerData {
  56. using type = YGMarkerNoData;
  57. static type*& get(YGMarkerData& d) {
  58. return d.noData;
  59. }
  60. };
  61. template <>
  62. struct MarkerData<YGMarkerMeasure> : NoMarkerData {};
  63. template <>
  64. struct MarkerData<YGMarkerBaselineFn> : NoMarkerData {};
  65. } // namespace detail
  66. template <YGMarker M>
  67. typename detail::MarkerData<M>::type* data(YGMarkerData d) {
  68. return detail::MarkerData<M>::get(d);
  69. }
  70. } // namespace marker
  71. } // namespace yoga
  72. } // namespace facebook
  73. #endif // __cplusplus