Class: UI::HtmlDialog
- 继承于:
-
Object
- Object
- UI::HtmlDialog
概述
Ruby HtmlDialog类允许你从Ruby创建HTML对话框并与之互动。这是在SketchUp内部生成复杂的嵌入式UI的最好方法,但它通常需要HTML和JavaScript的专业知识。
如果你的目标是向你的用户简单地显示一个网站,考虑使用#openURL,这将在他们的默认浏览器中显示一个网页,而不是在SketchUp的一个对话框中。
对话框的左、上、宽、高等尺寸都是以逻辑单位表示的。这意味着你要提供单位,就像他们在一个 "正常 "DPI的显示器上一样。给出的单位将被乘以相同的系数,该系数由scale_factor.
关于使用例子,包括如何从旧的WebDialog类迁移,请参见github.com/SketchUp/htmldialog-examples. 你可以使用Trimble Modus框架,使你的对话框的外观和感觉与SketchUp的对话框一致。
HtmlDialog使用以下版本的CEF(Chromium Embedded Framework)。
- SketchUp 2021.1
-
CEF 88
- SketchUp 2019.0
-
CEF 64
- SketchUp 2018.0
-
CEF 56
- SketchUp 2017.0
-
CEF 52
恒定摘要#
- UI::HtmlDialog::STYLE_WINDOW
- UI::HtmlDialog::STYLE_DIALOG
- UI::HtmlDialog::STYLE_UTILITY
- UI::HtmlDialog::CEF_VERSION
- UI::HtmlDialog::CHROME_VERSION
实例方法总结 崩溃
-
#add_action_callback(callback_name) {|action_context, ...| ... } ⇒ Boolean
该#add_action_callback方法建立了一个Ruby回调方法,你的html对话框可以调用它来执行一些功能。
-
#bring_to_front⇒ nil
该#bring_to_front方法用于将窗口移到前面,即使它已经最小化,也会将其放在其他窗口的上面。
-
#center⇒ true
的#center方法用于使HtmlDialog相对于活动模型窗口居中。
-
#close⇒ nil
该#close方法是用来关闭一个对话框的。
-
#execute_script(script) ⇒ nil
该#execute_script方法是用来在html对话框上异步执行一个JavaScript字符串。
-
#get_content_size⇒ Array(Integer, Integer)?
该#get_content_size方法是用来获取HtmlDialog的内容大小,以逻辑像素为单位。
-
#get_position⇒ Array(Integer, Integer)?
的方法。#get_position方法是用来获取HtmlDialog相对于屏幕的位置,以逻辑像素为单位。
-
#get_size⇒ Array(Integer, Integer)?
的方法。#get_size方法是用来获取HtmlDialog的外框尺寸,单位是逻辑像素。
-
#initialize(properties) ⇒ HtmlDialog
构造函数
新方法用于创建一个新的HtmlDialog。
-
#set_can_close⇒ Boolean
该#set_can_close方法是用来附加一个在关闭前执行的块,这个块必须返回一个布尔值,如果这个块返回错误,关闭将被取消。
-
#set_content_size(width, height) ⇒ nil
这个#set_content_size方法是用来设置HtmlDialog的内容大小,以逻辑像素为单位。
-
#Set_file(文件名) ⇒ nil
该#set_file方法是用来确定一个本地的HTML文件,以便在HtmlDialog中显示。
-
#set_html(html_string) ⇒ nil
的#set_html方法是用来加载一个HtmlDialog,并提供一串HTML。
-
#set_on_closed⇒ Boolean
该#set_on_closed方法用于附加一个块,当对话框已经处于关闭过程中时,该块将被执行,在该块中进行任何最后的操作,如保存当前状态。
-
#set_position(left, top) ⇒ true
的#set_position方法是用来设置HtmlDialog相对于屏幕的位置,单位是像素。
-
#set_size(width, height) ⇒ true
的#set_size方法是用来设置HtmlDialog的外框尺寸,单位是像素。
-
#set_url(url) ⇒ nil
该#set_url方法是用来加载一个HtmlDialog,其内容在一个特定的URL。
-
#show⇒ nil
该#show方法是用来显示一个非模式的对话框。
-
#show_modal⇒ nil
的#show_modal方法用于显示一个模态对话框。
-
#visible?⇒ Boolean
该#visible?方法是用来判断对话框是否被显示并且仍然存在,如果对话框被最小化或者在屏幕上不可见,则仍然会返回
true
.
构造函数的细节
↑#initialize(属性) ⇒HtmlDialog
前缀preference_key
前缀为你的扩展特有的东西。
如果没有保留对HtmlDialog对象的引用,一旦运行垃圾回收,窗口将关闭。这种行为在琐碎的测试代码中可能会引起混淆,但在现实生活中通常不会有什么问题。通常情况下,一个持久的引用,例如一个实例变量,应该被保留下来,以便在用户第二次请求时,将对话框带到前面,而不是创建一个重复的对话框。
新方法用于创建一个新的HtmlDialog。
In SketchUp 2021.1 use_content_size
被添加。当设置为true
,width
,height
,min_width
,max width,min_height
,max_height
将代表窗口的内容区域的大小。这不包括标题栏和窗口框架。当use_content_size
被设置为false
(默认值),大小尺寸将代表外框尺寸。
这些属性
哈希接受一个可选的键风格
其中的值是以下之一。
UI::HtmlDialog::STYLE_DIALOG
-
HtmlDialog会停留在SketchUp的顶部。
UI::HtmlDialog::STYLE_WINDOW
-
HtmlDialog可以走到SketchUp后面,并且在SketchUp失去焦点时不会消失。
UI::HtmlDialog::STYLE_UTILITY
-
HtmlDialog会以小标题栏显示,并保持在SketchUp的顶部。
实例方法细节
↑#add_action_callback(callback_name) {|action_context, ...| ... } ⇒布尔型
当一个HtmlDialog被关闭时,该实例的所有回调都被清除了。如果你需要再次打开该对话框,请重新连接它们。
列表中的#add_action_callback方法建立了一个Ruby回调方法,你的html对话框可以调用它来执行一些功能。
使用sketchup.callback_method_name
来调用html对话框中的回调方法。你在html对话框中的JavaScript将以相同数量的参数调用回调。
该调用是异步的。JavaScript调用可能会在Ruby回调调用之前返回。使用onCompleted
回调来获得完成的通知。
基本类型,如布尔、数字、字符串、数组和哈希值,在Ruby和JavaScript之间自动转换。
↑#bring_to_front⇒nil
的#bring_to_front方法用于将窗口移到前面,即使它被最小化了,也要将它放在其他窗口的上面。
↑#center⇒true
的#centermethod 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.
↑#execute_script(script) ⇒nil
The#execute_scriptmethod is used to execute a JavaScript string on the html dialog asynchronously.
↑#get_content_size⇒Array(Integer, Integer)?
The#get_content_sizemethod is used to get the content size of the HtmlDialog, in logical pixels.
↑#get_position⇒Array(Integer, Integer)?
The#get_positionmethod is used to get the position of the HtmlDialog relative to the screen, in logical pixels.
↑#get_size⇒Array(Integer, Integer)?
The#get_sizemethod is used to get the outer frame size of the HtmlDialog, in logical pixels.
↑#set_can_close⇒Boolean
The#set_can_closemethod 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_sizemethod is used to set the content size of the HtmlDialog, in logical pixels.
↑#set_file(filename) ⇒nil
The#set_filemethod is used to identify a local HTML file to display in the HtmlDialog.
↑#set_html(html_string) ⇒nil
The#set_htmlmethod is used to load a HtmlDialog with a string of provided HTML.
↑#set_on_closed⇒Boolean
The#set_on_closedmethod 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_positionmethod is used to set the position of the HtmlDialog relative to the screen, in pixels.
↑#set_size(width, height) ⇒true
The#set_sizemethod is used to set the outer frame size of the HtmlDialog, in pixels.
↑#set_url(url) ⇒nil
The#set_urlmethod is used to load a HtmlDialog with the content at a specific URL. This method allows you to load web sites in a HtmlDialog.
↑#show_modal⇒nil
The#show_modalmethod is used to display a modal dialog box.