Constrain() function / mouse click on button

constrain has not to do with it

void mousePressed() {

  if (mouseX >= x && 
      mouseX <= x+widthRect && 
      mouseY >= y && 
      mouseY <= y+heightRect) {
    // do something 
  } else {
    // nothing 
  }

}

see https://www.processing.org/examples/button.html