Moving templates on window

Has anyone had success with moving templates on a window?
I have tried a number of approaches as follows:

Template canvas
Placing a template canvas on a window in the required location, or even spanning the entire window, allows moving the template. However we found it is impossible to locate the template accurately wrt graphical objects / components that are not templates (ie not on the canvas).

system.gui.transform() allows movement of templates, but again the coordinates seem to be unmanageable over window coordinates. Extending this approach, we used invisible lines as reverence x & y axes, and used transform() to move the template wrt to these axes. Again, we found this unreliable as templates moved to unexpected locations.

Any ideas would be greatly appreciated

Review every component involved and make sure anchored layout is selected. Only anchored layout coordinates match designer coordinates.

Thanks Phil
Yes, that works, thanks
However, my screen is rather complex with many components. To keep the screen appearance consistent ALL components would need to be anchored. This results in unacceptable layout.

What I find confusing is that I can use an expression binding on the ‘x’ property of a ‘normal’ component and this works fine, but it doesn’t work on a template

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

Try using the coordSpace argument.

system.gui.transform(event.source, 100, 200, coordSpace=system.gui.COORD_DESIGNER)

https://docs.inductiveautomation.com/display/DOC79/system.gui.transform

2 Likes

Thanks Kevin
That’s exactly what I needed.
I thought I had read all the doco, but obviously missed that bit :slight_smile:

Ross