My plugin is using HtmlDialog. It requires knowing the window size to position the HtmlDialog window. How does ruby API get the window sizes of Sketchup or screen?
You want the position of the SketchUp main window? Or the viewport?
Those are values we don’t have exposed via the API.
We currently only expose size and position of the HtmlDialog itself. This was added in SU2021.1 that was released yesterday:
Can you elaborate on what you’re doing that require you to position the HtmlDialog in relationship to the SU window or Viewport? Also whether it’s SU’s main window or Viewport is also important info to know, as on macOS SU is an MDI, so you’d have multiple windows. Or even none if all models are closed.
Thank you. I attempt to position my plugin like this in the red box:
If I know the position and size of the viewport, I can just fit my plugin into the left side of the viewport.
At a higher level you want to simulate docking? So if the API allowed dialogs to be docked you wouldn’t need the lower level details of SU window and viewport position?
What you’re looking for falls within this feature request?
Add ability to dock HTML · Issue #384 · SketchUp/api-issue-tracker (github.com)
Side note: wow would you expect this to work on macOS with multiple model windows? Would you have a single dialog for all windows? Or a window per open model?
Thanks a lot. No, I am not looking for a docking feature. Just a single dialog for all windows:
dialog = UI::HtmlDialog.new({
:left => 0,
:top => 82,
......
})
dialog.show
I am wondering if given the size of viewport of Sketchup, I can set :left, and :top to position the dialog window to the left side of viewport before dialog.show.
You can find the relative position of dialog with viewport via dialog.center
method.
Check this code - (Just tested on macOS):
def move_dialog_to(dialog, edge = :left)
v = Sketchup.active_model.active_view
case edge
when :left
h = v.vpheight
w = 100
when :right
h = v.vpheight
w = 100
when :top
w = v.vpwidth
h = 100
when :bottom
w = v.vpwidth
h = 100
else
return
end
dialog.set_size(w, h)
dialog.center
x, y = dialog.get_position
case edge
when :left
x -= v.vpwidth / 2 - w / 2
when :right
x += v.vpwidth / 2 - w / 2
when :top
y -= v.vpheight / 2 - h / 2
when :bottom
y += v.vpheight / 2 - h / 2
end
if Sketchup.platform == :platform_osx
y += 17
else
# y +=
end
dialog.set_position(x, y)
end
dialog = UI::HtmlDialog.new
dialog.show
move_dialog_to(dialog, :right)