| 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 | |
| 25 | QT_YOGA_NAMESPACE_BEGIN |
| 26 | |
| 27 | YG_EXTERN_C_BEGIN |
| 28 | |
| 29 | struct YGConfig; |
| 30 | struct YGNode; |
| 31 | class YGStyle; |
| 32 | |
| 33 | typedef struct YGSize { |
| 34 | float width; |
| 35 | float height; |
| 36 | } YGSize; |
| 37 | |
| 38 | typedef struct YGConfig* YGConfigRef; |
| 39 | |
| 40 | typedef struct YGNode* YGNodeRef; |
| 41 | typedef const struct YGNode* YGNodeConstRef; |
| 42 | |
| 43 | typedef YGSize (*YGMeasureFunc)( |
| 44 | YGNodeRef node, |
| 45 | float width, |
| 46 | YGMeasureMode widthMode, |
| 47 | float height, |
| 48 | YGMeasureMode heightMode); |
| 49 | typedef float (*YGBaselineFunc)(YGNodeRef node, float width, float height); |
| 50 | typedef void (*YGDirtiedFunc)(YGNodeRef node); |
| 51 | typedef void (*YGPrintFunc)(YGNodeRef node); |
| 52 | typedef void (*YGNodeCleanupFunc)(YGNodeRef node); |
| 53 | typedef int (*YGLogger)( |
| 54 | YGConfigRef config, |
| 55 | YGNodeRef node, |
| 56 | YGLogLevel level, |
| 57 | const char* format, |
| 58 | va_list args); |
| 59 | typedef YGNodeRef ( |
| 60 | *YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex); |
| 61 | |
| 62 | // YGNode |
| 63 | WIN_EXPORT YGNodeRef YGNodeNew(void); |
| 64 | WIN_EXPORT YGNodeRef YGNodeNewWithConfig(YGConfigRef config); |
| 65 | WIN_EXPORT YGNodeRef YGNodeClone(YGNodeRef node); |
| 66 | WIN_EXPORT void YGNodeFree(YGNodeRef node); |
| 67 | WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( |
| 68 | YGNodeRef node, |
| 69 | YGNodeCleanupFunc cleanup); |
| 70 | WIN_EXPORT void YGNodeFreeRecursive(YGNodeRef node); |
| 71 | WIN_EXPORT void YGNodeReset(YGNodeRef node); |
| 72 | |
| 73 | WIN_EXPORT void YGNodeInsertChild( |
| 74 | YGNodeRef node, |
| 75 | YGNodeRef child, |
| 76 | uint32_t index); |
| 77 | |
| 78 | WIN_EXPORT void YGNodeSwapChild( |
| 79 | YGNodeRef node, |
| 80 | YGNodeRef child, |
| 81 | uint32_t index); |
| 82 | |
| 83 | WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); |
| 84 | WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); |
| 85 | WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); |
| 86 | WIN_EXPORT YGNodeRef YGNodeGetOwner(YGNodeRef node); |
| 87 | WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); |
| 88 | WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node); |
| 89 | WIN_EXPORT void YGNodeSetChildren( |
| 90 | YGNodeRef owner, |
| 91 | const YGNodeRef* children, |
| 92 | uint32_t count); |
| 93 | |
| 94 | WIN_EXPORT void YGNodeSetIsReferenceBaseline( |
| 95 | YGNodeRef node, |
| 96 | bool isReferenceBaseline); |
| 97 | |
| 98 | WIN_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node); |
| 99 | |
| 100 | WIN_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. |
| 112 | WIN_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. |
| 118 | WIN_EXPORT void YGNodeMarkDirtyAndPropagateToDescendants(YGNodeRef node); |
| 119 | |
| 120 | WIN_EXPORT void YGNodePrint(YGNodeRef node, YGPrintOptions options); |
| 121 | |
| 122 | WIN_EXPORT bool YGFloatIsUndefined(float value); |
| 123 | |
| 124 | WIN_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 | |
| 139 | WIN_EXPORT void YGNodeCopyStyle(YGNodeRef dstNode, YGNodeRef srcNode); |
| 140 | |
| 141 | WIN_EXPORT void* YGNodeGetContext(YGNodeRef node); |
| 142 | WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context); |
| 143 | |
| 144 | WIN_EXPORT YGConfigRef YGNodeGetConfig(YGNodeRef node); |
| 145 | WIN_EXPORT void YGNodeSetConfig(YGNodeRef node, YGConfigRef config); |
| 146 | |
| 147 | void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled); |
| 148 | bool YGNodeHasMeasureFunc(YGNodeRef node); |
| 149 | WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc); |
| 150 | bool YGNodeHasBaselineFunc(YGNodeRef node); |
| 151 | void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc); |
| 152 | YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node); |
| 153 | void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc); |
| 154 | void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc); |
| 155 | WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node); |
| 156 | WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout); |
| 157 | YGNodeType YGNodeGetNodeType(YGNodeRef node); |
| 158 | void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType); |
| 159 | WIN_EXPORT bool YGNodeIsDirty(YGNodeRef node); |
| 160 | |
| 161 | WIN_EXPORT void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction); |
| 162 | WIN_EXPORT YGDirection YGNodeStyleGetDirection(YGNodeConstRef node); |
| 163 | |
| 164 | WIN_EXPORT void YGNodeStyleSetFlexDirection( |
| 165 | YGNodeRef node, |
| 166 | YGFlexDirection flexDirection); |
| 167 | WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeConstRef node); |
| 168 | |
| 169 | WIN_EXPORT void YGNodeStyleSetJustifyContent( |
| 170 | YGNodeRef node, |
| 171 | YGJustify justifyContent); |
| 172 | WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(YGNodeConstRef node); |
| 173 | |
| 174 | WIN_EXPORT void YGNodeStyleSetAlignContent( |
| 175 | YGNodeRef node, |
| 176 | YGAlign alignContent); |
| 177 | WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(YGNodeConstRef node); |
| 178 | |
| 179 | WIN_EXPORT void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems); |
| 180 | WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(YGNodeConstRef node); |
| 181 | |
| 182 | WIN_EXPORT void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf); |
| 183 | WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(YGNodeConstRef node); |
| 184 | |
| 185 | WIN_EXPORT void YGNodeStyleSetPositionType( |
| 186 | YGNodeRef node, |
| 187 | YGPositionType positionType); |
| 188 | WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(YGNodeConstRef node); |
| 189 | |
| 190 | WIN_EXPORT void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap); |
| 191 | WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(YGNodeConstRef node); |
| 192 | |
| 193 | WIN_EXPORT void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow); |
| 194 | WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(YGNodeConstRef node); |
| 195 | |
| 196 | WIN_EXPORT void YGNodeStyleSetDisplay(YGNodeRef node, YGDisplay display); |
| 197 | WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(YGNodeConstRef node); |
| 198 | |
| 199 | WIN_EXPORT void YGNodeStyleSetFlex(YGNodeRef node, float flex); |
| 200 | WIN_EXPORT float YGNodeStyleGetFlex(YGNodeConstRef node); |
| 201 | |
| 202 | WIN_EXPORT void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow); |
| 203 | WIN_EXPORT float YGNodeStyleGetFlexGrow(YGNodeConstRef node); |
| 204 | |
| 205 | WIN_EXPORT void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink); |
| 206 | WIN_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node); |
| 207 | |
| 208 | WIN_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis); |
| 209 | WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis); |
| 210 | WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node); |
| 211 | WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node); |
| 212 | |
| 213 | WIN_EXPORT void YGNodeStyleSetPosition( |
| 214 | YGNodeRef node, |
| 215 | YGEdge edge, |
| 216 | float position); |
| 217 | WIN_EXPORT void YGNodeStyleSetPositionPercent( |
| 218 | YGNodeRef node, |
| 219 | YGEdge edge, |
| 220 | float position); |
| 221 | WIN_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge); |
| 222 | |
| 223 | WIN_EXPORT void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin); |
| 224 | WIN_EXPORT void YGNodeStyleSetMarginPercent( |
| 225 | YGNodeRef node, |
| 226 | YGEdge edge, |
| 227 | float margin); |
| 228 | WIN_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge); |
| 229 | WIN_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge); |
| 230 | |
| 231 | WIN_EXPORT void YGNodeStyleSetPadding( |
| 232 | YGNodeRef node, |
| 233 | YGEdge edge, |
| 234 | float padding); |
| 235 | WIN_EXPORT void YGNodeStyleSetPaddingPercent( |
| 236 | YGNodeRef node, |
| 237 | YGEdge edge, |
| 238 | float padding); |
| 239 | WIN_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge); |
| 240 | |
| 241 | WIN_EXPORT void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border); |
| 242 | WIN_EXPORT float YGNodeStyleGetBorder(YGNodeConstRef node, YGEdge edge); |
| 243 | |
| 244 | WIN_EXPORT void YGNodeStyleSetGap( |
| 245 | YGNodeRef node, |
| 246 | YGGutter gutter, |
| 247 | float gapLength); |
| 248 | WIN_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); |
| 249 | |
| 250 | WIN_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width); |
| 251 | WIN_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width); |
| 252 | WIN_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node); |
| 253 | WIN_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node); |
| 254 | |
| 255 | WIN_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height); |
| 256 | WIN_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height); |
| 257 | WIN_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node); |
| 258 | WIN_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node); |
| 259 | |
| 260 | WIN_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth); |
| 261 | WIN_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth); |
| 262 | WIN_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node); |
| 263 | |
| 264 | WIN_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight); |
| 265 | WIN_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight); |
| 266 | WIN_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node); |
| 267 | |
| 268 | WIN_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth); |
| 269 | WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth); |
| 270 | WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node); |
| 271 | |
| 272 | WIN_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight); |
| 273 | WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight); |
| 274 | WIN_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 |
| 291 | WIN_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio); |
| 292 | WIN_EXPORT float YGNodeStyleGetAspectRatio(YGNodeConstRef node); |
| 293 | |
| 294 | WIN_EXPORT float YGNodeLayoutGetLeft(YGNodeRef node); |
| 295 | WIN_EXPORT float YGNodeLayoutGetTop(YGNodeRef node); |
| 296 | WIN_EXPORT float YGNodeLayoutGetRight(YGNodeRef node); |
| 297 | WIN_EXPORT float YGNodeLayoutGetBottom(YGNodeRef node); |
| 298 | WIN_EXPORT float YGNodeLayoutGetWidth(YGNodeRef node); |
| 299 | WIN_EXPORT float YGNodeLayoutGetHeight(YGNodeRef node); |
| 300 | WIN_EXPORT YGDirection YGNodeLayoutGetDirection(YGNodeRef node); |
| 301 | WIN_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. |
| 307 | WIN_EXPORT float YGNodeLayoutGetMargin(YGNodeRef node, YGEdge edge); |
| 308 | WIN_EXPORT float YGNodeLayoutGetBorder(YGNodeRef node, YGEdge edge); |
| 309 | WIN_EXPORT float YGNodeLayoutGetPadding(YGNodeRef node, YGEdge edge); |
| 310 | |
| 311 | WIN_EXPORT void YGConfigSetLogger(YGConfigRef config, YGLogger logger); |
| 312 | WIN_EXPORT void YGAssert(bool condition, const char* message); |
| 313 | WIN_EXPORT void YGAssertWithNode( |
| 314 | YGNodeRef node, |
| 315 | bool condition, |
| 316 | const char* message); |
| 317 | WIN_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 |
| 323 | WIN_EXPORT void YGConfigSetPointScaleFactor( |
| 324 | YGConfigRef config, |
| 325 | float pixelsInPoint); |
| 326 | WIN_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. |
| 333 | WIN_EXPORT YG_DEPRECATED( |
| 334 | "Please use " |
| 335 | "\"YGConfigGetErrata()\"" ) bool YGConfigGetUseLegacyStretchBehaviour(YGConfigRef |
| 336 | config); |
| 337 | WIN_EXPORT |
| 338 | YG_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\"." ) |
| 345 | void YGConfigSetUseLegacyStretchBehaviour( |
| 346 | YGConfigRef config, |
| 347 | bool useLegacyStretchBehaviour); |
| 348 | |
| 349 | // YGConfig |
| 350 | WIN_EXPORT YGConfigRef YGConfigNew(void); |
| 351 | WIN_EXPORT void YGConfigFree(YGConfigRef config); |
| 352 | WIN_EXPORT void YGConfigCopy(YGConfigRef dest, YGConfigRef src); |
| 353 | WIN_EXPORT int32_t YGConfigGetInstanceCount(void); |
| 354 | |
| 355 | WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled( |
| 356 | YGConfigRef config, |
| 357 | YGExperimentalFeature feature, |
| 358 | bool enabled); |
| 359 | WIN_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. |
| 365 | WIN_EXPORT void YGConfigSetUseWebDefaults(YGConfigRef config, bool enabled); |
| 366 | WIN_EXPORT bool YGConfigGetUseWebDefaults(YGConfigRef config); |
| 367 | |
| 368 | WIN_EXPORT void YGConfigSetCloneNodeFunc( |
| 369 | YGConfigRef config, |
| 370 | YGCloneNodeFunc callback); |
| 371 | |
| 372 | // Export only for C# |
| 373 | WIN_EXPORT YGConfigRef YGConfigGetDefault(void); |
| 374 | |
| 375 | WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); |
| 376 | WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); |
| 377 | |
| 378 | WIN_EXPORT void YGConfigSetErrata(YGConfigRef config, YGErrata errata); |
| 379 | WIN_EXPORT YGErrata YGConfigGetErrata(YGConfigRef config); |
| 380 | |
| 381 | WIN_EXPORT float YGRoundValueToPixelGrid( |
| 382 | double value, |
| 383 | double pointScaleFactor, |
| 384 | bool forceCeil, |
| 385 | bool forceFloor); |
| 386 | |
| 387 | YG_EXTERN_C_END |
| 388 | |
| 389 | QT_YOGA_NAMESPACE_END |
| 390 | |