I need to configure the textbox of my custom slider, so that the textbox is a few pixels below the slider. Currently, it is too close to the slider. I have tried changing the look and feel of the slider and modifying the getSliderLayout function, but when I change the y position of the textbox by giving it 20 more pixels, the textbox goes out of the bounds of the slider and disappears. I have tried increasing the height of the layout, but it still does not work.
What can I do? All I need is to move the textbox a bit further down.
class myLookF : public juce::LookAndFeel_V4
{
public:
juce::Slider::SliderLayout getSliderLayout(juce::Slider& slider)
{
// 1. compute the actually visible textBox size from the slider textBox size and some additional constraints
int minXSpace = 0;
int minYSpace = 0;
auto textBoxPos = slider.getTextBoxPosition();
juce::Slider::SliderLayout layout;
if (textBoxPos == juce::Slider::TextBoxBelow)
{
int minXSpace = 0;
int minYSpace = 0;
auto textBoxPos = slider.getTextBoxPosition();
if (textBoxPos == juce::Slider::TextBoxLeft || textBoxPos == juce::Slider::TextBoxRight)
minXSpace = 30;
else
minYSpace = 15;
auto localBounds = slider.getLocalBounds();
auto textBoxWidth = juce::jmax(0, juce::jmin(slider.getTextBoxWidth(), localBounds.getWidth() - minXSpace));
auto textBoxHeight = juce::jmax(0, juce::jmin(slider.getTextBoxHeight(), localBounds.getHeight() - minYSpace));
// 2. set the textBox bounds
if (textBoxPos != juce::Slider::NoTextBox)
{
if (slider.isBar())
{
layout.textBoxBounds = localBounds;
}
else
{
layout.textBoxBounds.setWidth(textBoxWidth);
layout.textBoxBounds.setHeight(50);
if (textBoxPos == juce::Slider::TextBoxLeft) layout.textBoxBounds.setX(0);
else if (textBoxPos == juce::Slider::TextBoxRight) layout.textBoxBounds.setX(localBounds.getWidth() - textBoxWidth);
else /* above or below -> centre horizontally */ layout.textBoxBounds.setX((localBounds.getWidth() - textBoxWidth) / 2);
if (textBoxPos == juce::Slider::TextBoxAbove) layout.textBoxBounds.setY(0);
else if (textBoxPos == juce::Slider::TextBoxBelow) layout.textBoxBounds.setY(localBounds.getHeight() - textBoxHeight + 20);
else /* left or right -> centre vertically */ layout.textBoxBounds.setY((localBounds.getHeight() - textBoxHeight) / 2);
}
}
// 3. set the slider bounds
layout.sliderBounds = localBounds;
if (slider.isBar())
{
layout.sliderBounds.reduce(1, 1); // bar border
}
else
{
if (textBoxPos == juce::Slider::TextBoxLeft) layout.sliderBounds.removeFromLeft(textBoxWidth);
else if (textBoxPos == juce::Slider::TextBoxRight) layout.sliderBounds.removeFromRight(textBoxWidth);
else if (textBoxPos == juce::Slider::TextBoxAbove) layout.sliderBounds.removeFromTop(textBoxHeight);
else if (textBoxPos == juce::Slider::TextBoxBelow) layout.sliderBounds.removeFromBottom(textBoxHeight);
const int thumbIndent = getSliderThumbRadius(slider);
if (slider.isHorizontal()) layout.sliderBounds.reduce(thumbIndent, 0);
else if (slider.isVertical()) layout.sliderBounds.reduce(0, thumbIndent);
}
}
else
{
if (textBoxPos == juce::Slider::TextBoxLeft || textBoxPos == juce::Slider::TextBoxRight)
minXSpace = 30;
else
minYSpace = 15;
auto localBounds = slider.getLocalBounds();
localBounds.setHeight(localBounds.getHeight() + 20);
auto textBoxWidth = juce::jmax(0, juce::jmin(slider.getTextBoxWidth(), localBounds.getWidth() - minXSpace));
auto textBoxHeight = juce::jmax(0, juce::jmin(slider.getTextBoxHeight(), localBounds.getHeight() - minYSpace));
// 2. set the textBox bounds
if (textBoxPos != juce::Slider::NoTextBox)
{
if (slider.isBar())
{
layout.textBoxBounds = localBounds;
}
else
{
layout.textBoxBounds.setWidth(textBoxWidth);
layout.textBoxBounds.setHeight(textBoxHeight);
if (textBoxPos == juce::Slider::TextBoxLeft) layout.textBoxBounds.setX(0);
else if (textBoxPos == juce::Slider::TextBoxRight) layout.textBoxBounds.setX(localBounds.getWidth() - textBoxWidth);
else /* above or below -> centre horizontally */ layout.textBoxBounds.setX((localBounds.getWidth() - textBoxWidth) / 2);
if (textBoxPos == juce::Slider::TextBoxAbove) layout.textBoxBounds.setY(0);
else if (textBoxPos == juce::Slider::TextBoxBelow) layout.textBoxBounds.setY(localBounds.getHeight() - textBoxHeight);
else /* left or right -> centre vertically */ layout.textBoxBounds.setY((localBounds.getHeight() - textBoxHeight) / 2);
}
}
//layout.textBoxBounds.setY(layout.sliderBounds.getY() );
// 3. set the slider bounds
layout.sliderBounds = localBounds;
if (slider.isBar())
{
layout.sliderBounds.reduce(1, 1); // bar border
}
else
{
if (textBoxPos == juce::Slider::TextBoxLeft) layout.sliderBounds.removeFromLeft(textBoxWidth);
else if (textBoxPos == juce::Slider::TextBoxRight) layout.sliderBounds.removeFromRight(textBoxWidth);
else if (textBoxPos == juce::Slider::TextBoxAbove) layout.sliderBounds.removeFromTop(textBoxHeight);
else if (textBoxPos == juce::Slider::TextBoxBelow) layout.sliderBounds.removeFromBottom(textBoxHeight);
const int thumbIndent = getSliderThumbRadius(slider);
if (slider.isHorizontal()) layout.sliderBounds.reduce(thumbIndent, 0);
else if (slider.isVertical()) layout.sliderBounds.reduce(0, thumbIndent);
}
}
return layout;
}
};
