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 <assert.h>
11#include <math.h>
12#include <stdarg.h>
13#include <stdint.h>
14#include <stdio.h>
15#include <stdlib.h>
16
17#ifndef __cplusplus
18#include <stdbool.h>
19#endif
20
21#include <yoga/YGEnums.h>
22#include <yoga/YGMacros.h>
23#include <yoga/YGValue.h>
24
25QT_YOGA_NAMESPACE_BEGIN
26
27YG_EXTERN_C_BEGIN
28
29struct YGConfig;
30struct YGNode;
31class YGStyle;
32
33typedef struct YGSize {
34 float width;
35 float height;
36} YGSize;
37
38typedef struct YGConfig* YGConfigRef;
39
40typedef struct YGNode* YGNodeRef;
41typedef const struct YGNode* YGNodeConstRef;
42
43typedef YGSize (*YGMeasureFunc)(
44 YGNodeRef node,
45 float width,
46 YGMeasureMode widthMode,
47 float height,
48 YGMeasureMode heightMode);
49typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height);
50typedef void (*YGDirtiedFunc)(YGNodeRef node);
51typedef void (*YGPrintFunc)(YGNodeRef node);
52typedef void (*YGNodeCleanupFunc)(YGNodeRef node);
53typedef int (*YGLogger)(
54 YGConfigRef config,
55 YGNodeRef node,
56 YGLogLevel level,
57 const char* format,
58 va_list args);
59typedef YGNodeRef (
60 *YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
61
62// YGNode
63WIN_EXPORT YGNodeRef YGNodeNew(void);
64WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config);
65WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node);
66WIN_EXPORT void YGNodeFree(YGNodeRef node);
67WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
68 YGNodeRef node,
69 YGNodeCleanupFunc cleanup);
70WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node);
71WIN_EXPORT void YGNodeReset(YGNodeRef node);
72
73WIN_EXPORT void YGNodeInsertChild(
74 YGNodeRef node,
75 YGNodeRef child,
76 uint32_t index);
77
78WIN_EXPORT void YGNodeSwapChild(
79 YGNodeRef node,
80 YGNodeRef child,
81 uint32_t index);
82
83WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
84WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node);
85WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
86WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node);
87WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
88WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node);
89WIN_EXPORT void YGNodeSetChildren(
90 YGNodeRef owner,
91 const YGNodeRef* children,
92 uint32_t count);
93
94WIN_EXPORT void YGNodeSetIsReferenceBaseline(
95 YGNodeRef node,
96 bool isReferenceBaseline);
97
98WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node);
99
100WIN_EXPORT void YGNodeCalculateLayout(
101 YGNodeRef node,
102 float availableWidth,
103 float availableHeight,
104 YGDirection ownerDirection);
105
106// Mark a node as dirty. Only valid for nodes with a custom measure function
107// set.
108//
109// Yoga knows when to mark all other nodes as dirty but because nodes with
110// measure functions depend on information not known to Yoga they must perform
111// this dirty marking manually.
112WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node);
113
114// Marks the current node and all its descendants as dirty.
115//
116// Intended to be used for Yoga benchmarks. Don't use in production, as calling
117// `YGCalculateLayout` will cause the recalculation of each and every node.
118WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node);
119
120WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options);
121
122WIN_EXPORT bool YGFloatIsUndefined(float value);
123
124WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
125 YGMeasureMode widthMode,
126 float width,
127 YGMeasureMode heightMode,
128 float height,
129 YGMeasureMode lastWidthMode,
130 float lastWidth,
131 YGMeasureMode lastHeightMode,
132 float lastHeight,
133 float lastComputedWidth,
134 float lastComputedHeight,
135 float marginRow,
136 float marginColumn,
137 YGConfigRef config);
138
139WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode);
140
141WIN_EXPORT void* YGNodeGetContext(YGNodeRef node);
142WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
143
144WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node);
145WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config);
146
147void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
148bool YGNodeHasMeasureFunc(YGNodeRef node);
149WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
150bool YGNodeHasBaselineFunc(YGNodeRef node);
151void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
152YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node);
153void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
154void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
155WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node);
156WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
157YGNodeType YGNodeGetNodeType(YGNodeRef node);
158void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
159WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node);
160
161WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
162WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node);
163
164WIN_EXPORT void YGNodeStyleSetFlexDirection(
165 YGNodeRef node,
166 YGFlexDirection flexDirection);
167WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node);
168
169WIN_EXPORT void YGNodeStyleSetJustifyContent(
170 YGNodeRef node,
171 YGJustify justifyContent);
172WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node);
173
174WIN_EXPORT void YGNodeStyleSetAlignContent(
175 YGNodeRef node,
176 YGAlign alignContent);
177WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node);
178
179WIN_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems);
180WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node);
181
182WIN_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf);
183WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node);
184
185WIN_EXPORT void YGNodeStyleSetPositionType(
186 YGNodeRef node,
187 YGPositionType positionType);
188WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node);
189
190WIN_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap);
191WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(YGNodeConstRef node);
192
193WIN_EXPORT void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow);
194WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(YGNodeConstRef node);
195
196WIN_EXPORT void YGNodeStyleSetDisplay(YGNodeRef node, YGDisplay display);
197WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(YGNodeConstRef node);
198
199WIN_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, float flex);
200WIN_EXPORT float YGNodeStyleGetFlex(YGNodeConstRef node);
201
202WIN_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow);
203WIN_EXPORT float YGNodeStyleGetFlexGrow(YGNodeConstRef node);
204
205WIN_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink);
206WIN_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node);
207
208WIN_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis);
209WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis);
210WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node);
211WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node);
212
213WIN_EXPORT void YGNodeStyleSetPosition(
214 YGNodeRef node,
215 YGEdge edge,
216 float position);
217WIN_EXPORT void YGNodeStyleSetPositionPercent(
218 YGNodeRef node,
219 YGEdge edge,
220 float position);
221WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge);
222
223WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin);
224WIN_EXPORT void YGNodeStyleSetMarginPercent(
225 YGNodeRef node,
226 YGEdge edge,
227 float margin);
228WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge);
229WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge);
230
231WIN_EXPORT void YGNodeStyleSetPadding(
232 YGNodeRef node,
233 YGEdge edge,
234 float padding);
235WIN_EXPORT void YGNodeStyleSetPaddingPercent(
236 YGNodeRef node,
237 YGEdge edge,
238 float padding);
239WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge);
240
241WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border);
242WIN_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge);
243
244WIN_EXPORT void YGNodeStyleSetGap(
245 YGNodeRef node,
246 YGGutter gutter,
247 float gapLength);
248WIN_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter);
249
250WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width);
251WIN_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width);
252WIN_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node);
253WIN_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node);
254
255WIN_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height);
256WIN_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height);
257WIN_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node);
258WIN_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node);
259
260WIN_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth);
261WIN_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth);
262WIN_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node);
263
264WIN_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight);
265WIN_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight);
266WIN_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node);
267
268WIN_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth);
269WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth);
270WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node);
271
272WIN_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight);
273WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight);
274WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);
275
276// Yoga specific properties, not compatible with flexbox specification Aspect
277// ratio control the size of the undefined dimension of a node. Aspect ratio is
278// encoded as a floating point value width/height. e.g. A value of 2 leads to a
279// node with a width twice the size of its height while a value of 0.5 gives the
280// opposite effect.
281//
282// - On a node with a set width/height aspect ratio control the size of the
283// unset dimension
284// - On a node with a set flex basis aspect ratio controls the size of the node
285// in the cross axis if unset
286// - On a node with a measure function aspect ratio works as though the measure
287// function measures the flex basis
288// - On a node with flex grow/shrink aspect ratio controls the size of the node
289// in the cross axis if unset
290// - Aspect ratio takes min/max dimensions into account
291WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
292WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node);
293
294WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node);
295WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node);
296WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node);
297WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node);
298WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node);
299WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node);
300WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
301WIN_EXPORT bool YGNodeLayoutGetHadOverflow(YGNodeRef node);
302
303// Get the computed values for these nodes after performing layout. If they were
304// set using point values then the returned value will be the same as
305// YGNodeStyleGetXXX. However if they were set using a percentage value then the
306// returned value is the computed value used during layout.
307WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge);
308WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge);
309WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge);
310
311WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger);
312WIN_EXPORT void YGAssert(bool condition, const char* message);
313WIN_EXPORT void YGAssertWithNode(
314 YGNodeRef node,
315 bool condition,
316 const char* message);
317WIN_EXPORT void YGAssertWithConfig(
318 YGConfigRef config,
319 bool condition,
320 const char* message);
321// Set this to number of pixels in 1 point to round calculation results If you
322// want to avoid rounding - set PointScaleFactor to 0
323WIN_EXPORT void YGConfigSetPointScaleFactor(
324 YGConfigRef config,
325 float pixelsInPoint);
326WIN_EXPORT float YGConfigGetPointScaleFactor(YGConfigRef config);
327
328// Yoga previously had an error where containers would take the maximum space
329// possible instead of the minimum like they are supposed to. In practice this
330// resulted in implicit behaviour similar to align-self: stretch; Because this
331// was such a long-standing bug we must allow legacy users to switch back to
332// this behaviour.
333WIN_EXPORT YG_DEPRECATED(
334 "Please use "
335 "\"YGConfigGetErrata()\"") bool YGConfigGetUseLegacyStretchBehaviour(YGConfigRef
336 config);
337WIN_EXPORT
338YG_DEPRECATED(
339 "\"YGConfigSetUseLegacyStretchBehaviour\" will be removed in the next "
340 "release. Usage should be replaced with \"YGConfigSetErrata(YGErrataAll)\" "
341 "to opt out of all future breaking conformance fixes, or "
342 "\"YGConfigSetErrata(YGErrataStretchFlexBasis)\" to opt out of the "
343 "specific conformance fix previously disabled by "
344 "\"UseLegacyStretchBehaviour\".")
345void YGConfigSetUseLegacyStretchBehaviour(
346 YGConfigRef config,
347 bool useLegacyStretchBehaviour);
348
349// YGConfig
350WIN_EXPORT YGConfigRef YGConfigNew(void);
351WIN_EXPORT void YGConfigFree(YGConfigRef config);
352WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src);
353WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
354
355WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
356 YGConfigRef config,
357 YGExperimentalFeature feature,
358 bool enabled);
359WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
360 YGConfigRef config,
361 YGExperimentalFeature feature);
362
363// Using the web defaults is the preferred configuration for new projects. Usage
364// of non web defaults should be considered as legacy.
365WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled);
366WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config);
367
368WIN_EXPORT void YGConfigSetCloneNodeFunc(
369 YGConfigRef config,
370 YGCloneNodeFunc callback);
371
372// Export only for C#
373WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
374
375WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
376WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
377
378WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata);
379WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config);
380
381WIN_EXPORT float YGRoundValueToPixelGrid(
382 double value,
383 double pointScaleFactor,
384 bool forceCeil,
385 bool forceFloor);
386
387YG_EXTERN_C_END
388
389QT_YOGA_NAMESPACE_END
390

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