ofxUI - some questions...

Hi there,

I am using ofxUI addon to build a GUI. I’m a bit rusted with everything dealing with C++ but i make my way and things reminds me little by little.

My project progresses quite well and i am happy with it, but there are some issues i can’t get thru :

  • I am using a text input so i can enter some information. Problem is : how do you get and use the text entered ? I can’t figure how to assign this to a variable so i can use it in my code… yes i feel pretty dumb !

  • I am using buttons and toggles. I didn’t verify all widgets as i haven’t developped them yet. But one of them, an ofxLabelButton, triggers when mouse pressed AND when mouse released ! I use this button to add a canvas in my interface. Consequence is : it creates two canvas, one when clicked and one when released. Is it a bug or is there a mean to tell the widget to trigger only when mousse pressed ? If yes, How ?

thanks

For text input, try something along these lines in your guiEvent function:

  
      
  
string inputPhrase; //put this wherever  
else if(e.widget->getName() == "InputPhrase")  
	{  
        ofxUITextInput *textInput = (ofxUITextInput *) e.widget;    
        inputPhrase = textInput->getTextString();  
        cout<<"InputPhrase: " + inputPhrase<<endl;  
	}  
  

Also, look into using the ofSystemTextBoxDialog, i was having some issues with ofxUI and how it takes in text sometimes and SystemTextBoxDialog gave me more predictable results. Only issue is that the textbox dialogs seemed to get triggered on load in the program I was playing with them with…didn’t bugfix further:

  
  
  
    else if(name == "inputPhrase")  
	{  
        ofxUITextInput *textInput = (ofxUITextInput *) e.widget;  
        inputPhrase = textInput->getTextString();  
        if(textInput->getTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS && loadBang){ //i was trying loadbang to stop it from loading the system dialog box on program load...probably not necessary  
            inputPhrase = ofSystemTextBoxDialog("Input Phrase Please", inputPhrase);  
            textInput->setTextString(inputPhrase);  
            cout<<"input Phrase: " + inputPhrase<<endl;  
        }  
  
	}  

Hi,

Thanks for the answer.
I already tried your first solution but without effect. I will have a look tonight and see if i missed something.
I will also try your second option.

Thanks.

Ok it works !
First solution is ok. I just changed the name of the widget textinput as i suspected the name was already in use or something like that. I think there was something like conflict somewhere…

Thanks a lot for your answer which forced me to have closer look in my code :wink:

Ok for this one also. I contacted Rezaali, developer of ofxUI. Here is his answer :

buttons are supposed to tell you when you click on them and when you release, you can perform a simple check to see what the button’s state is by button->getValue() and if the value is true then do something, the second button event is the UI telling you that the button was released.

Thus:

if(button->getValue())
{
//do something
}
else
{
//do something else.
}

thanks everybody