Using a OfxButton in two different OfxPanel

Hi,

I’m trying to use the same OfxButton in two different OfxPanel to avoid creating a 2nd OfxButton, it technically works but there are graphical errors and my button does not appear in one of my Panel unless I move it.

I understand that I can just initialize a different OfxButton, do the setup the same way as the first and use the same listener, just curious if there’s way around that.

First button is set that way:

button_undo.setup("Undo");
button_undo.addListener(this, &Application::button_pressed_undo);
group_utilCanvas.add(&button_undo);

Then down below where I am setting up the 2nd Panel I have

util3D.add(&button_undo);

Here’s what it looks like, this is the first button that is being added:
lol

Cheers !

Hi, it is better and easier if you use an ofParameter<void>.

ofParameter button_undo;

button_undo.set("Undo");
button_undo.addListener(this, &Application::button_pressed_undo);
group_utilCanvas.add(button_undo);
util3D.add(button_undo);

Thanks I didn’t know ofParameter were a thing.

ofParameter is awesome and really useful, not only for the gui.
it is essentially an object of the templated class ( the one between < > when you declare it) which emits an event whenever its value changes, thus you can use a listener on it.
ofParameter<void> is a special case where it holds no object but it emits an event. This is used mostly for a buttons

1 Like