Limiting a ComponentBoundsConstrainer to be smaller than a window?

I have a draggable component controlled by a ComponentDragger as a child of a larger component which occupies the whole window. To make sure that the smaller component can’t be dragged off screen, this constructor where constrainer is a ComponentBoundsConstrainer object works fine:

AnchorPoint::AnchorPoint(float pX, float pY, float pW)
    fXpos = pX;
    fYpos = pY;
    fHeight = pW;
    fWidth = (fHeight * getParentHeight()) / getParentWidth();
    setBoundsRelative(fXpos, fYpos, fWidth, fHeight);
    printf("fWidth: %f\n", fWidth);
    printf("fHeight: %f\n", fHeight);
    conRect = getLocalBounds().reduced(5);
                              conRect.getX() + conRect.getWidth(),
                              conRect.getY() + conRect.getHeight());
    constrainer.setMinimumOnscreenAmounts(0xffffff, 0xffffff, 0xffffff, 0xffffff);

I want to be able to add and change the constraints such that the object is constrained to some area smaller than the window, my first instinct was to create a second component, also as a child of the AnchorPoint’s parent which is initialized with a pointer to the AnchorPoint object. This component then contains a Rectangle<int> , which changes its bounds based on the limits added to the AnchorPoint, then assigns its bounds to the AnchorPoint’s conRect and updates the constrainer via a call to .setSizeLimits with the same arguments as in the constructor.

The callback for movement of the AnchorPoint in the rectangle component looks like this:

int oldWidth = peerAnchor->conRect.getWidth();
    int oldHeight = peerAnchor->conRect.getHeight();
    int oldX = peerAnchor->conRect.getX();
    int oldY = peerAnchor->conRect.getY();
    int oldRight = oldX + oldWidth;
    int oldBottom = oldY + oldHeight;
    int deltaX = newX;
    int deltaY = newY;
    int deltaRight = (getParentWidth() - newRight);
    int deltaBottom = (getParentHeight() - newBottom);
    tempBounds.setLeft(oldX - deltaX);
    tempBounds.setTop(oldY - deltaY);
    tempBounds.setRight(oldRight + deltaRight);
    tempBounds.setBottom(oldBottom + deltaBottom);
    peerAnchor->conRect = tempBounds;

This still only limits the AnchorPoint to the window, but I did try filling the tempBounds rectangle in the paint function and upon dragging the AnchorPoint I get some strange trails/artifacts like described in this post.

This must be something I’m just not getting about the way a ComponentBoundsConstrainer and a ComponentDragger work together. Has anyone dealt with this before?

Ok so I figured it out, it’s much simpler to have the main component take a third type of component as a child, called AnchorBox in my case, which is essentially just a rectangle which has an AnchorPoint object as a child. The constrainer code stays the same except for that conRect uses getBoundsInParent rather than local bounds. All the functionality for limiting is also done in the AnchorBox methods which just resize it relative to the window, not requiring any changes to the ComponentBoundsConstrainer.