Template Canvas Layout Constraints

Are there directions for how to use this property? The default is ins 0, fill - whatever that means.

I would like to be able to set up the template to maintain the aspect ratio and center itself in the available space within the component bounds. Is that possible?

It's MigLayout:

Centering, yes. Aspect ratio... Probably.

I tried ins 0, fill, grow, push, align center but I just get the little error triangle. The template shows up if I use the default ins 0, fill

The property at the top level only sets the outer container's constraints.
Directives like push, grow, align are all applied to the individual component - you need them to end up in your template canvas dataset/to set them via the customizer.

Like so?

No change.

Any errors in the output console? What do you have for your container layout props? Can you show the error indicator you're seeing?

Nothing in the output console.

Not sure which prop you're referring to. This is a popup view with the root container. The template canvas is inside the root container. There are no layout options on the window or root container view. The template canvas is set to relative layout.

The error indicator I was seeing was when I was putting ins 0, fill, grow, push, align center all in the Layout Constraints for the template canvas component, before I moved everything after 0 into the templates dataset prop.

In that case, I got the following error in the console

15:18:30.959 [AWT-EventQueue-0] WARN Vision.TemplateCanvas - Error during layout construction
java.lang.IllegalArgumentException: Illegal Constraint: 'grow'
Unknown Constraint: 'grow'

	at net.miginfocom.layout.ConstraintParser.parseLayoutConstraint(Unknown Source)
	at net.miginfocom.swing.MigLayout.setLayoutConstraints(Unknown Source)
	at net.miginfocom.swing.MigLayout.<init>(Unknown Source)
	at net.miginfocom.swing.MigLayout.<init>(Unknown Source)
	at com.inductiveautomation.factorypmi.application.components.TemplateCanvas$LayoutPanel.<init>(TemplateCanvas.java:814)
	at com.inductiveautomation.factorypmi.application.components.TemplateCanvas._rebuild(TemplateCanvas.java:246)
	at com.inductiveautomation.ignition.client.util.EDTUtil$ProcessQueue.run(EDTUtil.java:126)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

idk why I'm trying to do this the hard way... I'll just increase the size of my template to match the canvas and center things within my template. :sweat_smile:

1 Like

So, simple centering is easy:

These template canvases are ins 0, fill. The inner templates are just align center.

Maintaining an aspect ratio is tricky for an arbitrary template. MigLayout is, at its core, built around a table-based layout approach that doesn't really care about preserving aspect ratio, only components' preferred sizes. It would probably be possible to do some live math using the actual size of the canvas and passing that into the constraints on the component, but it's probably not worth it.

1 Like