| 4446 | |
| 4447 | CLAY_WASM_EXPORT("Clay_EndLayout") |
| 4448 | Clay_RenderCommandArray Clay_EndLayout(float deltaTime) { |
| 4449 | Clay_Context* context = Clay_GetCurrentContext(); |
| 4450 | Clay__CloseElement(); |
| 4451 | |
| 4452 | if (context->openLayoutElementStack.length > 1) { |
| 4453 | context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) { |
| 4454 | .errorType = CLAY_ERROR_TYPE_UNBALANCED_OPEN_CLOSE, |
| 4455 | .errorText = CLAY_STRING("There were still open layout elements when EndLayout was called. This results from an unequal number of calls to Clay__OpenElement and Clay__CloseElement."), |
| 4456 | .userData = context->errorHandler.userData }); |
| 4457 | } |
| 4458 | |
| 4459 | for (int i = 0; i < context->transitionDatas.length; ++i) { |
| 4460 | Clay__TransitionDataInternal *data = Clay__TransitionDataInternalArray_Get(&context->transitionDatas, i); |
| 4461 | Clay_LayoutElementHashMapItem *hashMapItem = Clay__GetHashMapItem(data->elementId); |
| 4462 | // This might seems strange - can't we just look up the element itself, and check the config to see whether it has an exit transition defined? |
| 4463 | // That would work fine if the element actually had an exit transition in the first place. If it doesn't have an exit transition defined, the element |
| 4464 | // will have simply disappeared completely at this point, and there will be no element through which to access the config. |
| 4465 | if (data->transitionOut) { |
| 4466 | Clay_TransitionElementConfig* config = &data->elementThisFrame->config.transition; |
| 4467 | // Element wasn't found this frame - either delete transition data or transition out |
| 4468 | if (hashMapItem->generation <= context->generation) { |
| 4469 | Clay_LayoutElementHashMapItem *parentHashMapItem = Clay__GetHashMapItem(data->parentId); |
| 4470 | // Don't exit transition if the parent has also exited and SKIP_WHEN_PARENT_EXITS is used |
| 4471 | if (config->exit.trigger == CLAY_TRANSITION_EXIT_TRIGGER_WHEN_PARENT_EXITS || !parentHashMapItem || parentHashMapItem->generation > context->generation) { |
| 4472 | // This if only runs one single time when the element first starts exiting |
| 4473 | if (data->state != CLAY_TRANSITION_STATE_EXITING) { |
| 4474 | if (parentHashMapItem->generation <= context->generation) { |
| 4475 | data->elementThisFrame->config.floating.attachTo = CLAY_ATTACH_TO_ROOT; |
| 4476 | data->elementThisFrame->config.floating.offset = CLAY__INIT(Clay_Vector2) { hashMapItem->boundingBox.x, hashMapItem->boundingBox.y }; |
| 4477 | data->elementThisFrame->config.floating.parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0).id; |
| 4478 | } |
| 4479 | hashMapItem->appearedThisFrame = false; |
| 4480 | data->elementThisFrame->exiting = true; |
| 4481 | data->elementThisFrame->config.layout.sizing.width = CLAY_SIZING_FIXED(data->elementThisFrame->dimensions.width); |
| 4482 | data->elementThisFrame->config.layout.sizing.height = CLAY_SIZING_FIXED(data->elementThisFrame->dimensions.height); |
| 4483 | data->state = CLAY_TRANSITION_STATE_EXITING; |
| 4484 | data->activeProperties = config->properties; |
| 4485 | data->elapsedTime = 0; |
| 4486 | data->targetState = config->exit.setFinalState(data->targetState, config->properties); |
| 4487 | } |
| 4488 | |
| 4489 | // Below this line runs every frame while element is exiting ----------- |
| 4490 | |
| 4491 | // Clone the entire subtree back into the main UI layout tree |
| 4492 | Clay__int32_tArray bfsBuffer = context->openLayoutElementStack; |
| 4493 | bfsBuffer.length = 0; |
| 4494 | data->elementThisFrame = Clay_LayoutElementArray_Add(&context->layoutElements, *data->elementThisFrame); |
| 4495 | int32_t exitingElementIndex = data->elementThisFrame - context->layoutElements.internalArray; |
| 4496 | Clay__StringArray_Add(&context->layoutElementIdStrings, *Clay__StringArray_GetCheckCapacity(&context->layoutElementIdStrings, exitingElementIndex)); |
| 4497 | Clay__int32_tArray_Add(&context->layoutElementClipElementIds, *Clay__int32_tArray_GetCheckCapacity(&context->layoutElementClipElementIds, exitingElementIndex)); |
| 4498 | Clay__int32_tArray_Add(&bfsBuffer, exitingElementIndex); |
| 4499 | hashMapItem->layoutElement = data->elementThisFrame; |
| 4500 | hashMapItem->generation = context->generation + 1; |
| 4501 | int32_t bufferIndex = 0; |
| 4502 | while (bufferIndex < bfsBuffer.length) { |
| 4503 | Clay_LayoutElement *layoutElement = Clay_LayoutElementArray_GetCheckCapacity(&context->layoutElements, Clay__int32_tArray_GetValue(&bfsBuffer, bufferIndex)); |
| 4504 | bufferIndex++; |
| 4505 | int32_t firstChildSlot = context->layoutElementChildren.length; |
no test coverage detected