Hi,
I have a slate ui app in which I create a custom slider with SSlider, named MySlider.
In this class, I create a function to get the SSlider value when it changes. Then, in another class, BlockSliders, where I use MySlider, I want to do
SNew(MySlider)
.OnMySliderValueChanged(valueChanged)
But I can’t figure out what to add in my class MySlider. By looking in SSlider.cpp and .h files, I tried the following :
- in MySlider.h
public:
SLATE_BEGIN_ARGS(SMySlider)
{}
//EVENTS
/** Called when the value is changed by the slider. */
SLATE_EVENT(FOnFloatValueChanged, OnMySliderValueChanged)
SLATE_END_ARGS()
void Construct(const FArguments& args);
float sliderValue;
//When a slider's value changes
void SliderValueChanged(float inValue);
private:
// Holds the slider's current value.
TAttribute<float> ValueAttribute;
// Holds a delegate that is executed when the slider's value changed.
FOnFloatValueChanged OnMySliderValueChanged;
};
- in MySlider.cpp
void SMySlider::Construct(const FArguments& args)
{
FOnFloatValueChanged onSliderChange;
onSliderChange.BindLambda([this](float value) { SliderValueChanged(value); });
...
SNew(SSlider)
.OnValueChanged(onSliderChange)
...
}
void SMySlider::SliderValueChanged(float inValue)
{
if (GEngine)
{
if (!ValueAttribute.IsBound())
{
ValueAttribute.Set(inValue);
}
bool b=OnMySliderValueChanged.ExecuteIfBound(inValue);
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Yellow, TEXT("SliderValueChanged ")); //this text is correctly displayed
std::cout << "b " << b << std::endl; //b is always false
}
}
In the file BlockSliders.h :
public
...
float sliderValue;
//When a slider's value changes
void SliderValueChanged(float inValue);
...
In the file BlockSliders.cpp :
void SBlockSliders::Construct(const FArguments& args)
{
...
FOnFloatValueChanged onSliderChange;
onSliderChange.BindLambda([this](float value) { SliderValueChanged(value); });
...
SNew(SMySlider)
.OnMySliderValueChanged(onSliderChange)
...
}
void SMySlidersBlock::SliderValueChanged(float inValue)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Yellow, TEXT("BlockSlidersValueChanged ")); //never displayed
}
}
So what is wrong in my code please? How to know that MySlider’s value has changed in BlockSliders?
Thanks.