slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
YGJNI.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#include <yoga/Yoga.h>
9
10const short int LAYOUT_EDGE_SET_FLAG_INDEX = 0;
11const short int LAYOUT_WIDTH_INDEX = 1;
12const short int LAYOUT_HEIGHT_INDEX = 2;
13const short int LAYOUT_LEFT_INDEX = 3;
14const short int LAYOUT_TOP_INDEX = 4;
15const short int LAYOUT_DIRECTION_INDEX = 5;
16const short int LAYOUT_MARGIN_START_INDEX = 6;
17const short int LAYOUT_PADDING_START_INDEX = 10;
18const short int LAYOUT_BORDER_START_INDEX = 14;
19
20namespace {
21
22const int HAS_NEW_LAYOUT = 16;
23
24union YGNodeContext {
25 int32_t edgesSet = 0;
26 void* asVoidPtr;
27};
28
29class YGNodeEdges {
30 int32_t edges_;
31
32 public:
33 enum Edge {
34 MARGIN = 1,
35 PADDING = 2,
36 BORDER = 4,
37 };
38
39 explicit YGNodeEdges(YGNodeRef node) {
40 auto context = YGNodeContext{};
41 context.asVoidPtr = YGNodeGetContext(node);
42 edges_ = context.edgesSet;
43 }
44
45 void setOn(YGNodeRef node) {
46 auto context = YGNodeContext{};
47 context.edgesSet = edges_;
48 YGNodeSetContext(node, context.asVoidPtr);
49 }
50
51 bool has(Edge edge) {
52 return (edges_ & edge) == edge;
53 }
54
55 YGNodeEdges& add(Edge edge) {
56 edges_ |= edge;
57 return *this;
58 }
59
60 int get() {
61 return edges_;
62 }
63};
64
65struct YogaValue {
66 static constexpr jint NAN_BYTES = 0x7fc00000;
67
68 static jlong asJavaLong(const YGValue& value) {
69 uint32_t valueBytes = 0;
70 memcpy(&valueBytes, &value.value, sizeof valueBytes);
71 return ((jlong)value.unit) << 32 | valueBytes;
72 }
73 constexpr static jlong undefinedAsJavaLong() {
74 return ((jlong)YGUnitUndefined) << 32 | NAN_BYTES;
75 }
76};
77} // namespace
typedefYG_EXTERN_C_BEGIN struct YGNode * YGNodeRef
Definition YGConfig.h:19
YG_EXTERN_C_BEGIN YGBoxSizingContentBox YGDirectionRTL YGEdgeAll YGExperimentalFeatureFixFlexBasisFitContent YGGridTrackTypeMinmax YGJustifyEnd YGMeasureModeAtMost YGOverflowScroll YGUnitUndefined
Definition YGEnums.h:147
const short int LAYOUT_WIDTH_INDEX
Definition YGJNI.h:11
const short int LAYOUT_HEIGHT_INDEX
Definition YGJNI.h:12
const short int LAYOUT_DIRECTION_INDEX
Definition YGJNI.h:15
const short int LAYOUT_TOP_INDEX
Definition YGJNI.h:14
const short int LAYOUT_EDGE_SET_FLAG_INDEX
Definition YGJNI.h:10
const short int LAYOUT_MARGIN_START_INDEX
Definition YGJNI.h:16
const short int LAYOUT_BORDER_START_INDEX
Definition YGJNI.h:18
const short int LAYOUT_LEFT_INDEX
Definition YGJNI.h:13
const short int LAYOUT_PADDING_START_INDEX
Definition YGJNI.h:17
void YGNodeSetContext(YGNodeRef node, void *context)
Definition YGNode.cpp:296
void * YGNodeGetContext(YGNodeConstRef node)
Definition YGNode.cpp:300
int32_t jint
Definition jni.h:35
int64_t jlong
Definition jni.h:36
Definition YGValue.h:31