IncDecButton Layout: Am I overthinking this?

image

There is a lot of room for improvement, but I thought I would post this, since others have been looking for this.

How I did this:

  1. Added a value to the enum class
    /** The position of the slider’s text-entry box.
    @see setTextBoxStyle
    /
    enum TextEntryBoxPosition
    {
    NoTextBox,
    TextBoxLeft,
    TextBoxRight,
    TextBoxAbove,
    TextBoxBelow,
    TextBoxCentered /
    The new Enum */
    };
  1. I updated resizeIncDecButtons();
    void resizeIncDecButtons()
    {
    auto buttonRect = sliderRect;

     if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight || textBoxPos == TextBoxCentered)
         buttonRect.expand (-2, 0);
     else
         buttonRect.expand (0, -2);
    
     incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
    
     if (incDecButtonsSideBySide)
     {
         if (textBoxPos == TextBoxCentered)            
         {
             // NEW CODE
             auto w = valueBox->getWidth();
             auto y = buttonRect.getWidth();
             auto btnWidth = (y - w) / 2;
             decButton->setBounds(buttonRect.removeFromLeft( btnWidth));
             valueBox->setBounds(buttonRect.removeFromLeft(valueBox->getWidth()));
         }
         else
         {
             decButton->setBounds(buttonRect.removeFromLeft(buttonRect.getWidth() / 2));
             decButton->setConnectedEdges(Button::ConnectedOnRight);
             incButton->setConnectedEdges(Button::ConnectedOnLeft);
         }
     }
    
  2. To get the Arrow buttons to point appropriately, you’ll need to update the “LookAndFeel”

    class  CustomLookAndFeel : public LookAndFeel_V4
    {
    
    public:
        Button* createSliderButton(Slider&, bool isIncrement) override
        {
            if (isIncrement)
                return new ArrowButton("u", 0.0f, Colours::white.withAlpha(0.8f));
        
        return new ArrowButton("d", 0.5f, Colours::white.withAlpha(0.8f)); 
        }
    };