/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include struct YGConfig; struct YGNode; namespace facebook { namespace yoga { enum struct LayoutType : int { kLayout = 0, kMeasure = 1, kCachedLayout = 2, kCachedMeasure = 3 }; enum struct LayoutPassReason : int { kInitial = 0, kAbsLayout = 1, kStretch = 2, kMultilineStretch = 3, kFlexLayout = 4, kMeasureChild = 5, kAbsMeasureChild = 6, kFlexMeasure = 7, COUNT }; struct LayoutData { int layouts; int measures; int maxMeasureCache; int cachedLayouts; int cachedMeasures; int measureCallbacks; std::array(LayoutPassReason::COUNT)> measureCallbackReasonsCount; }; const char* LayoutPassReasonToString(const LayoutPassReason value); struct YOGA_EXPORT Event { enum Type { NodeAllocation, NodeDeallocation, NodeLayout, LayoutPassStart, LayoutPassEnd, MeasureCallbackStart, MeasureCallbackEnd, NodeBaselineStart, NodeBaselineEnd, }; class Data; using Subscriber = void(const YGNode&, Type, Data); using Subscribers = std::vector>; template struct TypedData {}; class Data { const void* data_; public: template Data(const TypedData& data) : data_{&data} {} template const TypedData& get() const { return *static_cast*>(data_); }; }; static void reset(); static void subscribe(std::function&& subscriber); template static void publish(const YGNode& node, const TypedData& eventData = {}) { #ifdef YG_ENABLE_EVENTS publish(node, E, Data{eventData}); #endif } template static void publish(const YGNode* node, const TypedData& eventData = {}) { publish(*node, eventData); } private: static void publish(const YGNode&, Type, const Data&); }; template <> struct Event::TypedData { YGConfig* config; }; template <> struct Event::TypedData { YGConfig* config; }; template <> struct Event::TypedData { void* layoutContext; }; template <> struct Event::TypedData { void* layoutContext; LayoutData* layoutData; }; template <> struct Event::TypedData { void* layoutContext; float width; YGMeasureMode widthMeasureMode; float height; YGMeasureMode heightMeasureMode; float measuredWidth; float measuredHeight; const LayoutPassReason reason; }; template <> struct Event::TypedData { LayoutType layoutType; void* layoutContext; }; } // namespace yoga } // namespace facebook