brendanberg / interfascia

A graphical user interface library for the Processing graphics programming environment
http://interfascia.berg.industries/
Other
44 stars 9 forks source link

Remove button does not remove #18

Open rodri16 opened 5 years ago

rodri16 commented 5 years ago

Hi, I am using the library to draw a menu with 6 buttons. the problem is that when I try to delete buttons the last one remains in the drawing.

  c = new GUIController(this);
  rc = new IFRadioController("Mode Selector");

  b1 = new IFRadioButton("10s", 60, rectY, rc);
  b2 = new IFRadioButton("20s", 60, rectY+20, rc);
  b3 = new IFRadioButton("30s", 60, rectY+40, rc);
  b4 = new IFRadioButton("40s", 60, rectY+60, rc);
  b5 = new IFRadioButton("50s", 60, rectY+80, rc);
  b6 = new IFRadioButton("60s", 60, rectY+100, rc);
  c.add(b1);
  c.add(b2);
  c.add(b3);
  c.add(b4);
  c.add(b5);
  c.add(b6);

image

then i do other things and

 c.remove(b1);
  c.remove(b2);
  c.remove(b3);
  c.remove(b4);
  c.remove(b5);
  c.remove(b6);

but b6 remains

image

If for example I don't add b6, b5 remains. What is the problem?

akerfel commented 4 years ago

I have the same problem with IFButton's. The last button is still visible on the canvas when trying to remove all of them.

brendanberg commented 4 years ago

Thank you for documenting this. I've been able to reproduce the issue and I'm currently looking into it.

TrnsltLife commented 3 years ago

I was having this problem with 6 buttons that were permanent, and two that I added and removed. The following strategy seems to have worked for me:

IFButton okButton, cancelButton;

void addOKButton()
{
  int buttonY = 5 + buttonSpacingY * 5;
  okButton = new IFButton("OK", (int)guiOffset.x + buttonRowAX, (int)guiOffset.y + buttonY, buttonWidth, buttonHeight);
  okButton.addActionListener(this);
  gui.add(okButton);
}

void addCancelButton()
{
  int buttonY = 5 + buttonSpacingY * 5;
  cancelButton = new IFButton("Cancel", (int)guiOffset.x + buttonRowBX, (int)guiOffset.y + buttonY, buttonWidth, buttonHeight);
  cancelButton.addActionListener(this);
  gui.add(cancelButton);
}

void removeOKButton()
{
  gui.remove(okButton);
  //Set to null so the button isn't reused. Avoids some kind of mouse event already assigned exception.
  okButton = null;
}

void removeCancelButton()
{
  gui.remove(cancelButton);
  //Set to null so the button isn't reused. Avoids some kind of mouse event already assigned exception.
  cancelButton = null;
}

void showConfirmDialog(GUIEvent e)
{
  hideConfirmDialog(); //Get rid of any existing dialog
  confirmGuiEvent = e;
  addOKButton();
  addCancelButton();
}

void hideConfirmDialog()
{
  //Remove them in the opposite order
  removeCancelButton();
  removeOKButton();
  confirmGuiEvent = null;
}

Calling the showConfirmDialog() and the hideConfirmDialog() successfully adds/removes the buttons, and the buttons function properly (code for that not shown).