I have a system of Flexboxes that automatically organizes groups of sliders or other components on the screen. It is working well. A crude early version of what this can look like is this for perspective:
The trouble is my development and implementation has gotten far more advanced and I need a Viewport so I can vertically scroll as the groups are passing the viewable limit horizontally.
Here is my broken attempt to add a ViewPort (at the end). Not only is no viewport or scrollbar showing up, it is giving me a breakpoint on building and saying Unhandled exception at 0x00007FF80B0C47FB (ntdll.dll) in AudioPlugIn-Private.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FF80B1297B0).
. So obviously I am doing this completely wrong.
As I understand it the Viewport needs a component to base itself around, right? And it wouldn’t take “parentBox” which is the appropriate item in the design (since “parentBox” is the overarching FlexBox that contains all the groups and everything inside). So I thought maybe I could just make a generic new Component, find some way to make it the same size as ParentBox, and then use that as my Viewport component.
This is from my PluginEditor.cpp:
void AudioPlugInAudioProcessorEditor::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
FlexBox groupsBox;
groupsBox.flexWrap = FlexBox::Wrap::wrap;
groupsBox.justifyContent = FlexBox::JustifyContent::flexStart;
groupsBox.alignContent = FlexBox::AlignContent::flexStart;
for (int i = 0; i< mLabeledGroups.size(); i++) {
int rowCount = (mLabeledGroups[i]->getWidth() / (getWidth() - outerScreenMargin * 2 - betweenLabeledGroupMargin * 2) + (mLabeledGroups[i]->getWidth() % (getWidth() - outerScreenMargin * 2 - betweenLabeledGroupMargin * 2) != 0));
groupsBox.items.add(FlexItem(*mLabeledGroups[i])
.withMinHeight((mLabeledGroups[i]->getHeight()) * rowCount
+ verticalLabeledGroupMargin
+ betweenLabeledComponentMargin * 2 * (rowCount - 1)
)
.withMinWidth(mLabeledGroups[i]->getWidth())
.withMaxWidth(getWidth() - outerScreenMargin * 2 - betweenLabeledGroupMargin * 2)
.withMargin(betweenLabeledGroupMargin)
.withFlex(1));
}
FlexBox parentBox;
parentBox.flexDirection = FlexBox::Direction::column;
parentBox.items.add(FlexItem(groupsBox).withFlex(2.5, 2).withMargin(outerScreenMargin));
parentBox.performLayout(getLocalBounds().toFloat());
//BROKEN PART FOLLOWS
Component generalBoundsComponent;
addAndMakeVisible(generalBoundsComponent);
generalBoundsComponent.setSize(1000, 1000);
Viewport mainViewPort;
addAndMakeVisible(mainViewPort);
mainViewPort.setScrollBarsShown(true, false);
mainViewPort.setSize(screenWidth, screenHeight);
mainViewPort.setViewedComponent(&generalBoundsComponent);
}
Any help? Thanks.