Class: UI::HtmlDialog
- Inherits:
-
Object
- Object
- UI::HtmlDialog
- Defined in:
- lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb
Overview
The Ruby HtmlDialog class allows you to create and interact with HTML dialog boxes from Ruby. This is the best way to generate complex, embedded UIs inside SketchUp, but it does generally require HTML and JavaScript expertise.
If your goal is to simple display a website to your users, consider using #openURL, which will show them a web page in their default browser rather than inside a dialog in SketchUp.
The left, top, width, height etc. dimensions of the dialog are in logical units. This means you provide the units as if they where on a monitor with “normal” DPI. The units given will be multiplied by the same factor as returned by scale_factor.
For usage examples, including how to migrate from the old WebDialog class, see github.com/SketchUp/htmldialog-examples. You may use the Trimble Modus framework for a look and feel of your dialog that matches that of SketchUp’s dialogs.
HtmlDialog uses the following versions of CEF (Chromium Embedded Framework):
- SketchUp 2021.1
-
CEF 88
- SketchUp 2019.0
-
CEF 64
- SketchUp 2018.0
-
CEF 56
- SketchUp 2017.0
-
CEF 52
Constant Summary collapse
- CEF_VERSION =
Constants
nil
- CHROME_VERSION =
Stub value.
nil
- STYLE_DIALOG =
Stub value.
nil
- STYLE_UTILITY =
Stub value.
nil
- STYLE_WINDOW =
Stub value.
nil
Instance Method Summary collapse
-
#add_action_callback(callback_name) {|action_context, *args| ... } ⇒ Boolean
The #add_action_callback method establishes a Ruby callback method that your html dialog can call to perform some function.
-
#bring_to_front ⇒ nil
The #bring_to_front method is used to bring the window to the front, putting it on top of other windows even if its minimized.
-
#center ⇒ true
The #center method is used to center the HtmlDialog relative to the active model window.
-
#close ⇒ nil
The #close method is used to close a dialog box.
-
#execute_script(script) ⇒ nil
The #execute_script method is used to execute a JavaScript string on the html dialog asynchronously.
-
#get_content_size ⇒ Array(Integer, Integer)?
The #get_content_size method is used to get the content size of the HtmlDialog, in logical pixels.
-
#get_position ⇒ Array(Integer, Integer)?
The #get_position method is used to get the position of the HtmlDialog relative to the screen, in logical pixels.
-
#get_size ⇒ Array(Integer, Integer)?
The #get_size method is used to get the outer frame size of the HtmlDialog, in logical pixels.
-
#initialize(properties) ⇒ UI::HtmlDialog
constructor
The new method is used to create a new HtmlDialog.
-
#set_can_close ⇒ Boolean
The #set_can_close method is used to attach a block that is executed just before closing, this block has to return a boolean, if the block returns false the close will be canceled.
-
#set_content_size(width, height) ⇒ nil
The #set_content_size method is used to set the content size of the HtmlDialog, in logical pixels.
-
#set_file(filename) ⇒ nil
The #set_file method is used to identify a local HTML file to display in the HtmlDialog.
-
#set_html(html_string) ⇒ nil
The #set_html method is used to load a HtmlDialog with a string of provided HTML.
-
#set_on_closed ⇒ Boolean
The #set_on_closed method is used to attach a block that will be executed when a dialog is already in the process of closing, do any last minute operations within this block such as saving the current state.
-
#set_position(left, top) ⇒ true
The #set_position method is used to set the position of the HtmlDialog relative to the screen, in pixels.
-
#set_size(width, height) ⇒ true
The #set_size method is used to set the outer frame size of the HtmlDialog, in pixels.
-
#set_url(url) ⇒ nil
The #set_url method is used to load a HtmlDialog with the content at a specific URL.
-
#show ⇒ nil
The #show method is used to display a non-modal dialog box.
-
#show_modal ⇒ nil
The #show_modal method is used to display a modal dialog box.
-
#visible? ⇒ Boolean
The #visible? method is useful to tell if the dialog is shown and still alive, if the dialog is minimized or not visible on the screen this will still return
true
.
Constructor Details
#initialize(properties) ⇒ UI::HtmlDialog
Prefix preference_key
with something unique to your extension.
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.
The new method is used to create a new HtmlDialog.
In SketchUp 2021.1 use_content_size
was added. When set to true
, width
, height
, min_width
, max width, min_height
, max_height
will represent the size of the content area of the window. This excludes the titlebar and the window frame. When use_content_size
is set to false
(the default value), the size dimensions will represent the outer frame size.
The properties
hash accepts an optional key style
where the value is one of:
UI::HtmlDialog::STYLE_DIALOG
-
HtmlDialog stays at the top of SketchUp.
UI::HtmlDialog::STYLE_WINDOW
-
HtmlDialog can go behind SketchUp and doesn’t disappear when SketchUp looses focus.
UI::HtmlDialog::STYLE_UTILITY
-
HtmlDialog is shown with small titlebar and stays on top of SketchUp.
315 316 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 315 def initialize(properties) end |
Instance Method Details
#add_action_callback(callback_name) {|action_context, *args| ... } ⇒ Boolean
When an HtmlDialog is closed, all callbacks to that instance are cleared. Re-attach them if you need to open the dialog again.
The #add_action_callback method establishes a Ruby callback method that your html dialog can call to perform some function.
Use the sketchup.callback_method_name
to invoke the callback method from your html dialog. Your JavaScript in the html dialog will invoke the callback with the same number of arguments.
The call is asynchronous. JavaScript call might return before Ruby callback even called. Use onCompleted
callback to get notified for completion.
Basic types such as booleans, numbers, strings, arrays and hashes are automatically converted between Ruby and JavaScript.
93 94 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 93 def add_action_callback(callback_name) end |
#bring_to_front ⇒ nil
The #bring_to_front method is used to bring the window to the front, putting it on top of other windows even if its minimized.
110 111 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 110 def bring_to_front end |
#center ⇒ true
The #center method is used to center the HtmlDialog relative to the active model window. If there is no active model window, this function doesn’t do anything.
123 124 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 123 def center end |
#close ⇒ nil
The #close method is used to close a dialog box.
134 135 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 134 def close end |
#execute_script(script) ⇒ nil
The #execute_script method is used to execute a JavaScript string on the html dialog asynchronously.
150 151 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 150 def execute_script(script) end |
#get_content_size ⇒ Array(Integer, Integer)?
The #get_content_size method is used to get the content size of the HtmlDialog, in logical pixels.
164 165 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 164 def get_content_size end |
#get_position ⇒ Array(Integer, Integer)?
The #get_position method is used to get the position of the HtmlDialog relative to the screen, in logical pixels.
178 179 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 178 def get_position end |
#get_size ⇒ Array(Integer, Integer)?
The #get_size method is used to get the outer frame size of the HtmlDialog, in logical pixels.
191 192 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 191 def get_size end |
#set_can_close ⇒ Boolean
The #set_can_close method is used to attach a block that is executed just before closing, this block has to return a boolean, if the block returns false the close will be canceled.
331 332 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 331 def set_can_close end |
#set_content_size(width, height) ⇒ nil
The #set_content_size method is used to set the content size of the HtmlDialog, in logical pixels.
349 350 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 349 def set_content_size(width, height) end |
#set_file(filename) ⇒ nil
The #set_file method is used to identify a local HTML file to display in the HtmlDialog.
364 365 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 364 def set_file(filename) end |
#set_html(html_string) ⇒ nil
The #set_html method is used to load a HtmlDialog with a string of provided HTML.
381 382 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 381 def set_html(html_string) end |
#set_on_closed ⇒ Boolean
The #set_on_closed method is used to attach a block that will be executed when a dialog is already in the process of closing, do any last minute operations within this block such as saving the current state.
394 395 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 394 def set_on_closed end |
#set_position(left, top) ⇒ true
The #set_position method is used to set the position of the HtmlDialog relative to the screen, in pixels.
415 416 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 415 def set_position(left, top) end |
#set_size(width, height) ⇒ true
The #set_size method is used to set the outer frame size of the HtmlDialog, in pixels.
435 436 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 435 def set_size(width, height) end |
#set_url(url) ⇒ nil
The #set_url method is used to load a HtmlDialog with the content at a specific URL. This method allows you to load web sites in a HtmlDialog.
450 451 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 450 def set_url(url) end |
#show ⇒ nil
The #show method is used to display a non-modal dialog box.
461 462 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 461 def show end |
#show_modal ⇒ nil
The #show_modal method is used to display a modal dialog box.
472 473 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 472 def show_modal end |
#visible? ⇒ Boolean
The #visible? method is useful to tell if the dialog is shown and still alive, if the dialog is minimized or not visible on the screen this will still return true
.
491 492 |
# File 'lib/sketchup-api-stubs/stubs/UI/HtmlDialog.rb', line 491 def visible? end |