💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Centering/Positioning a WebDialog at Load
-
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.
-
Hey Jim. Is there a question here, or are you posting how to do it?
-
Heh, it's supposed to be a how-to in reponse to this question.
Advertisement