1/*
2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 *
5 * SPDX-License-Identifier: MIT
6 */
7
8#pragma once
9
10#include "BitUtils.h"
11#include "YGFloatOptional.h"
12#include "Yoga-internal.h"
13
14QT_YOGA_NAMESPACE_BEGIN
15
16struct YGLayout {
17 std::array<float, 4> position = {};
18 std::array<float, 2> dimensions = {._M_elems: {YGUndefined, YGUndefined}};
19 std::array<float, 4> margin = {};
20 std::array<float, 4> border = {};
21 std::array<float, 4> padding = {};
22
23private:
24 static constexpr size_t directionOffset = 0;
25 static constexpr size_t hadOverflowOffset =
26 directionOffset + facebook::yoga::detail::bitWidthFn<YGDirection>();
27 uint8_t flags = 0;
28
29public:
30 uint32_t computedFlexBasisGeneration = 0;
31 YGFloatOptional computedFlexBasis = {};
32
33 // Instead of recomputing the entire layout every single time, we cache some
34 // information to break early when nothing changed
35 uint32_t generationCount = 0;
36 YGDirection lastOwnerDirection = YGDirectionInherit;
37
38 uint32_t nextCachedMeasurementsIndex = 0;
39 std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
40 cachedMeasurements = {};
41 std::array<float, 2> measuredDimensions = {._M_elems: {YGUndefined, YGUndefined}};
42
43 YGCachedMeasurement cachedLayout = YGCachedMeasurement();
44
45 YGDirection direction() const {
46 return facebook::yoga::detail::getEnumData<YGDirection>(
47 flags, index: directionOffset);
48 }
49
50 void setDirection(YGDirection direction) {
51 facebook::yoga::detail::setEnumData<YGDirection>(
52 flags, index: directionOffset, newValue: direction);
53 }
54
55 bool hadOverflow() const {
56 return facebook::yoga::detail::getBooleanData(flags, index: hadOverflowOffset);
57 }
58 void setHadOverflow(bool hadOverflow) {
59 facebook::yoga::detail::setBooleanData(
60 flags, index: hadOverflowOffset, value: hadOverflow);
61 }
62
63 bool operator==(YGLayout layout) const;
64 bool operator!=(YGLayout layout) const { return !(*this == layout); }
65};
66
67QT_YOGA_NAMESPACE_END
68

source code of qtdeclarative/src/3rdparty/yoga/YGLayout.h