I’ve asked this many times over the years because it’s always puzzled me why we see it on the forum so much, but never got a good answer from anyone:
As a beginner, what made you think you had to write String ("0") rather than just "0" ?
Adding the String around it isn’t something you need to do with juce, or C++ in general, or any other language or toolkit that I know. And none of our JUCE demo code looks like that, but still it seems that countless beginners end up writing code that way! Do you remember where you saw it and copied it from?
Yes, you skipped the construction of your child objects, otherwise I could have pointed that out.
The reason for setSize() to call resized() is, that it actually changed the bounds, so the component gets the chance to update things like the children bounds.
The solution is to call setSize() AFTER you created the child components.
Another addition, since the number of child components is static, you could preferably make them members instead of heap allocated objects by defining them like:
The problem was rather trivial actually. I was so convinced it was something in the layout that I didn’t think. I had overridden paint in VFODigit but not called the base paint with the result that the label wasn’t painted, only the background. Still I’ve learnt a lot. I will incorporate the other helpful hints and hopefully have some half decent code by the end of it. As for String(“0”) it just seems more explicit to me but if it upsets people I will leave it out in future posts.
Nobody’s going to be upset by it! I’m just always puzzled about why people do stuff like that when it’s not needed, and that one seems like a very common quirk for some reason.
Noob writes DBG("level: " + level); (or something) and finds that it won’t compile.
Noob spends 45 minutes trying to work out why it won’t compile and finally stumbles upon DBG(String("level: ") + String(level));
Noob “learns” to put String() in front of everything so that (s)he doesn’t have to wage a war every time (s)he wants to print something.
Six months later, Noob accidentally writes DBG("level: " + String(level)); and finds that it works. (S)he learns something new!
Learning a programming language (or anything) is 10% learning from first principles and 90% learning from reinforcement. To an expert, C++ is defined by the ISO standard, but to a learner it is defined by obscure compiler messages telling you that you’re wrong and by people on Stack Overflow* making you feel terrible for asking honest questions.