slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
event.h
浏览该文件的文档.
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
17namespace facebook::yoga {
18
19enum struct LayoutType : int {
20 kLayout = 0,
21 kMeasure = 1,
22 kCachedLayout = 2,
24};
25
26enum struct LayoutPassReason : int {
27 kInitial = 0,
28 kAbsLayout = 1,
29 kStretch = 2,
31 kFlexLayout = 4,
32 kMeasureChild = 5,
34 kFlexMeasure = 7,
35 kGridLayout = 8,
36 COUNT
37};
38
39struct LayoutData {
40 int layouts = 0;
41 int measures = 0;
42 uint32_t maxMeasureCache = 0;
46 std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)>
48};
49
51
64 class 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 explicit Data(const TypedData<E>& data) : data_{&data} {}
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 static void publish(YGNodeConstRef node, const TypedData<E>& eventData = {}) {
90 publish(node, E, Data{eventData});
91 }
92
93 private:
94 static void publish(
95 YGNodeConstRef /*node*/,
96 Type /*eventType*/,
97 const Data& /*eventData*/);
98};
99
100template <>
101struct Event::TypedData<Event::NodeAllocation> {
103};
104
105template <>
106struct Event::TypedData<Event::NodeDeallocation> {
108};
109
110template <>
111struct Event::TypedData<Event::LayoutPassEnd> {
113};
114
115template <>
116struct Event::TypedData<Event::MeasureCallbackEnd> {
117 float width;
118 YGMeasureMode widthMeasureMode;
119 float height;
120 YGMeasureMode heightMeasureMode;
124};
125
126template <>
127struct Event::TypedData<Event::NodeLayout> {
129};
130
131} // namespace facebook::yoga
#define YG_EXPORT
Definition YGMacros.h:35
Definition event.h:71
const void * data_
Definition event.h:72
const TypedData< E > & get() const
Definition event.h:79
Data(const TypedData< E > &data)
Definition event.h:76
Definition Benchmark.cpp:19
LayoutPassReason
Definition event.h:26
LayoutType
Definition event.h:19
const char * LayoutPassReasonToString(const LayoutPassReason value)
Definition event.cpp:14
Definition Config.h:18
Definition Node.h:29
const LayoutPassReason reason
Definition event.h:123
YGConfigConstRef config
Definition event.h:102
YGConfigConstRef config
Definition event.h:107
Definition event.h:52
static void publish(YGNodeConstRef node, const TypedData< E > &eventData={})
Definition event.h:89
void(YGNodeConstRef, Type, Data) Subscriber
Definition event.h:65
std::vector< std::function< Subscriber > > Subscribers
Definition event.h:66
Type
Definition event.h:53
@ NodeDeallocation
Definition event.h:55
@ MeasureCallbackEnd
Definition event.h:60
@ LayoutPassStart
Definition event.h:57
@ NodeBaselineEnd
Definition event.h:62
@ NodeBaselineStart
Definition event.h:61
@ MeasureCallbackStart
Definition event.h:59
@ NodeLayout
Definition event.h:56
@ NodeAllocation
Definition event.h:54
@ LayoutPassEnd
Definition event.h:58
Definition event.h:39
int layouts
Definition event.h:40
int measureCallbacks
Definition event.h:45
std::array< int, static_cast< uint8_t >(LayoutPassReason::COUNT)> measureCallbackReasonsCount
Definition event.h:47
int cachedLayouts
Definition event.h:43
int cachedMeasures
Definition event.h:44
int measures
Definition event.h:41
uint32_t maxMeasureCache
Definition event.h:42
std::function< Event::Subscriber > subscriber
Definition event.cpp:42