ofxUI, changing size and position of a widget?

I am not sure if this is the right forum section to post my question.

How can I change size and position(custom position,x and y positions) of an ofxUI widget,for example of an ofxUIButton?

It depends, whether you want to do this once or repeatedly.

If you take a look at the source code of ofxUIButton, you can see there are several constructor methods to instantiate a button. Most of these allow for x, y, width and height properties. Example from the top of my head:

int myWidth  = 100;
int myHeight = 100;
int myX      = 150;
int myY      = 50;

ofxUIButton *btn = (ofxUIButton * ) myCanvas->addWidget(new ofxUIButton("My Button", false, myWidth, myHeight, myX, myY, OFX_UI_FONT_MEDIUM));

If you want to build from there, just use functions like myCanvas->addWidgetSouthOf and refer to your button.

I’ve noticed that if you want a dynamic GUI -where for instance buttons are resized during runtime- this can easily become problematic using ofxUI.

When using the default addWidget() approach, the location of a ofxUIWidget is determined using the location and size of his/her older siblings. This calculation is only made upon adding a widget.
Resizing a widget after you have added even younger widgets, requires all younger siblings to reset their positions accordingly. I couldn’t find a better method for this than to completely remove all widgets (including listeners etc), and re-add them with updated sizes/positions.

Thanks for your answer.

ofxUIButton *btn = (ofxUIButton * ) myCanvas->addWidget(new ofxUIButton(“My Button”, false, myWidth, myHeight, myX, myY, OFX_UI_FONT_MEDIUM));

I was wondering how I can use a pointer for widgets and at the same time give initialization values for size and position,this line solved my that problem.

I thought the same thing.

Are there any other good c++ gui libraries suitable for(with documentation or good examples) OpenFrameworks,which can run especially on Android,Windows and Mac?

Did you(or anyone) test ofxUI on Android?The author of ofxUI wrote in his webpage that he tested it on Mac and Ios,and didn’t test it on Linux or Windows,but he wrote that ofxUI should run on them too cause his library is using OpenFrameworks for drawing(and I tested on Windows and it’s working).He didn’t mention anything about Android but I assume it should work on Android too cause ofxUI is using Openframeworks functions and Openframeworks can run on Android.

I think ofxUI is the most useful, but sadly also the most difficult GUI available right now. I have some good experience with ofxMSAInteractiveObject and have a sneaking suspicion that for my next project I’ll try to build a GUI from the ground up using that addon.

I have no experience with oF+Android at all, sorry, but I’d assume it would run fine because of the drawing by oF. You may want to check out ofxTouchGUI though to see if you can use it on Android.

Thanks for your answer :smile: