Return the slot from InsertChildWidgetAt

This commit is contained in:
Steve Streeting 2024-01-02 17:57:41 +00:00
parent e8aec1fd24
commit 0ccd90cdd8
4 changed files with 11 additions and 7 deletions

View File

@ -11,9 +11,9 @@ void UStevesBPL::SetWidgetFocus(UWidget* Widget)
SetWidgetFocusProperly(Widget); SetWidgetFocusProperly(Widget);
} }
void UStevesBPL::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex) UPanelSlot* UStevesBPL::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex)
{ {
StevesUiHelpers::InsertChildWidgetAt(Parent, Child, AtIndex); return StevesUiHelpers::InsertChildWidgetAt(Parent, Child, AtIndex);
} }
FStevesBalancedRandomStream UStevesBPL::MakeBalancedRandomStream(int64 Seed) FStevesBalancedRandomStream UStevesBPL::MakeBalancedRandomStream(int64 Seed)

View File

@ -6,6 +6,7 @@
#include "StevesBalancedRandomStream.h" #include "StevesBalancedRandomStream.h"
#include "StevesMathHelpers.h" #include "StevesMathHelpers.h"
#include "Components/PanelSlot.h"
#include "StevesBPL.generated.h" #include "StevesBPL.generated.h"
class UPanelWidget; class UPanelWidget;
@ -51,9 +52,10 @@ public:
* @param Parent The container widget * @param Parent The container widget
* @param Child The child widget to add * @param Child The child widget to add
* @param AtIndex The index at which the new child should exist * @param AtIndex The index at which the new child should exist
* @returns The slot the child was inserted at
*/ */
UFUNCTION(BlueprintCallable, Category="StevesUEHelpers|UI") UFUNCTION(BlueprintCallable, Category="StevesUEHelpers|UI")
static void InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex = 0); static UPanelSlot* InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex = 0);
UFUNCTION(BlueprintPure, Category="StevesUEHelpers|Random", meta=(NativeMakeFunc)) UFUNCTION(BlueprintPure, Category="StevesUEHelpers|Random", meta=(NativeMakeFunc))
static FStevesBalancedRandomStream MakeBalancedRandomStream(int64 Seed); static FStevesBalancedRandomStream MakeBalancedRandomStream(int64 Seed);

View File

@ -2,7 +2,7 @@
#include "Components/PanelWidget.h" #include "Components/PanelWidget.h"
void StevesUiHelpers::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex) UPanelSlot* StevesUiHelpers::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex)
{ {
checkf(AtIndex <= Parent->GetChildrenCount(), TEXT("Insertion index %d is greater than child count"), AtIndex); checkf(AtIndex <= Parent->GetChildrenCount(), TEXT("Insertion index %d is greater than child count"), AtIndex);
@ -10,7 +10,7 @@ void StevesUiHelpers::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child,
const int OrigCount = Parent->GetChildrenCount(); const int OrigCount = Parent->GetChildrenCount();
if (OrigCount == AtIndex) if (OrigCount == AtIndex)
{ {
Parent->AddChild(Child); return Parent->AddChild(Child);
} }
else else
{ {
@ -32,12 +32,13 @@ void StevesUiHelpers::InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child,
Parent->RemoveChildAt(i); Parent->RemoveChildAt(i);
} }
// insert item // insert item
Parent->AddChild(Child); auto Slot = Parent->AddChild(Child);
// add back previous, reverse order // add back previous, reverse order
for (int i = WidgetsToReplaceReversed.Num() - 1; i >= 0; --i) for (int i = WidgetsToReplaceReversed.Num() - 1; i >= 0; --i)
{ {
Parent->AddChild(WidgetsToReplaceReversed[i]); Parent->AddChild(WidgetsToReplaceReversed[i]);
} }
return Slot;
} }

View File

@ -12,6 +12,7 @@ public:
* @param Parent The container widget * @param Parent The container widget
* @param Child The child widget to add * @param Child The child widget to add
* @param AtIndex The index at which the new child should exist * @param AtIndex The index at which the new child should exist
* @returns The slot the child was inserted at
*/ */
static void InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex = 0); static UPanelSlot* InsertChildWidgetAt(UPanelWidget* Parent, UWidget* Child, int AtIndex = 0);
}; };