96541a575eeb20cecb2cbd9e267a95244e4ad2c9
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / third-party / yoga / YGNode.h
1 /**
2  * Copyright (c) 2014-present, Facebook, Inc.
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 #include <stdio.h>
10 #include "YGConfig.h"
11 #include "YGLayout.h"
12 #include "YGStyle.h"
13 #include "Yoga-internal.h"
14
15 struct YGNode {
16  private:
17   void* context_;
18   YGPrintFunc print_;
19   bool hasNewLayout_;
20   YGNodeType nodeType_;
21   YGMeasureFunc measure_;
22   YGBaselineFunc baseline_;
23   YGDirtiedFunc dirtied_;
24   YGStyle style_;
25   YGLayout layout_;
26   uint32_t lineIndex_;
27   YGNodeRef owner_;
28   YGVector children_;
29   YGNodeRef nextChild_;
30   YGConfigRef config_;
31   bool isDirty_;
32   std::array<YGValue, 2> resolvedDimensions_;
33
34   YGFloatOptional relativePosition(
35       const YGFlexDirection& axis,
36       const float& axisSize) const;
37
38  public:
39   YGNode();
40   ~YGNode();
41   explicit YGNode(const YGConfigRef newConfig);
42   YGNode(const YGNode& node);
43   YGNode& operator=(const YGNode& node);
44   YGNode(
45       void* context,
46       YGPrintFunc print,
47       bool hasNewLayout,
48       YGNodeType nodeType,
49       YGMeasureFunc measure,
50       YGBaselineFunc baseline,
51       YGDirtiedFunc dirtied,
52       YGStyle style,
53       const YGLayout& layout,
54       uint32_t lineIndex,
55       YGNodeRef owner,
56       const YGVector& children,
57       YGNodeRef nextChild,
58       YGConfigRef config,
59       bool isDirty,
60       std::array<YGValue, 2> resolvedDimensions);
61
62   // Getters
63   void* getContext() const;
64   YGPrintFunc getPrintFunc() const;
65   bool getHasNewLayout() const;
66   YGNodeType getNodeType() const;
67   YGMeasureFunc getMeasure() const;
68   YGBaselineFunc getBaseline() const;
69   YGDirtiedFunc getDirtied() const;
70   // For Performance reasons passing as reference.
71   YGStyle& getStyle();
72   // For Performance reasons passing as reference.
73   YGLayout& getLayout();
74   uint32_t getLineIndex() const;
75   // returns the YGNodeRef that owns this YGNode. An owner is used to identify
76   // the YogaTree that a YGNode belongs to.
77   // This method will return the parent of the YGNode when a YGNode only belongs
78   // to one YogaTree or nullptr when the YGNode is shared between two or more
79   // YogaTrees.
80   YGNodeRef getOwner() const;
81   YGVector getChildren() const;
82   uint32_t getChildrenCount() const;
83   YGNodeRef getChild(uint32_t index) const;
84   YGNodeRef getNextChild() const;
85   YGConfigRef getConfig() const;
86   bool isDirty() const;
87   std::array<YGValue, 2> getResolvedDimensions() const;
88   YGValue getResolvedDimension(int index);
89
90   // Methods related to positions, margin, padding and border
91   YGFloatOptional getLeadingPosition(const YGFlexDirection& axis,
92       const float& axisSize) const;
93   bool isLeadingPositionDefined(const YGFlexDirection& axis) const;
94   bool isTrailingPosDefined(const YGFlexDirection& axis) const;
95   YGFloatOptional getTrailingPosition(
96       const YGFlexDirection& axis,
97       const float& axisSize) const;
98   YGFloatOptional getLeadingMargin(
99       const YGFlexDirection& axis,
100       const float& widthSize) const;
101   YGFloatOptional getTrailingMargin(
102       const YGFlexDirection& axis,
103       const float& widthSize) const;
104   float getLeadingBorder(const YGFlexDirection& flexDirection) const;
105   float getTrailingBorder(const YGFlexDirection& flexDirection) const;
106   YGFloatOptional getLeadingPadding(
107       const YGFlexDirection& axis,
108       const float& widthSize) const;
109   YGFloatOptional getTrailingPadding(
110       const YGFlexDirection& axis,
111       const float& widthSize) const;
112   YGFloatOptional getLeadingPaddingAndBorder(
113       const YGFlexDirection& axis,
114       const float& widthSize) const;
115   YGFloatOptional getTrailingPaddingAndBorder(
116       const YGFlexDirection& axis,
117       const float& widthSize) const;
118   YGFloatOptional getMarginForAxis(
119       const YGFlexDirection& axis,
120       const float& widthSize) const;
121   // Setters
122
123   void setContext(void* context);
124   void setPrintFunc(YGPrintFunc printFunc);
125   void setHasNewLayout(bool hasNewLayout);
126   void setNodeType(YGNodeType nodeTye);
127   void setMeasureFunc(YGMeasureFunc measureFunc);
128   void setBaseLineFunc(YGBaselineFunc baseLineFunc);
129   void setDirtiedFunc(YGDirtiedFunc dirtiedFunc);
130   void setStyle(const YGStyle& style);
131   void setStyleFlexDirection(YGFlexDirection direction);
132   void setStyleAlignContent(YGAlign alignContent);
133   void setLayout(const YGLayout& layout);
134   void setLineIndex(uint32_t lineIndex);
135   void setOwner(YGNodeRef owner);
136   void setChildren(const YGVector& children);
137   void setNextChild(YGNodeRef nextChild);
138   void setConfig(YGConfigRef config);
139   void setDirty(bool isDirty);
140   void setLayoutLastOwnerDirection(YGDirection direction);
141   void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis);
142   void setLayoutComputedFlexBasisGeneration(
143       uint32_t computedFlexBasisGeneration);
144   void setLayoutMeasuredDimension(float measuredDimension, int index);
145   void setLayoutHadOverflow(bool hadOverflow);
146   void setLayoutDimension(float dimension, int index);
147   void setLayoutDirection(YGDirection direction);
148   void setLayoutMargin(float margin, int index);
149   void setLayoutBorder(float border, int index);
150   void setLayoutPadding(float padding, int index);
151   void setLayoutPosition(float position, int index);
152   void setPosition(
153       const YGDirection direction,
154       const float mainSize,
155       const float crossSize,
156       const float ownerWidth);
157   void setAndPropogateUseLegacyFlag(bool useLegacyFlag);
158   void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
159   void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
160   void markDirtyAndPropogateDownwards();
161
162   // Other methods
163   YGValue marginLeadingValue(const YGFlexDirection axis) const;
164   YGValue marginTrailingValue(const YGFlexDirection axis) const;
165   YGValue resolveFlexBasisPtr() const;
166   void resolveDimension();
167   YGDirection resolveDirection(const YGDirection ownerDirection);
168   void clearChildren();
169   /// Replaces the occurrences of oldChild with newChild
170   void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);
171   void replaceChild(YGNodeRef child, uint32_t index);
172   void insertChild(YGNodeRef child, uint32_t index);
173   /// Removes the first occurrence of child
174   bool removeChild(YGNodeRef child);
175   void removeChild(uint32_t index);
176
177   void cloneChildrenIfNeeded();
178   void markDirtyAndPropogate();
179   float resolveFlexGrow();
180   float resolveFlexShrink();
181   bool isNodeFlexible();
182   bool didUseLegacyFlag();
183   bool isLayoutTreeEqualToNode(const YGNode& node) const;
184 };