How do you restrict a button to only be visible inside a canvas in UMG?

Hey, so i’m working on a menu that have several different buttons that are being drawn to the screen. I have also made a simple way to drag the buttons around using the mouse using SetRenderTranslation. But what i cannot figure out is how i could do so that the buttons only get drawn inside the canvas they are inside in the hierarchy.

This is what it looks like at the moment, what i would like to achieve is so that when i drag the button to the location in the image only the small part inside the white window is shown, not the entire button.
Does anyone know a way to do this? Any help is appriciated.

You should be able to toggle the visibility using remove from parent or set visibility. You are going to have to do some math though. Create a second 2D vector that adds the width and height of your container there. Those two vectors will give you your boundaries.

Get the coordinates of your widget (should return top left most corner). In your update, loop, check the widget that you are dragging’s location. On each update, check if button coordinates are within the range of values.

x1y1< i < x2y2

If its within range, do nothing, else, remove from parent.