Could you use a constructor within the class instead of addButton ?
class ButtonPressable {
public:
int x;
int y;
int width;
int height;
std::string text = "Filler";
ButtonPressable (int x, int y, int width, int height, void (*onPress)(), std::string text = "Filler", vex::color color = vex::color(255, 0, 0)) {
x = x;
y = y;
width = width;
height = height;
onPress = onPress;
startListener();
draw();
}
}
//Example
int main() {
ButtonPressable(0, 0, 250, 100, onButtonPress, "Clear", vex::color(255, 0, 0));
}
When I get V5, I’m going to write a class for buttons.
I’m in IQ, so you can’t draw to the brain and it’s not a touchscreen. You can only print and check if Brain buttons are pressed. Like, physical Up, Down, and Check buttons.
So then I can just do something like
new Button(0, 0, 250, 100, [function to call when button pressed], "Name");
// Or however you create new objects in C++
Basically what you did, except using class instead of functions.