Where can I put stuff that should be available from all components?

for example my colour sheme, or methods that i wanna use all the time. can i put them in a seperated file or so? how would i go about this?

Hi
This is a pretty broad question.
Colours and such, I have defined as static in my LookAndFeel class that inherits the standard LF.
Generic utility functions that can be static, I have in some kind of helpers.h file.

1 Like

There is no reason for statics anywhere! avoid statics at all costs!

Nicolai is correct, the LookAndFeel is inherited to the child components. And you can have another instance at any layer, where you set a different set of colours.
Every Component’s ColourIds are in a separate namespace, so you can define every single colour in the master lookAndFeel. There is always a fallback lookAndFeel, so using

getLookAndFeel().setColour (Slider::rotarySliderFillColourId, Colours::green);

will set the colour on the components lookAndFeel. If none was set, the setting ends up in the fallback lookAndFeel, so it will effect all components.

1 Like

thank you! i think this is exactly what i need. the only problem is… i can’t seem to make it work. let me give you an example. i took my colour-array and put it into my utility.h like this: https://pastebin.com/puHJVSvQ

then i went to the header-file of the component, where i used this array, deleted it from there and included utility.h on it, so it takes the array from the utility-header. it didn’t underline anything as wrong.

but when i compiled it, it said: error LNK2005: “class juce::Array<class juce::Colour,class juce::DummyCriticalSection,0> cSheme” (?cSheme@@3V?$Array@VColour@juce@@VDummyCriticalSection@2@$0A@@juce@@A) already defined in Main.obj

but i did not define this array in the main-object already. i didn’t declare anything there at all. what am i doing wrong?

i still find the lookAndFeel-class a bit confusing. instead of telling it what colour a slider object should have i’d much rather just use it to define an array with colours and then send this to all my objects myself. i’d find that more intuitive because then i could also come up with component-types that aren’t there yet. or i just understand it wrong, but it seems like it’s restricted to the juce-classes

Have a look inside Juce_Colours.h
This is where all the colours like Colours::white are defined.

So I would go about it like this.
If you want to set a “rule” let’s say Button colour, this should be set with the ColourId as @daniel says.
But, if you also want to define some colours to use, you can do that like in the Juce_Colours file. I just keep them in the LookAndFeel class.
Then you can define “MySpecialGreen” and use this when settings ColourIds to make all greens in your app the same.
And if you later want to change the design of your app, you only have to change these key-colours.
Did that make sense?

The look and feel class take care of how the components are drawn.
If you want your buttons to look a special way, just override the right functions and add your code.
If you just want to change colours use the setColourId function that all components have.

1 Like

i’m very careful about overriding methods since i don’t wanna break anything, but i guess this is the way to go. atm i indeed try to figure out how to make my button look exactly like the rest of my design. need to get rid of its bg-colour, so it’s transparent and replace all lines with a specific colour. i looked into the textbutton-class and didn’t find methods for this, so i went into the button-class and it contains some lookAndFeel-methods for similiar stuff. i guess i just have to figure out how this class works finally. thanks for your help, everyone!