Resizable and draggable component

I’m working on a simple component that I want to be resizable and draggable, using a ResizableBorderComponent and a ComponentDragger. My component seems to be working fine in most cases, but after I resize, the next drag makes the component jump. If the component starts at (10,10), and I start dragging, the mouse cursor moves as expected but the component itself moves to (20,20). Subsequent calls to mouseDrag work as expected. I’m guessing setBounds is being called twice in a row or something like that, but I just can’t figure it out.

[code]class ResizableTextButton : public TextButton
{
public:
ResizableBorderComponent* resizer;
ComponentDragger dragger;
ResizableTextButton(String name) : TextButton(name)
{
resizer = new ResizableBorderComponent(this, 0);
addAndMakeVisible(resizer);
}

void resized()
{
	resizer->setBounds(this->getBounds());
}

void paint(Graphics& g)
{
	TextButton::paint(g);
	Rectangle dims = this->getBounds();
	g.drawRoundedRectangle(0, 0, dims.getWidth(), dims.getHeight(),5,3);
}

void mouseDown(const MouseEvent &e)
{
	if(e.mods.isRightButtonDown())
	{
		dragger.startDraggingComponent(this,0);
		dragger.startDraggingComponent(resizer,0);
	}
	else
	{
		TextButton::mouseDown(e);
	}
}

void mouseDrag(const MouseEvent &e)
{
	if(e.mods.isRightButtonDown())
	{
		dragger.dragComponent(this,e);
		dragger.dragComponent(resizer,e);
	}
	else
	{
		TextButton::mouseDown(e);
	}
	
}

};[/code]

this is odd, but I don’t experience the jumpiness you describe, however the draggable component does seem to be acting odd…the component must be at least a certain size(I haven’t looked into what size it is) or it won’t show the dragging cursors…but that could just be the code I’m using…which is pretty much your code copied and pasted into the juce hello world application.

I think you should have a careful think about the line “resizer->setBounds(this->getBounds());”…

Changed it to resizer->setBounds(0,0,getWidth(),getHeight()) and that fixed it. When I started, I made it resizable, and apparently didn’t notice the slight offset between the border and the component itself.

Thanks for the help.