Resizing WebDialog windows
-
Howdy;
I'm working on the UI for a plugin that uses the WebDialog class.
One feature of this UI is "accordion panels:" sections of the UI that collapse or expand when their header is clicked. Because the WebDialog.set_size method resizes windows by moving the top down instead of moving the bottom up (goofy!), and there isn't any way I'm aware of from which I can retrieve the window position so as to correct this behaviour using WebDialog.set_position, I initially implemented the resizing using the resizeTo method in Javascript.
This worked great in OSX, but I'm now testing in Windows and for some reason resizeTo and its good friend, resizeBy, don't want to work. They work in IE when called from the JavaScript console, but not within a WebDialog, whether called in a script or from the Ruby console. So, I'm wondering:
- Has anyone encountered this problem? If so, are you aware of the source, and any fixes or workarounds?
- Is there another way to resize windows in Javascript that consistently works within a WebDialog?
- Alternatively, is their a way to retrieve window position within Ruby so I can use a combination of the WebDialog.set_size and WebDialog.set_position methods to accomplish what I'm after?
The only solution I can think of is to use Javascript to get the window position and send it back to Ruby, but I'm always leery of sending data back and forth between Ruby and Javascript in rapid succession as it almost always breaks. So, any suggestions would be most welcome.
Here's hoping future versions of the API address the bug-ridden nightmare that is UI development.
-
The Sketchup DynamicComponents extension adds a few undocumented methods to several other classes, including UI::WebDialog, but the DC extension must be loaded to use them.
Test:
unless defined?($dc_observers) Sketchup.require('DynamicComponents/ruby/dcutils') end
(...at least I think if memory serves, that it is the 'dcutils.rbs' file that adds the extra functionality.)
Added instance methods to UI::WebDialog class:
last_height() last_height=() last_width() last_width=()
-
For MS IE specific development use the MSDN site:
Here's the window object page:
http://msdn.microsoft.com/en-us/library/ms535873(v=VS.85).aspx -
The next alternative is to use Win32API system calls on Windows.
Several plugins use this already, including Jim Foltz' RubyToolbar.
http://sketchuptips.blogspot.com/2007/08/plugin-ruby-toolbar.html
(Take a look at the code, you'll see how a window handle can be referenced using FindWindow(), the position gotten using GetWindowRect(), and the position set using SetWindowPos()There is also some style coding info in this topic (which applies to all floating "owned" windows.)
[url=http://forums.sketchucation.com/viewtopic.php?f=180&t=31213&start=30#p280148:3fgvmm5g]Re: [code] Win32 Moving/Showing/Hiding Toolbars and Dialogs[/url:3fgvmm5g] -
@dan rathbun said:
For MS IE specific development use the MSDN site:
Here's the window object page:
http://msdn.microsoft.com/en-us/library/ms535873(v=VS.85).aspxAin't working on WebDialogs - Javascript window object isn't linked to the WebDialog window.
-
@jeemang said:
The only solution I can think of is to use Javascript to get the window position and send it back to Ruby, but I'm always leery of sending data back and forth between Ruby and Javascript in rapid succession as it almost always breaks. So, any suggestions would be most welcome.
Callbacks from WebDialog Javascript under OSX is asynchronous - so sending multiple callbacks rapidly will eat some of the messages. You'd have to have a messagepump system to verify each message is received by Ruby before sending a new callback from Javascript.
-
@dan rathbun said:
The Sketchup DynamicComponents extension adds a few undocumented methods to several other classes, including UI::WebDialog, but the DC extension must be loaded to use them.
Thanks for the info, Dan! I searched around a little to find some more info on this, but wasn't able to (and unfortunately, as I'm sure you know, the Ruby code for this extension is scrambled). Is there a list of these methods collected anywhere? Although the last_height and last_width methods you list are interesting, what I really need is some sort of last_position method...
-
@thomthom said:
Callbacks from WebDialog Javascript under OSX is asynchronous - so sending multiple callbacks rapidly will eat some of the messages. You'd have to have a messagepump system to verify each message is received by Ruby before sending a new callback from Javascript.
Do you know if anyone has yet managed to build such a system? I searched around a little on the forums and all I could seem to find was stuff like this: http://forums.sketchucation.com/viewtopic.php?f=180&t=22698
The javascript code in the Dynamic Components folder shows what seems to be one half of such a system, and thus gives a bit of a starting point, but it would be nice to have something a little more substantial to start from...
Advertisement