.h
#include “CoreMinimal.h”
#include “Components/NativeWidgetHost.h”
#include “ColorPickerTest.generated.h”
class SColorPicker;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FColorPickerColorChangedDelegate, const FLinearColor&, new_color);
UCLASS()
class MULTIUSERVIEWER2_API UColorPickerTest : public UNativeWidgetHost
{
GENERATED_BODY()
public:
UColorPickerTest(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "custom_UMG")
void SetInitialColor(const FLinearColor initial_color);
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FLinearColor selected_color_rgb_;
UPROPERTY(BlueprintAssignable, Category = "custom_UMG")
FColorPickerColorChangedDelegate ColorPickerColorChangedDelegate;
private:
TSharedPtr<SColorPicker> color_picker_;
void GenerateColorPicker(const FLinearColor& initial_color);
};
.cpp
#include “ColorPickerTest.h”
#include "Runtime/AppFramework/Public/Widgets/Colors/SColorPicker.h"
#include "Kismet/KismetMathLibrary.h"
UColorPickerTest::UColorPickerTest(const FObjectInitializer& ObjectInitializer) : UNativeWidgetHost(ObjectInitializer), selected_color_rgb_(FLinearColor::White)
{
GenerateColorPicker(selected_color_rgb_);
}
void UColorPickerTest::SetInitialColor(const FLinearColor initial_color)
{
GenerateColorPicker(initial_color);
//color_picker_->SetColorRGB(initial_color);
}
void UColorPickerTest::GenerateColorPicker(const FLinearColor& initial_color)
{
Super::ReleaseSlateResources(/*bReleaseChildren = */true);
if (color_picker_.IsValid())
{
color_picker_.Reset();
}
selected_color_rgb_ = initial_color;
SAssignNew(color_picker_, SColorPicker)
.TargetColorAttribute(selected_color_rgb_)
.OnColorCommitted_Lambda([this](FLinearColor changed_color)
{
selected_color_rgb_ = changed_color;
if (ColorPickerColorChangedDelegate.IsBound())
{
ColorPickerColorChangedDelegate.Broadcast(changed_color);
}
})
.ExpandAdvancedSection(true)
.UseAlpha(false)
.sRGBOverride(true);
SetContent(color_picker_.ToSharedRef());
}
packing error: Stack for UTA.