Last active
October 13, 2021 18:04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Framework/Application/SlateApplication.h" | |
#include "Layout/LayoutUtils.h" | |
#include "Layout/ArrangedChildren.h" | |
void ArrangeChildrenRecursive(FArrangedChildren& Childs, FArrangedWidget& ParentWidget) | |
{ | |
FArrangedChildren arrangedChilds (EVisibility::All); | |
ParentWidget.Widget->ArrangeChildren(ParentWidget.Geometry, arrangedChilds); | |
Childs.Append(arrangedChilds); // add arranged children to array | |
for (auto& arrangedChild: arrangedChilds.GetInternalArray()) | |
{ | |
ArrangeChildrenRecursive(Childs, arrangedChild); // walk through recursively | |
} | |
} | |
FVector2D UMyWidget::GetWidgetSize() | |
{ | |
FVector2D DesiredWidgetSize; | |
FArrangedChildren Childs(EVisibility::All); | |
auto thisWidget = TakeWidget(); | |
auto parent = GetCachedWidget()->GetParentWidget(); | |
// search for first parent with valid geometry | |
while (parent.IsValid() && parent->GetCachedGeometry().Size.SizeSquared()==0) | |
{ | |
parent = parent->GetParentWidget(); | |
} | |
// calculate size for all children down form found parent | |
FArrangedWidget parentArrangedWidget(parent.ToSharedRef(), parent->GetCachedGeometry()); | |
ArrangeChildrenRecursive(Childs, parentArrangedWidget); | |
// search for desired widget (thisWidget) | |
for (auto& child: Childs.GetInternalArray()) | |
{ | |
if (child.Widget == thisWidget) | |
{ | |
// desired size found | |
DesiredWidgetSize = child.Geometry.Size; | |
break; | |
} | |
} | |
return DesiredWidgetSize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment