Invalid when window position is negative

  1. SketchUp Version: Sketchup 2022
  2. OS Platform: Windows 11 23H2 x64

When I set the window position to a negative number, it should appear on my left screen, because my right screen is the main monitor.

dialog.set_poistion(-100,100) is valid.

dialog = UI::HtmlDialog.new(
  dialog_title: "Dialog Example",
  width: 600,
  height: 400,
  left: -100,
  top: 100,
  style: UI::HtmlDialog::STYLE_DIALOG
)
dialog.set_url("https://www.sketchup.com")
dialog.show
dialog.get_position
=> [0, 100]

Move the window to the left screen with the mouse

dialog.get_position
=> [-832, 131]

Use that after dialog.show:wink:

The position and size parameters in the option hash are only initial anyway.
If you’ve properly wrapped the namespace for the extension and provided a preference_key parameter to the dialog, Sketchup will remember the last position the user set and display it next time where it was last. To override it, use the dialog.set_poistion(left, top) command after the dialog.show.

BTW, better to use instance variable for reference e.g. @dialog,

“If there is no reference kept to the HtmlDialog object, the window will close once the garbage collection runs. This behavior can be confusing in trivial test code but is usually not a concern in real life scenarios. Typically a persistent reference, e.g. an instance variable, should be kept to bring the dialog to front, rather than creating a duplicate, if the user should request it a second time.”

1 Like

This solution will cause the window to flicker, so I hope to set the correct position directly during initialization.