Skip to main content
Participant
April 19, 2017
Question

What's the benefit of defining your UI with a string?

  • April 19, 2017
  • 1 reply
  • 562 views

I see a lot of scripts that define their UI in a string and then add it to the panel, like this:

                    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);

                    res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                              // Then a whole bunch of groups of tabs

                    }"

                    //Add resource string to panel

                    myPanel.grp = myPanel.add(res);

What benefit does this give you compared to defining each group / tab / etc as a variable and using standard scripting?

This topic has been closed for replies.

1 reply

Horshack
Legend
April 19, 2017

It's faster and more tidy to declare a resource string than to write out the code. That said there are limitations/bugs in the resource implementation though - for example the ListBox control doesn't recognize the listbox-specific elements like numberOfColumns and showHeaders when encoded in a resource strong vs doing it the normal way.

UQg
Legend
April 20, 2017

Horshack​ :

The 4th argument to add is an object (the creation properties), and must be declared as 'properties' (an object) in the ressouces as well:

var myList = myGroup.add("listbox", undefined, undefined, {numberOfColumns: 2, columnTitles: ["name", "value"], showHeaders: true});

"{/**/

    myList: ListBox{properties:{numberOfColumns: 2, columnTitles: ['name', 'value'], showHeaders: true}},\

    }";

alert(myGroup.myList.properties.numberOfColumns);    // true

Xavier

Horshack
Legend
April 20, 2017

Thanks for this. I had tried all combinations before, including without any enclosing brackets and also with "creation_properties" as the nested named bracket. Prior attempts would create the instance props within the LB but wouldn't actually be used by the LB logic. Did you find this by creating a LB the traditional way and inspecting the object? Because I couldn't find naming it "properties" in the documentation when I was first trying to troubleshoot it.