Thanks Daniel.
I understand this part of the example project:
MainContentComponent()
#if ! JUCE_PROJUCER_LIVE_BUILD
: rightPanel (Colours::lightgrey),
leftPanel (Colours::lightblue)
#endif
{
addAndMakeVisible (rightPanel);
addAndMakeVisible (leftPanel);
addAndMakeVisible (mainPanel);
setSize (600, 400);
}
~MainContentComponent() {}
void paint (Graphics& g) override
{
g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
}
void resized() override
{
FlexBox fb;
FlexItem left (getWidth() / 4.0f, getHeight(), leftPanel);
FlexItem right (getWidth() / 4.0f, getHeight(), rightPanel);
FlexItem main (getWidth() / 2.0f, getHeight(), mainPanel);
fb.items.addArray ( { left, main, right } );
fb.performLayout (getLocalBounds().toFloat());
}
It makes a flexbox called fb with three flexitems, that are then added to an array so the flex box can organize them.
But I don’t understand how this works with the knobs and sliders. I don’t see the same method used. It’s just for loops. There’s no other “addarray” anywhere else. And I don’t even see the knobs/sliders defined anywhere except as (I think) auto-generated by for loops.
eg.
for (int i = 0; i < 6; ++i)
{
auto* slider = new Slider();
slider->setSliderStyle (Slider::SliderStyle::Rotary);
slider->setTextBoxStyle (Slider::NoTextBox, true, 0, 0);
addAndMakeVisible (knobs.add (slider));
As I said I think this is useless from a demonstration purpose because you never just want to generate 6 random sliders with nothing specific about any of them.
So let’s say in the simplest form, I want to individually define ~30-50 knobs each with parameters each like this:
addAndMakeVisible (frequencySlider);
frequencySlider.setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
frequencySlider.setTextBoxStyle(Slider::TextBoxBelow, false, 100, 20);
frequencySlider.setRange (50.0, 5000.0);
frequencySlider.setSkewFactorFromMidPoint (500.0);
frequencySlider.setNumDecimalPlacesToDisplay(1);
addAndMakeVisible(frequencyLabel);
frequencyLabel.setText("Frequency", dontSendNotification);
frequencyLabel.attachToComponent(&frequencySlider, false);
frequencyLabel.setJustificationType(Justification::horizontallyCentred);
And then I want to put those in a simple array and have it automatically assign each one an equal width/height and wrap it into rows, how would I do that?
I think that would make a much more useful application of the tutorial, even if it was demonstrated with just 3-5 knobs, since that’s what we actually have to try to do in real life.
I think I can do this by just using the same method as the panels above by manually defining each knob as a flex item (but with what width/height?) and then manually entering them to an array in the same way. But with all the “for” loops in the tutorial I’m not sure if this is the most efficient or correct way.
Any further help?
Thanks