Skip to main content
Lordrhavin
Inspiring
April 3, 2024
Question

Scripting: Gridalingment of UI elements in dialogs

  • April 3, 2024
  • 1 reply
  • 179 views

The following code creates a simple dialog for layers:

 

	var doc = app.activeDocument;
	var dlg = new Window ("dialog", "Select Export Layers");

	var layerSelect = dlg.add("group");
	layerSelect.orientation = "column";
	layerSelect.alignChildren = "fill";
	
	for (var i = 0; i < doc.layers.length; ++i) {
		var layerRow = layerSelect.add("group");
		layerRow.add('statictext {text:"'+doc.layers[i].name.substring(0,10)+'",justify:"left",characters:10}');
		layerRow.add('checkbox', undefined, "");
		layerRow.add('checkbox', undefined, "");
	}

 


The UI elements are strangely aligned, perhaps someone can give some insight:


a) checkboxes and static text dont have vertical central alignment, can I set this somehow, so that either the middle of the checkbox is the vertical middle of text or that the baseline of the static text is the bottom of the checkboxes quare.

b) they all look different, is this a poor GUI rendering or something I was doing wrong?


c) what is the coordinate-system for "characters:10", is there a better way to do this?

This topic has been closed for replies.

1 reply

Community Expert
June 1, 2024

I'm not great at this stuff - and I know you are quite good @Lordrhavin 

But as nobody has replied I thought I'd offer something to get the conversation going

 

I wouldn't be 100% sure this is what you're looking for but hey, just trying to help 

 

https://documentation.help/InDesign-CS6/pc_EditText.html

 

 

var doc = app.activeDocument;
var dlg = new Window ("dialog", "Select Export Layers");

var layerSelect = dlg.add("group");
layerSelect.orientation = "column";
layerSelect.alignChildren = "fill";

for (var i = 0; i < doc.layers.length; ++i) {
    var layerRow = layerSelect.add("group");
    layerRow.orientation = "row";
    layerRow.alignChildren = ["center", "center"];
    
    var layerName = layerRow.add('statictext {text:"'+doc.layers[i].name.substring(0,10)+'"}');
    layerName.characters = 10;
    
    var exportCheckbox = layerRow.add('checkbox');
    exportCheckbox.value = false;
    
    var anotherCheckbox = layerRow.add('checkbox');
    anotherCheckbox.value = false;
}