Get component size before layout applied

Is there any way to get the size of a component before layout is applied (e.g. as in a client) in scripting?
I have a fly-in panel using system.gui.transform however at the moment I have to hardcode the x coordinates to move it to to move in in and out of the (right side of the) page. I’m using designer coordinates, as I can’t use runtime with right-side fly-ins due to the layout system (left side works ok).

To make it dynamic code instead, I want to get the width of the component and the width of the container its in, and use that instead. However these need to use designer widths, not client/layout-applied widths… Can I get this?

if event.propertyName == 'ShowConfig':
	objWidth = event.source.width ## this is the layout-applied width, need to replace with the designer width
	cntWidth = event.source.parent.width ## this is the layout-applied width, need to replace with the designer width
	newX = cntWidth #### Doesn't work as not designer-width
	newX = 1361 

	# if we want to show it, move it into the screen from the right
	if event.newValue:
		newX -= objWidth ####
		newX = 921
		event.source.visible = 1
	else: event.source.visible = 1
	
	system.gui.transform(event.source
						,newX = newX
						,duration=75
						,acceleration=4
						,coordSpace=system.gui.COORD_DESIGNER)

This code in a rectangle’s mouse released event

widthConfig = event.source.relWidth
widthRuntime = event.source.getSize().getWidth()
system.gui.messageBox(str(widthRuntime), str(widthConfig))

gives results like this when clicked in a resized client:
image

1 Like

I assume that relWidth is a custom property you added and set manually? The manual part is what I want to avoid; if I change the width of the fly-out panel, I don’t want to rely on remembering to also update the new width in the parameter / code (it’s also neater not to have to hardcode things)

No, it's the scripting name of the "Width" property on components that show one, like a rectangle:
image
Nothing is manually set for the code I posted to work. I don't know offhand if there's a way to get a similar property on components that don't have "Width" listed in their properties, but figure you could likely use a transparent rectangle or other shape with this property in your container, etc. (use absolute layout to keep it stretched to extents) to get what you need--if you don't already have a suitable rectangle to get this from as part of your design.

I've been trying to do the same and stumbled upon this which so far gives what I need.

from com.inductiveautomation.factorypmi.application.components.util import FPMILayout
component = event.source
design = FPMILayout.getPreferredBounds(component)
print design.width, design.height, design.x, design.y
1 Like