Component painted over its children


#1

Hello there, I am new in the community, I just discovered JUCE yesterday and that seems to be a nice framework !

Something strange happened on a project I’m currently working on. The point is to have a main component (called “mainComponent”) which fits the application window and manages a color themed-based child component (“themedComponent”).
I use LookAndFeel_V3 to create my color themes, then when I choose a theme I apply the new LookAndFeel to “themedComponent” and its children. It seems working fine for the LookAndFeel part, but my problem is “themedComponent” seems painted over its child components.

Example:
-mainComponent => nothing in paint() override
–themedComponent => nothing in paint() override
—childComponent => fill blue in paint() override

Result : The blue component is shown.

Example:
-mainComponent => nothing in paint() override
–themedComponent => fill in black in paint() override
—childComponent => fill blue in paint() override

Result : All is black, no blue component shown.

I don’t know what is wrong, I’m currently referring to the JUCE’s LookAndFeel example, which handle several LookAndFeel classes without problem…

The code of my themed component is like this:

class themedComponent : public Component
{
public:
    themedComponent()
    {
        setSize(getParentWidth(),getParentHeight());
        addAndMakeVisible(childComponent);
    }
    void paint (Graphics &g) override
    {
        g.fillAll(getLookAndFeel().findColor(MyApp::ColourIds::main_background));
    }
    void resized() override
    {
        childComponent.setBounds(0,0,20,20);
    }
private:
    Component childComponent;
}

Since the official example use a struct instead of a class, I don’t know if it is related to the problem.


#2

I finally found the problem, it comes from my ColourIds enum for each child components. Since I didn’t define initializers in my enums, colors had been overwritten… The child component wasn’t be hidden, it had the same color as the main component :sleeping:

Sorry for that !