HtmlDialog window size not meeting width and height parameters

I define a HtmlDialog in the following way:

  dlg = UI::HtmlDialog.new(dialog_title: 'Dialog Example',
                           preferences_key: 'dialog.example',
                           scrollable: false,
                           resizable: false,
                           width: 238,
                           height: 197,
                           style: UI::HtmlDialog::STYLE_DIALOG)

I want the window to have a fixed size of 238x197 pixels. When I pop up the window the size is 401x290. Why is this so?

image

  • Traditionally, the size with which you create a WebDialog included the window borders and titlebar, leading to a smaller HTML area (this is often what developers didn’t want because they design the size of the HTML content and the window borders are unpredictable). To my knowledge, this behavior was not changed with the introduction of HtmlDialog.
    → Is your observation about the size of the window in physical pixels of the HTML content in virtual pixels applied by the browser engine?
  • You may have an OS-scaling factor other than 1.0 (100%).
    → What operating system and version and SketchUp version do you use?
    There was an OS&SU-specific inconsistency between scale factor of window coordinates/size and those inside the HTML, but in the latest combination of SketchUp 2018 and Wine/Windows 10 it is fixed.

@Aerilius

I’m using SketchUp Pro 2017 and Windows 10. Perhaps we found one of the reasons here.

Besides, I have observed that the window is keeping the last window size I set. For example, let’s say I set resizable: true in the code, resize the window to 600x400 manually with the mouse and close SketchUp.

Then, I set width: 200, height: 100 and resizable: false in the code and restart SketchUp. When I open the window, it does it at 600x400.

It’s like the dialog has “memory” and does not meet the parameters left, top, width, height. It always opens at the last position and size it was before closing.

Do you open it as modal?

I had an issue with the positioning of the dialog when opened as modal once. Wehn I opened it as a regular dialog it was positioned fine.

@Mitchell2.24v I use dlg.show so it’s a non-modal window

To get the dialog to show at the size you have specified in code you can comment out the preferences_key argument and add it back once you have found values you are happy with.

You can also manually delete the position from the preference file (C:\Users<Username>\AppData\Local\SketchUp\SketchUp 2019\SketchUp\PrivatePreferences.json) and restart SketchUp.

1 Like

You can also try creating it first, and then setting its properties before showing it. When I set center=true inside the new statement, the dialog is not centered. When I create it first and then do

dialog.center = true
dialog.show

It is centered. This might also work for the size properties with set_size?

That is precisely what happen when preferences_key is set on older SketchUp versions. This was fixed in SketchUp 2019 (File: Release Notes — SketchUp Ruby API Documentation)

For older versions, call .set_size after creating the dialog instance.

2 Likes

I don’t quite understand what you mean by that. center isn’t a constructor property of UI::HtmlDialog. Is that what you where trying to do?

I’m ashamed to admit that is what I was trying to do. I have just re-read the documentation and now don’t understand why I did that. My best excuse might be a late night at work?

Thanks for setting me straight.

To be fair, it wouldn’t be unreasonable to have it as a constructor property imo.

2 Likes

And for the record - Dan logged it as a feature request in our issue tracker: UI::HtmlDialog constructor could allow :center flag without breaking existing code · Issue #258 · SketchUp/api-issue-tracker · GitHub

Pointing that out to increase awareness of our public API issue tracker.

2 Likes