Hello
Is it possible to set step value for a slider? I have not found any method in 3.0alpha.
Thanks in advance.
Hello
Is it possible to set step value for a slider? I have not found any method in 3.0alpha.
Thanks in advance.
Found the solution in case anyone interested
In CControlSlider.h:
CC_SYNTHESIZE(float, _step, Step);
In CControlSlider.cpp:
ControlSlider::ControlSlider()
:
...
...
, _step(-1.0f)
void ControlSlider::setValue(float value)
{
// set new value with sentinel
if (value < _minimumValue)
{
value = _minimumValue;
}
if (value > _maximumValue)
{
value = _maximumValue;
}
if (_step > 0)
{
float mod = fmod(value, _step);
if (mod <= _step / 2)
{
value -= mod;
}
else if (mod > _step / 2)
{
value += _step - mod;
}
}
_value = value;
this->needsLayout();
this->sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
}
And use like this:
ControlSlider *cslider = ControlSlider::create(...);
cslider->setStep(100.0f);