Dynamically changing the size of a toggle in ofxGui


i’d like to adjust the size of a toggle of type parameter or ofxToggle with respect to the size of a window, however, i am only able to change the size of the ofxPanel associated with it while the toggle stays the same size.

is it possible to change the size of the toggle? parameter doesn’t have any . properties that effect size; i can set its initial size with the ofxPanel.setDefaultWidth and Height or setSize, but only the panel’s size dynamically changes. ofxToggle has setSize as a property but only the area around the toggle changes while the toggle itself stays the same size.

thanks in advance.


Sorry, misread the question …

hi javl,

i’m not sure if your misunderstanding will help since it’s another method to try. i’ll try it anyway.

however, i only used it in this way … filled.setSize(400, 100);

what is the difference between calling the function as you have shown and this:

float wfilled = 400;
float hfilled = 100;

in setup()
filled.setSize(wfilled, hfilled);

in update()
wfilled = ofMap(wfilled, 0, 400, 0, ofGetWidth());
hfilled = ofMap(hfilled, 0, 100, 0, ofGetHeight());

this is the way i tried it; why doesn’t this update with the mouse movement as expected?

i saw sizeChangedCB() in the list of properties. what is CB? and why is there no bool function defined?


Sorry, misread the question and posted the exact ‘solution’ you mentioned didn’t work. I removed it but think you responded to the old answer.

Looking at the source, the size of the checkbox is determined by checkboxRect inside the ofxToggle object. But this variable is protected and there is no setter function outside of its setup(). Maybe you can remove the toggle and replace it with a new one that has the right size?

that’s a good idea. i’ll try that.

thanks again.


Oh, and I have no clue what a CB is and why the function is called sizeChangedCB() and not just sizeChanged() :stuck_out_tongue:


if the replacing toggle method works, i’ll let you know.


hi javi,

thanks for the suggestion. i got it to work, but had to use separate ofxPanels for each toggle instead of one for multiple toggles since changing the height of an ofxPanel beyond the space it needs to fit all of the toggles without any space between them does not work.