sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Centering/Positioning a WebDialog at Load

    Scheduled Pinned Locked Moved SketchUp Tutorials
    sketchup
    3 Posts 2 Posters 3.6k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by Jim

      This is a How-To demonstrating one way of positioning a WebDialog at the time it is first shown.

      The ruby file:

      
      w=UI;;WebDialog.new
      
      f = File.dirname(__FILE__) + "/w.html" 
      w.set_file( f )
      
      w.add_action_callback("move") { |d, a|
        xy, wh = a.split(";")
      
        x, y = xy.split(",")
        x = x.to_i
        y = y.to_i
      
        w, h = wh.split(",")
        w = w.to_i
        h = h.to_i
      
        d.set_position((x - w)/2, (y - h)/2)
      }
      w.show
      
      

      The html file:

      
      <html>
        <head>
          <script>
            function move_to_center() {
      	window.location = "skp;move@" + screen.width + "," + screen.height + ";" + document.body.offsetWidth + "," + document.body.offsetHeight;
            }
          </script>
        </head>
        <body onLoad="move_to_center()">
          Hi
        </body>
      </html>
      
      

      Another way is to execute a script in the dialog's show method:

      
      w.show { w.execute_script("move_to_center()") }
      
      

      You then eliminate the need for the "onLoad" in the html body tag.

      Hi

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        Hey Jim. Is there a question here, or are you posting how to do it?

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          Heh, it's supposed to be a how-to in reponse to this question.

          Hi

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement