Change size of G4P controls

I’d like to be able to rearrange my G4P controls with the mouse. I’ve found an easy way to move them around with moveTo(newX, newY):

//G4P library
import g4p_controls.*;

GButton button;
GTextField textField;

ArrayList<GAbstractControl> controls = new ArrayList<GAbstractControl>();

public void setup() {
  size(480, 320);

  button = new GButton(this, 188, 145, 80, 30);
  button.setText("button");
  controls.add(button); // upcast to GAbstractControl

  textField = new GTextField(this, 188, 205, 80, 20);
  textField.setText("textfield");
  controls.add(textField); // upcast to GAbstractControl
}

public void draw() {
  background(230);
}

void mouseDragged() {

  for ( GAbstractControl control : controls) {
    if ( control.isDragging() ) {
      float x = control.getX() + mouseX - pmouseX;
      float y = control.getY() + mouseY - pmouseY;
      control.moveTo(x, y);
    }
  }
}

But how would I change the width and height of the controls?

Thanks.

Sorry but G4P does not support resizing controls after creation.

Thanks, Peter.

G4P does not support resizing controls after creation.

Then would it be overkill or even possible to somehow delete the control and recreate it with its original properties but in a new size without losing its addEventHandler()?

Shamless plu, currently working on a lib, Still some adjustments left as its in beta, but it should be able to handle what you require.

I can paste example code if you want to learn more.

I can paste example code if you want to learn more.

I’m committed to G4P, still I would be interested in your example code.

BMS b;
	Button b1,b2,b3;
	boolean bb1 = false;
	
	public void settings() {
		//		fullScreen();
		size(700, 500);
		
	};

	public void setup() {
		b = new BMS(this);
		b1 = new Button(20,90,90,20,"BTN1",b);
		b.add(b1);
	};
	
	public void draw() {
		background(255);
		b.runEmpty(mouseButton);
		
		
		if(b1.click)println("click",b1.toggle);
		b1.toggle(this,"bb1");
		if(b1.toggle(this,"bb1")) {
			
		}
		
		if(b.toggle(0)) {
			
		}
		//this needs to be placed last
		b.theme.run();
	};
	
	public void mousePressed() {

		//f.writeLine("hello");
	};


	public void keyPressed() {

	};

please make sure to download my latest release if you are going to try it.

and use setPos(x,y) to update positions.

Sorry but is that a working example? I get a NullPointerException at:
b.runEmpty(mouseButton);

please redownload the lib I updated when I posted the example, and the error should be cleared.

Redownloaded: still the same error.

I’d forgotten to remove the docks try it now.

and you should be able to set the width and height by simply doing;

// set width and height to appropriate vars
b1.w = width;
b1.h = height;

You can get rid of a control with
control.dispose();
and then recreate it with
control = new GButton(... );
but since you have a new object you will have to add the event handler again. It would not be too inefficient provided you only created the control when the finished size is reached i.e. not while the mouse is dragging through intermediate sizes.

All visible G4P controls have an off screen buffer for its visual appearance which is lazily updated when its state changes. This is CPU friendly at the cost of a little RAM.

I see you make use of the textfield class in g4p did you also want example code for my textarea alternative

Could you start a new topic with lots of examples so that others can also notice your library? I for one would be happy to follow that new thread.

BTW this worked for me:

public void mouseDragged() {

  if ( b1.pos() ) {  // another "hidden" method :)
    if ( !keyPressed ) {
      float x = b1.x + mouseX - pmouseX;
      float y = b1.y + mouseY - pmouseY;
      b1.setPos(x, y);
    } else {
      float w = b1.w + mouseX - pmouseX;
      float h = b1.h + mouseY - pmouseY;
      b1.w = w;
      b1.h = h;
    }
  }
}

I shall when its done, i still have a bit of work finalising themes