• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Move UI button or any element in x and y axis specifically after creation?

Explorer ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

//Below script generates Window,Panel with button

//I would like to move button/UI element in x and y axis to desired location

//Could someone please let me know to achieve it?

function myScript(thisObj){

    function myScript_buildUI(thisObj){

       

        var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "tools",undefined ,{resizeable:true});

    

        

          var resAbout="panel{orientation:'row',\

                                          t1:Button{},\

                                           \

                                          \

                                          }";     

                                         

                myPanel.grp=myPanel.add(resAbout);

    myPanel.preferredSize=[500,200];

   myPanel.grp.preferredSize=[500,200];

           myPanel.grp.margins=2;

          

  

return myPanel;

}

var myScriptPal = myScript_buildUI(thisObj);

    if((myScriptPal != null) && (myScriptPal instanceof Window)) {

        myScriptPal.center();

        myScriptPal.show();

    }

}

      myScript(this);

TOPICS
Scripting

Views

439

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Feb 24, 2018 Feb 24, 2018

Button object as a location property that you can modify. Take a look at this snippet:

(function (thisObj) {

    buildUI(thisObj);

    function buildUI(thisObj) {

        var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {

            resizeable: true

        });

        // Resize the pallete

        win.preferredSize = [400, 200];

        // Create a dummy button

        var btn = win.add("button", undefined, "OK");

        btn.onClick = function () {

            /

...

Votes

Translate

Translate
Advocate ,
Feb 24, 2018 Feb 24, 2018

Copy link to clipboard

Copied

LATEST

Button object as a location property that you can modify. Take a look at this snippet:

(function (thisObj) {

    buildUI(thisObj);

    function buildUI(thisObj) {

        var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {

            resizeable: true

        });

        // Resize the pallete

        win.preferredSize = [400, 200];

        // Create a dummy button

        var btn = win.add("button", undefined, "OK");

        btn.onClick = function () {

            // Generate rnadom X and Y values

            var randomX = Math.random() * 400;

            var randomY = Math.random() * 200;

            // Change buttons position

            this.location = [randomX, randomY];

        }

        // Handle window resizing

        win.onResizing = win.onResize = function () {

            this.layout.resize();

        };

        // Show panel

        if (win instanceof Window) {

            win.center();

            win.show();

        } else {

            win.layout.layout(true);

            win.layout.resize();

        }

    }

})(this);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines