Hello,
I successfully managed to add a custom look and feel to all my TextButtons and customised them in the custom lnf class. Now I want to create a Button with a symbol in it. To be more precise, I want to create a custom Add Button. It should look like my Textbuttons but instead of a text it should have a Big Plus symbol in there. I could just write a plus symbol in there but for a Playbutton that’s not really possible. So I was thinking instead of using an imageButton, which I use at the moment, is it possible to create my own button which inherits from Button or even better TextButton? Then I think if it inherits from Textbutton and I attach the same lnf to it as to the others it should already have the implemented mask so that I just need to paint the plus symbol in the paint method. I already created an addbutton class which inherits from TextButton but I wasn’t able to draw anything in the button. Does somebody see the issue?
/*
==============================================================================
AddButton.h
Created: 5 Jul 2024 11:31:49am
Author: lazlo
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
//==============================================================================
/*
*/
class AddButton : public juce::TextButton
{
public:
AddButton() {}
AddButton(const juce::String& name) {}
~AddButton() override {}
void paintButton(juce::Graphics g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
auto& lf = getLookAndFeel();
lf.drawButtonBackground(g, *this,
findColour(getToggleState() ? buttonOnColourId : buttonColourId),
shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
//lf.drawButtonText(g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
//g.drawRect(getLocalBounds().reduced(20, 0), 1);
g.setColour(juce::Colours::black);
g.fillRect(getLocalBounds().reduced(20, 0));
}
void colourChanged() override { repaint(); }
enum ColourIds
{
buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
'off'). The look-and-feel class might re-interpret this to add
effects, etc. */
buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
'on'). The look-and-feel class might re-interpret this to add
effects, etc. */
textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */
textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */
};
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AddButton)
};
Could this approach worl in general or am I on a wrong path here? I kind of have the feeling the the lnf is blocking the paintButton() function, but I thought actually since I overrite it, it is possible somehow. Maybe somebody can explain that to me.
On the other hand, i thought then, well I could do another custom LnF but I feel like it’s not really DRY since I have to rewrite everything from the other LnF and only change the paint and actually change one line.
Or should I rather go with the image button? I feel like they are not so great if I zoom in or out and just painting these really simple symbols isn’t really complicated.
What approach would you recomment me?
