Slider track draw from centre?


#1

Is there a way to make the slider track start drawing in the centre and draw to either the left or the right depending on what side of centre the slider knob is on?

I’m already doing a custom look and feel, so I could do it in there, but I’d like to avoid doing another subclass of my look and feel. Is there anywhere I can hide a draw from centre flag in the slider?


#2

If for now you have the same code as the one in LookAndFeelV3, the line you want to change is :

filledArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, angle, thickness);

you just have do draw from the center instead of rotaryStartAngle. something like :

const float centerAngle = rotaryStartAngle + 0.5f * (rotaryEndAngle - rotaryStartAngle);
Path filledArc;
filledArc.addPieSegment (rx, ry, rw, rw, centerAngle, angle, thickness);
g.fillPath (filledArc);

I’d like to avoid doing another subclass of my look and feel. Is there anywhere I can hide a draw from centre flag in the slider?

That would mean subclassing the slider. you better subclass your lnf then I think.

Otherwise, if you want to do it just for a single slider or so, and don’t mind being a bit hacky you could still just check its name.

Another thing you could also consider (but that’s a particular behaviour) is setting the DoubleClickReturnValue of your sliders, and then drawing from there :

const double dbclkVal = slider.getDoubleClickReturnValue();
const float dbclkValPos = (float) slider.valueToProportionOfLength (dbclkVal);
const float dbclkValAngle = rotaryStartAngle + dbclkValPos * (rotaryEndAngle - rotaryStartAngle);
Path filledArc;
filledArc.addPieSegment (rx, ry, rw, rw, dbclkValAngle, angle, thickness);
g.fillPath (filledArc);

#3

Or you can do something like:

bool isMidPointSlider{false};

if (auto s = dynamic_cast<MySpecialSlider *>(&slider))
  isMidPointSlider = s->isMidPointSlider();  

Which might be one up from changing the name, though you’d need a subclass of slider with an isMidPointSlider() function …


#4

You can also set a property of the Component of you just need a flag. E.g. Component::getProperties()


#5

You can also set a property of the Component of you just need a flag. E.g. Component::getProperties()

This is what I want, thx for idea.