slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
StyleLength.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/enums/Unit.h>
12
13namespace facebook::yoga {
14
29 public:
30 constexpr StyleLength() = default;
31
32 constexpr static StyleLength points(float value) {
34 ? undefined()
36 }
37
43
44 constexpr static StyleLength ofAuto() {
45 return StyleLength{{}, Unit::Auto};
46 }
47
48 constexpr static StyleLength undefined() {
49 return StyleLength{{}, Unit::Undefined};
50 }
51
52 constexpr bool isAuto() const {
53 return unit_ == Unit::Auto;
54 }
55
56 constexpr bool isUndefined() const {
57 return unit_ == Unit::Undefined;
58 }
59
60 constexpr bool isPoints() const {
61 return unit_ == Unit::Point;
62 }
63
64 constexpr bool isPercent() const {
65 return unit_ == Unit::Percent;
66 }
67
68 constexpr bool isDefined() const {
69 return !isUndefined();
70 }
71
72 constexpr FloatOptional value() const {
73 return value_;
74 }
75
76 constexpr FloatOptional resolve(float referenceLength) {
77#ifdef __clang__
78#pragma clang diagnostic push
79#pragma clang diagnostic ignored "-Wswitch-enum"
80#endif
81 switch (unit_) {
82#ifdef __clang__
83#pragma clang diagnostic pop
84#endif
85 case Unit::Point:
86 return value_;
87 case Unit::Percent:
88 return FloatOptional{value_.unwrap() * referenceLength * 0.01f};
89 default:
90 return FloatOptional{};
91 }
92 }
93
94 explicit constexpr operator YGValue() const {
96 }
97
98 constexpr bool operator==(const StyleLength& rhs) const {
99 return value_ == rhs.value_ && unit_ == rhs.unit_;
100 }
101
102 constexpr bool inexactEquals(const StyleLength& other) const {
103 return unit_ == other.unit_ &&
105 }
106
107 private:
108 // We intentionally do not allow direct construction using value and unit, to
109 // avoid invalid, or redundant combinations.
111 : value_(value), unit_(unit) {}
112
115};
116
117inline bool inexactEquals(const StyleLength& a, const StyleLength& b) {
118 return a.inexactEquals(b);
119}
120
121} // namespace facebook::yoga
YG_EXTERN_C_BEGIN struct YGValue YGValue
Definition StyleLength.h:28
Unit unit_
Definition StyleLength.h:114
FloatOptional value_
Definition StyleLength.h:113
constexpr StyleLength(FloatOptional value, Unit unit)
Definition StyleLength.h:110
constexpr StyleLength()=default
static constexpr StyleLength undefined()
Definition StyleLength.h:48
constexpr bool isUndefined() const
Definition StyleLength.h:56
constexpr FloatOptional value() const
Definition StyleLength.h:72
constexpr FloatOptional resolve(float referenceLength)
Definition StyleLength.h:76
static constexpr StyleLength ofAuto()
Definition StyleLength.h:44
static constexpr StyleLength percent(float value)
Definition StyleLength.h:38
constexpr bool isPoints() const
Definition StyleLength.h:60
static constexpr StyleLength points(float value)
Definition StyleLength.h:32
constexpr bool isPercent() const
Definition StyleLength.h:64
constexpr bool operator==(const StyleLength &rhs) const
Definition StyleLength.h:98
constexpr bool isAuto() const
Definition StyleLength.h:52
constexpr bool isDefined() const
Definition StyleLength.h:68
constexpr bool inexactEquals(const StyleLength &other) const
Definition StyleLength.h:102
Definition Benchmark.cpp:19
Unit
Definition Unit.h:18
static bool isUndefined(json &j)
Definition TreeDeserialization.cpp:24
constexpr bool isinf(auto value)
Definition Comparison.h:30
constexpr YGAlign unscopedEnum(Align scoped)
Definition Align.h:41
bool inexactEquals(float a, float b)
Definition Comparison.h:56
Definition YGValue.h:31
Definition FloatOptional.h:15
constexpr float unwrap() const
Definition FloatOptional.h:24