How can I limit the dragging line to the edge of my project area

Hi i am using a Line and i am dragging in it window.

but i want limit the dragging at edge of the window

please let me know how to limit dragging near to edge of the window

Just use a condition?

line = event.source
window = system.gui.getParentWindow(event)
mouseX = event.x
screenEdgeDeadband = 100

if mouseX >= screenEdgeDeadband and mouseX <= (window.width - screenEdgeDeadband)
    lineX = line.getX()
    lineY = line.getY()
    newLineX = lineX + mouseX
    system.gui.transform(line, newLineX, lineY, duration = 10)

Note: I didn’t test this, but the concept is the same. If there is a position where you don’t want the transform to happen block it with a conditional statement.

its not working. i will try this concept