Snapping with componentDragger?


#1

Is there an easy way to enabling snapping(snap to grid) with a componentDragger? Right now I’m doing it rather crudely in the component mouseDrag method:

void MyComp::mouseDrag(const MouseEvent& e){
//pos hold the position of the component before dragging starts
	if(e.getDistanceFromDragStartX()%10==0)
		x = e.getDistanceFromDragStartX();
	if(e.getDistanceFromDragStartY()%10==0)
		y = e.getDistanceFromDragStartY();
		
	setTopLeftPosition(x+pos.getX(), y+pos.getY());
}

But I’d rather do it using a componentDragger if it’s possible?


#2

Take a look at ComponentBoundsConstrainer - I believe you’ll want to put your snapping logic into the checkBounds function. You’d then keep an instance of your constrainer subclass around somewhere, and pass a pointer to it to the ComponentDragger::dragComponent calls.


#3

Thanks haydxn, this should get me started. btw, I’m still using your ComponentLayoutEditor class! I’ve hacked it to pieces at this stage, but I’d be lost without it!