/src/yoga/yoga/event/event.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <yoga/Yoga.h> |
11 | | |
12 | | #include <array> |
13 | | #include <cstdint> |
14 | | #include <functional> |
15 | | #include <vector> |
16 | | |
17 | | namespace facebook::yoga { |
18 | | |
19 | | enum struct LayoutType : int { |
20 | | kLayout = 0, |
21 | | kMeasure = 1, |
22 | | kCachedLayout = 2, |
23 | | kCachedMeasure = 3 |
24 | | }; |
25 | | |
26 | | enum struct LayoutPassReason : int { |
27 | | kInitial = 0, |
28 | | kAbsLayout = 1, |
29 | | kStretch = 2, |
30 | | kMultilineStretch = 3, |
31 | | kFlexLayout = 4, |
32 | | kMeasureChild = 5, |
33 | | kAbsMeasureChild = 6, |
34 | | kFlexMeasure = 7, |
35 | | COUNT |
36 | | }; |
37 | | |
38 | | struct LayoutData { |
39 | | int layouts = 0; |
40 | | int measures = 0; |
41 | | uint32_t maxMeasureCache = 0; |
42 | | int cachedLayouts = 0; |
43 | | int cachedMeasures = 0; |
44 | | int measureCallbacks = 0; |
45 | | std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)> |
46 | | measureCallbackReasonsCount; |
47 | | }; |
48 | | |
49 | | const char* LayoutPassReasonToString(LayoutPassReason value); |
50 | | |
51 | | struct YG_EXPORT Event { |
52 | | enum Type { |
53 | | NodeAllocation, |
54 | | NodeDeallocation, |
55 | | NodeLayout, |
56 | | LayoutPassStart, |
57 | | LayoutPassEnd, |
58 | | MeasureCallbackStart, |
59 | | MeasureCallbackEnd, |
60 | | NodeBaselineStart, |
61 | | NodeBaselineEnd, |
62 | | }; |
63 | | class Data; |
64 | | using Subscriber = void(YGNodeConstRef, Type, Data); |
65 | | using Subscribers = std::vector<std::function<Subscriber>>; |
66 | | |
67 | | template <Type E> |
68 | | struct TypedData {}; |
69 | | |
70 | | class Data { |
71 | | const void* data_; |
72 | | |
73 | | public: |
74 | | template <Type E> |
75 | 27.8M | explicit Data(const TypedData<E>& data) : data_{&data} {}facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)0>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)0> const&) Line | Count | Source | 75 | 3.04M | explicit Data(const TypedData<E>& data) : data_{&data} {} |
facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)1>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)1> const&) Line | Count | Source | 75 | 3.04M | explicit Data(const TypedData<E>& data) : data_{&data} {} |
Unexecuted instantiation: facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)5>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)5> const&) Unexecuted instantiation: facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)6>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)6> const&) facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)2>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)2> const&) Line | Count | Source | 75 | 21.7M | explicit Data(const TypedData<E>& data) : data_{&data} {} |
facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)3>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)3> const&) Line | Count | Source | 75 | 1.03k | explicit Data(const TypedData<E>& data) : data_{&data} {} |
facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)4>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)4> const&) Line | Count | Source | 75 | 1.03k | explicit Data(const TypedData<E>& data) : data_{&data} {} |
Unexecuted instantiation: facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)7>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)7> const&) Unexecuted instantiation: facebook::yoga::Event::Data::Data<(facebook::yoga::Event::Type)8>(facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)8> const&) |
76 | | |
77 | | template <Type E> |
78 | | const TypedData<E>& get() const { |
79 | | return *static_cast<const TypedData<E>*>(data_); |
80 | | } |
81 | | }; |
82 | | |
83 | | static void reset(); |
84 | | |
85 | | static void subscribe(std::function<Subscriber>&& subscriber); |
86 | | |
87 | | template <Type E> |
88 | 27.8M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { |
89 | 27.8M | publish(node, E, Data{eventData}); |
90 | 27.8M | } void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)0>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)0> const&) Line | Count | Source | 88 | 3.04M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 89 | 3.04M | publish(node, E, Data{eventData}); | 90 | 3.04M | } |
void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)1>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)1> const&) Line | Count | Source | 88 | 3.04M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 89 | 3.04M | publish(node, E, Data{eventData}); | 90 | 3.04M | } |
Unexecuted instantiation: void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)5>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)5> const&) Unexecuted instantiation: void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)6>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)6> const&) void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)2>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)2> const&) Line | Count | Source | 88 | 21.7M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 89 | 21.7M | publish(node, E, Data{eventData}); | 90 | 21.7M | } |
void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)3>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)3> const&) Line | Count | Source | 88 | 1.03k | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 89 | 1.03k | publish(node, E, Data{eventData}); | 90 | 1.03k | } |
void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)4>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)4> const&) Line | Count | Source | 88 | 1.03k | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 89 | 1.03k | publish(node, E, Data{eventData}); | 90 | 1.03k | } |
Unexecuted instantiation: void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)7>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)7> const&) Unexecuted instantiation: void facebook::yoga::Event::publish<(facebook::yoga::Event::Type)8>(YGNode const*, facebook::yoga::Event::TypedData<(facebook::yoga::Event::Type)8> const&) |
91 | | |
92 | | private: |
93 | | static void publish( |
94 | | YGNodeConstRef /*node*/, |
95 | | Type /*eventType*/, |
96 | | const Data& /*eventData*/); |
97 | | }; |
98 | | |
99 | | template <> |
100 | | struct Event::TypedData<Event::NodeAllocation> { |
101 | | YGConfigConstRef config; |
102 | | }; |
103 | | |
104 | | template <> |
105 | | struct Event::TypedData<Event::NodeDeallocation> { |
106 | | YGConfigConstRef config; |
107 | | }; |
108 | | |
109 | | template <> |
110 | | struct Event::TypedData<Event::LayoutPassEnd> { |
111 | | LayoutData* layoutData; |
112 | | }; |
113 | | |
114 | | template <> |
115 | | struct Event::TypedData<Event::MeasureCallbackEnd> { |
116 | | float width; |
117 | | YGMeasureMode widthMeasureMode; |
118 | | float height; |
119 | | YGMeasureMode heightMeasureMode; |
120 | | float measuredWidth; |
121 | | float measuredHeight; |
122 | | const LayoutPassReason reason; |
123 | | }; |
124 | | |
125 | | template <> |
126 | | struct Event::TypedData<Event::NodeLayout> { |
127 | | LayoutType layoutType; |
128 | | }; |
129 | | |
130 | | } // namespace facebook::yoga |