Moving templates on window

When I had a template anchored to the bottom and right edges of a window, I had to negate some arguments in system.gui.transform().

The following code excerpt gets a button’s current coordinates, then “moves” the button to the coordinates that were just obtained. By all accounts, it looks like pointless code that wouldn’t do anything. But if the button is anchored to the right edge of the screen, this code snippet actually changes the x coordinate to the negative of whatever it was before. (E.g. If the button was at (40, 120) this would move it to (-40,120), which is off the screen.)

oldBtnY = btn.getY()
oldBtnX = btn.getX()
system.gui.transform(component = btn, newX = oldBtnX, newY = oldBtnY)

The following code, meanwhile, seems like it would move the button to a negative x coordinate. But when it runs on a button anchored to the right edge of the screen, the button does not move at all:

oldBtnY = btn.getY()
oldBtnX = btn.getX()
finalBtnY = oldBtnY
finalBtnX = -oldBtnX          # This needs to be negative because of the button being anchored to the right side of the screen.
system.gui.transform(component = btn, newX = finalBtnX, newY = finalBtnY)

Somebody who’s more competent with java might know a clever way to convert the coordinates automatically, but I stuck with manually programming negations in where I needed them.

1 Like