/** * 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 struct YGConfig; struct YGNode; namespace facebook { namespace yoga { struct Event { enum Type { NodeAllocation, NodeDeallocation, NodeLayout, LayoutPassStart, LayoutPassEnd }; 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 = {}) { publish(node, E, Data{eventData}); } 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; }; } // namespace yoga } // namespace facebook