Easiest way to pop a dialog box with a ColourSelector?


#1

What’s the easiest way to pop a dialog box that contains, as its content component, a ColourSelector with OK and Cancel buttons that call Component::exitModalState with the appropriate value (the colour will be transmitted using the ModalComponentManager::Callback)?

Is there a general solution or do I have to roll a DocumentWindow-derived class every time?


#2

DialogWindow::showModalDialog() used to work for me, but what i’m seeing now, Dialog windows are not in style.


#3

Yeah but I still have to roll my own DocumentWindow…is there no easier way to use the ColourSelector??

And then how do I get the Colour? By the time the modal state ends, the dialog box is destroyed and the only thing I get back is an int.


Assertion in Juce 5 that wasn't in 4
#4

Have you tried the pop-up colour selector in the introjucer’s colour editing panel? It uses a CalloutBox.


#5
void xxxxx()
{   
    ColourSelector colourSelector;
        
    colourSelector.set... (...);
    colourSelector.addChangeListener (...);
   
    CallOutBox callOut (colourSelector, *this, nullptr);
    callOut.runModalLoop();
}

void changeListenerCallback (ChangeBroadcaster* source) 
{
    ColourSelector* cs = dynamic_cast <ColourSelector*> (source);
    setColour (SomeComponentClass::xxxColourId, cs->getCurrentColour());
    //...
}

#6

Just in case anyone else finds this link, correct calling is noted here: