slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
StyleValueHandle.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 <cstdint>
11
12#include <yoga/Yoga.h>
13
17
18namespace facebook::yoga {
19
20#pragma pack(push)
21#pragma pack(1)
22
33 public:
34 static constexpr StyleValueHandle ofAuto() {
35 StyleValueHandle handle;
36 handle.setType(Type::Auto);
37 return handle;
38 }
39
40 constexpr bool isUndefined() const {
41 return type() == Type::Undefined;
42 }
43
44 constexpr bool isDefined() const {
45 return !isUndefined();
46 }
47
48 constexpr bool isAuto() const {
49 return type() == Type::Auto;
50 }
51
52 constexpr bool isPercent() const {
53 return type() == Type::Percent;
54 }
55
56 constexpr bool isPoint() const {
57 return type() == Type::Point;
58 }
59
60 private:
61 friend class StyleValuePool;
62
63 static constexpr uint16_t kHandleTypeMask = 0b0000'0000'0000'0111;
64 static constexpr uint16_t kHandleIndexedMask = 0b0000'0000'0000'1000;
65 static constexpr uint16_t kHandleValueMask = 0b1111'1111'1111'0000;
66
67 enum class Type : uint8_t {
69 Point,
70 Percent,
71 Number,
72 Auto,
74 };
75
76 // Intentionally leaving out auto as a fast path
77 enum class Keyword : uint8_t { MaxContent, FitContent, Stretch };
78
79 constexpr bool isKeyword(Keyword keyword) const {
80 return type() == Type::Keyword && value() == static_cast<uint16_t>(keyword);
81 }
82
83 constexpr Type type() const {
84 return static_cast<Type>(repr_ & kHandleTypeMask);
85 }
86
87 constexpr void setType(Type handleType) {
88 repr_ &= (~kHandleTypeMask);
89 repr_ |= static_cast<uint8_t>(handleType);
90 }
91
92 constexpr uint16_t value() const {
93 return repr_ >> 4;
94 }
95
96 constexpr void setValue(uint16_t value) {
97 repr_ &= (~kHandleValueMask);
98 repr_ |= (value << 4);
99 }
100
101 constexpr bool isValueIndexed() const {
102 return (repr_ & kHandleIndexedMask) != 0;
103 }
104
105 constexpr void setValueIsIndexed() {
107 }
108
109 uint16_t repr_{0};
110};
111
112#pragma pack(pop)
113
114} // namespace facebook::yoga
Definition StyleValueHandle.h:32
constexpr bool isKeyword(Keyword keyword) const
Definition StyleValueHandle.h:79
uint16_t repr_
Definition StyleValueHandle.h:109
constexpr bool isAuto() const
Definition StyleValueHandle.h:48
constexpr bool isPoint() const
Definition StyleValueHandle.h:56
constexpr bool isUndefined() const
Definition StyleValueHandle.h:40
constexpr bool isDefined() const
Definition StyleValueHandle.h:44
constexpr void setType(Type handleType)
Definition StyleValueHandle.h:87
constexpr bool isPercent() const
Definition StyleValueHandle.h:52
static constexpr StyleValueHandle ofAuto()
Definition StyleValueHandle.h:34
constexpr void setValueIsIndexed()
Definition StyleValueHandle.h:105
static constexpr uint16_t kHandleValueMask
Definition StyleValueHandle.h:65
Type
Definition StyleValueHandle.h:67
constexpr Type type() const
Definition StyleValueHandle.h:83
static constexpr uint16_t kHandleTypeMask
Definition StyleValueHandle.h:63
static constexpr uint16_t kHandleIndexedMask
Definition StyleValueHandle.h:64
constexpr bool isValueIndexed() const
Definition StyleValueHandle.h:101
Keyword
Definition StyleValueHandle.h:77
constexpr uint16_t value() const
Definition StyleValueHandle.h:92
constexpr void setValue(uint16_t value)
Definition StyleValueHandle.h:96
Definition StyleValuePool.h:28
Definition Benchmark.cpp:19