/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 | | kGridLayout = 8, |
36 | | COUNT |
37 | | }; |
38 | | |
39 | | struct LayoutData { |
40 | | int layouts = 0; |
41 | | int measures = 0; |
42 | | uint32_t maxMeasureCache = 0; |
43 | | int cachedLayouts = 0; |
44 | | int cachedMeasures = 0; |
45 | | int measureCallbacks = 0; |
46 | | std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)> |
47 | | measureCallbackReasonsCount; |
48 | | }; |
49 | | |
50 | | const char* LayoutPassReasonToString(LayoutPassReason value); |
51 | | |
52 | | struct YG_EXPORT Event { |
53 | | enum Type { |
54 | | NodeAllocation, |
55 | | NodeDeallocation, |
56 | | NodeLayout, |
57 | | LayoutPassStart, |
58 | | LayoutPassEnd, |
59 | | MeasureCallbackStart, |
60 | | MeasureCallbackEnd, |
61 | | NodeBaselineStart, |
62 | | NodeBaselineEnd, |
63 | | }; |
64 | | class Data; |
65 | | using Subscriber = void(YGNodeConstRef, Type, Data); |
66 | | using Subscribers = std::vector<std::function<Subscriber>>; |
67 | | |
68 | | template <Type E> |
69 | | struct TypedData {}; |
70 | | |
71 | | class Data { |
72 | | const void* data_; |
73 | | |
74 | | public: |
75 | | template <Type E> |
76 | 29.4M | 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 | 76 | 1.71M | 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 | 76 | 1.71M | 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 | 76 | 26.0M | 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 | 76 | 802 | 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 | 76 | 802 | 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&) |
77 | | |
78 | | template <Type E> |
79 | | const TypedData<E>& get() const { |
80 | | return *static_cast<const TypedData<E>*>(data_); |
81 | | } |
82 | | }; |
83 | | |
84 | | static void reset(); |
85 | | |
86 | | static void subscribe(std::function<Subscriber>&& subscriber); |
87 | | |
88 | | template <Type E> |
89 | 29.4M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { |
90 | 29.4M | publish(node, E, Data{eventData}); |
91 | 29.4M | } 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 | 89 | 1.71M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 90 | 1.71M | publish(node, E, Data{eventData}); | 91 | 1.71M | } |
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 | 89 | 1.71M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 90 | 1.71M | publish(node, E, Data{eventData}); | 91 | 1.71M | } |
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 | 89 | 26.0M | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 90 | 26.0M | publish(node, E, Data{eventData}); | 91 | 26.0M | } |
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 | 89 | 802 | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 90 | 802 | publish(node, E, Data{eventData}); | 91 | 802 | } |
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 | 89 | 802 | static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) { | 90 | 802 | publish(node, E, Data{eventData}); | 91 | 802 | } |
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&) |
92 | | |
93 | | private: |
94 | | static void publish( |
95 | | YGNodeConstRef /*node*/, |
96 | | Type /*eventType*/, |
97 | | const Data& /*eventData*/); |
98 | | }; |
99 | | |
100 | | template <> |
101 | | struct Event::TypedData<Event::NodeAllocation> { |
102 | | YGConfigConstRef config; |
103 | | }; |
104 | | |
105 | | template <> |
106 | | struct Event::TypedData<Event::NodeDeallocation> { |
107 | | YGConfigConstRef config; |
108 | | }; |
109 | | |
110 | | template <> |
111 | | struct Event::TypedData<Event::LayoutPassEnd> { |
112 | | LayoutData* layoutData; |
113 | | }; |
114 | | |
115 | | template <> |
116 | | struct Event::TypedData<Event::MeasureCallbackEnd> { |
117 | | float width; |
118 | | YGMeasureMode widthMeasureMode; |
119 | | float height; |
120 | | YGMeasureMode heightMeasureMode; |
121 | | float measuredWidth; |
122 | | float measuredHeight; |
123 | | const LayoutPassReason reason; |
124 | | }; |
125 | | |
126 | | template <> |
127 | | struct Event::TypedData<Event::NodeLayout> { |
128 | | LayoutType layoutType; |
129 | | }; |
130 | | |
131 | | } // namespace facebook::yoga |