Default colors for components


#1

Hi, I finally got to making my custom look and feel. I want to reuse as much as possible from the supplied implementation. Well the point is that I want all my buttons have a certain (but same) color. The same goes for the font color and lot of other things. I know I can individually set all the colors using the setColour() inherited from Component and ColourIDs enum in every specific item. But i think there has to be some way to make it easier, because I can imagine that this is a completelly common thing to do (usually you do want to have all the buttons of the same collor etc). No I don't think that I need to override the look and feel just to set the default color. Or do I?

 

Thanks a lot


#2

i have not looked into this enough yet so i cant be certain i have this right but as i understand the LookAndFeel class is integral to all widgets - if you do not choose one explicitly you get one of the defaults - you can see these in the JUCE demo app - i have found the demo app to be the best documentation as well - i think what you want to do is not 'override' as you say but to subclass the LookAndFeel class - define your colors and bitmaps there - and then tell all of your widgets to use your LookAndFeel class


#3

Yes, I actually meant to say to subclass one of the defaults, and "override" the inherited methods. Sorry if it was not clear though. Anyway, the point is that there already is this colorID system implemented in Component. Every child of the component has it's own set of color IDs and you can set every color individually for every component. Now I can subclass any of the default LookAndFeels and make that implementation ignore the color settings in the component, and just draw it in some fixed color. But that is not a good solution either. Say, I want ho have all the slider's red but just one of them green. Then I'd be screwed. What I would expect is that there could be some static method or something, that would allow me to change the default color for newly created sliders (buttons, windows...).


#4

Or create your own look and feel and define standardColours yourself in the constructor.


#5

But how would that help me? If I stilll wanted to have some of the items in different color, I couldn't do it. That would just limit me to use one specific color. Besides I think I would have to override all the methods again just to do almost exactly the same but with just a different color. That doesn't seem to me like a good solution. Either that, or I don't get your suggestion.


#6

Take a look at the LnFv2 constructor and the standardColours array - that's where the default colours are assigned to colour IDs. If you change these then the widgets will draw with those colours by default but you can still choose different colours for individual widgets on a case by case basis.

Alternatively, you can just redefine specific default colours in your derived constructor (see LnF v3 constructor for an example of this).


#7

Thanks a lot. I'll have a look.


#8

Yeas, that is exactly what I was looking for. Thanks.