OK there will be a simple answer to this but I cannot find it!
I have a DialogWindow that has a Component on it. The Component only has 3 Buttons and depending on which one is clicked we exitModalState(0), exitModalState(1) or exitModalState(2)
So how do I get that integer 0, 1 or 2 back to the DialogWindow and also returned from the openSwapDialog function?
Current code below, missing an integer to return:
int MemoryBankComponent::openSwapDialog(int startSlot, int endSlot)
{
juce::DialogWindow::LaunchOptions dialog;
dialog.content.setNonOwned(new DialogComponent());
dialog.dialogTitle = "Swap Memory Slots!";
dialog.componentToCentreAround = this;
dialog.dialogBackgroundColour = getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId);
dialog.escapeKeyTriggersCloseButton = true;
dialog.useNativeTitleBar = false;
dialog.resizable = false;
dialog.useBottomRightCornerResizer = false;
dialog.launchAsync();
}
class DialogComponent : public juce::Component
{
public:
DialogComponent()
{
addAndMakeVisible(cancelButton);
cancelButton.onClick = [this] { getParentComponent()->exitModalState(0); };
addAndMakeVisible(swapInLibrarianButton);
swapInLibrarianButton.onClick = [this] { getParentComponent()->exitModalState(1); };
addAndMakeVisible(swapBothButton);
swapBothButton.onClick = [this] { getParentComponent()->exitModalState(2); };
setSize(400, 300);
}
~DialogComponent() override
{
}
void resized()
{
swapInLibrarianButton.setBounds(getWidth() * 0.25, getHeight() * 0.2, getWidth()*0.5, getHeight()*0.1);
swapBothButton.setBounds(getWidth() * 0.25, getHeight() * 0.5, getWidth() * 0.5, getHeight() * 0.1);
cancelButton.setBounds(getWidth() * 0.25, getHeight() * 0.8, getWidth() * 0.5, getHeight() * 0.1);
}
private:
// Buttons
// -------
juce::TextButton swapInLibrarianButton{ "Swap only in Librarian?" };
juce::TextButton swapBothButton{ "Also swap in Hardware" };
juce::TextButton cancelButton{ "Cancel" };
};
Most of the solutions I found on the Forum refer to runModalLoop with an equal number of other articles saying DO NOT run ModalLoops! So I’m using launchAsync instead but I can’t find much reference to returning integers for that. I also looked at the DialogsDemo but tbh I cannot make head nor tail of it.