I created the standalone window plugin and now I am trying to add a button to the tab. I am confused on how to use the OnClicked function correctly. I want change the color to green if the button color is currently red and vice versa. the following code is:
TSharedRef FTaskManagerModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(SButton).ButtonColorAndOpacity(FLinearColor(1.0f, 0.0f, 0.0f, 1.0f)).OnClicked(/*not sure what to do here*/)
]
];
}
I’m not knowledgeable enough to be certain, but I don’t think you can override the functions of a native class in realtime (perhaps with Lambdas, but I’m not familiar enough with using them to say for certain).
My 2 cents, would be to do the following:
Create your own child button Button
class.
Create an ENum for your desired
color selection.
Add a property to your custom button
class for the enum.
Override the OnClicked event for
your custom button.
Within the OnClicked event code, use
“switch” to determine the current
color selection and change the color
accordingly and update the current
selection value.
in your .cpp file within the overriden OnClicked Event…
switch (ButtonColor)
{
case EButtonColor::Red:
{
// Additional code to change the button's color value to green
ButtonColor = EButtonColor::Green;
}
break;
case EButtonColor::Green:
{
// Additional code to change the button's color value to red
ButtonColor = EButtonColor::Red;
}
break;
}
The above isn’t verbatim, but should get you rolling if applicable.