I have a vertical slider with the included textbox placed above it. I need to get the bounding rectangle of the actual bar/slider portion of the slider. So far I have failed to find a good method of doing so. Can anyone provide some suggestions on how to do this?
This information must come from the LookAndFeel. Did you try the getSliderLayout() method?
auto layout = slider.getLookAndFeel().getSliderLayout(); // will draw a frame around the slider part without the textbox: g.drawRect (layout.sliderBounds, 1.0f);
For me its a slightly different syntax:
auto layout = getLookAndFeel().getSliderLayout(gainSlider);
This method gives the right size but not the right position. I’m using flex-box to layout my components and that seems to be make the positioning incorrect for some reason.
I can’t get flex-box to play nicely with the look and feel bounds, but I have come up with a simple enough workaround. Will try to simplify further later.
auto componentBounds = gainSlider.getBounds(); auto childBounds = getLookAndFeel().getSliderLayout(gainSlider).sliderBounds; auto offset = componentBounds.getTopLeft(); g.drawRect(childBounds.translated(offset.getX(), offset.getY()));
Yes, after posting I realised you need to convert the coordinates to the slider’s parent coordinates.
You can use
auto componentBounds = gainSlider.getBounds(); auto childBounds = getLookAndFeel().getSliderLayout(gainSlider).sliderBounds; auto bounds = getLocalArea (&slider, childBounds);
Oh thats perfect! Thanks for that!