I would like to add control over a TextButton's corner radius and border size.
What I though was make a class MyButton, derived from TextButton, and add two variables i.e. cornerRadius & borderSize.
Then through my LookAndFeel I could override the drawButtonBackground() to include these variables and draw accordingly.
Problem: How can I access the two variables of my class? The drawButtonBackground() only passes a Button*.
Can this be done through a LookAndFeel or should I just override the paintButton() and do the drawing directly there?
You can add these variables (cornerRadius && borderSize) and appropriate getters/setters in your custom LookAndFeel class.
Then you can store an instance of your custom LookAndFeel in your class and apply it for your class MyButton in constructor:
class MyButton: public TextButton
After that you can set your needed variables (e.g. cornerRadius) when you need:
void MyButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
m_customLookAndFeel.drawMyButton(g, *this, bool isMouseOverButton, bool isButtonDown);
// where through "this" I have access to the variables I need
// This would be the customLookAndFeel function declaration, so it has a "MyButton" pointer in its variables.
void drawMyButton (Graphics& g, MyButton& button, bool isMouseOverButton, bool isButtonDown);
Though, I understand that the setters then should also call the repaint() funtion?
If you want to have your own MyButton class which inherit Button, I think it's not so much difference, but for me it's more clear and convenient to perform these operations in LookAndFeel.
But also it makes a sense to create your button class only if you are going to use many buttons with different cornerSize & borderSize values.
If not, you can also just use standard Textbuttons and configure LookAndFeel with appropriate values as you need in your component's constructor.