MessageBox how to use

Started by ingar, 26 April 2019, 18:43:47

ingar

Hi all,

I am sure this question has been posted many times before, but anyway:

How do I display a message box in TGUI?

I have tried tgui::MessageBox::Create("Heading","Message",{"OK", "Cancel"});
Then I add it to the gui, and it displays in the upper left corner.

But how do I get the events from my buttons (OK or Cancel)?

Can someone give me a complete example. Then I can make a function that just displays the message and returns with a value.

Ingar

texus

The connectable signals of a widget are currently listed under "Public Attributes" in the documentation. E.g. for MessageBox: https://tgui.eu/documentation/0.8/classtgui_1_1MessageBox.html#pub-attribs
(I am aware that you might not search them there and that you have to know where to look before you can find them)

MessageBox has a "ButtonPressed" signal which has the text of the pressed button as optional parameter, so you would have something like this:
Code (cpp) Select
messageBox->connect("ButtonPressed", [&retVal](const std::string& button){
    if (button == "OK")
        retVal = 0;
    else if (button == "Cancel")
        retVal = 1;
});