ModraUp Ruby API Documentation Ruby API Reference

Class: UI::HtmlDialog

Inherits:
Object
  • Object
show all

Overview

Embedded CEF HTML window. Will raise an error during #initialize if there is no UI bridge.

Examples:

dlg = UI::HtmlDialog.new(dialog_title: "Hi", width: 400, height: 300)
dlg.set_html("<html><body>hello</body></html>")
dlg.show

Constants # collapse

UI::HtmlDialog::STYLE_DIALOG

STYLE_DIALOG = 0

Dialog box style.

Returns:

  • (Integer)

Examples:

UI::HtmlDialog.new(style: UI::HtmlDialog::STYLE_DIALOG)
UI::HtmlDialog::STYLE_WINDOW

STYLE_WINDOW = 1

Ordinary window style.

Returns:

  • (Integer)

Examples:

UI::HtmlDialog::STYLE_WINDOW  #=> 1
UI::HtmlDialog::STYLE_UTILITY

STYLE_UTILITY = 2

Utility window style.

Returns:

  • (Integer)

Examples:

UI::HtmlDialog::STYLE_UTILITY  #=> 2
UI::HtmlDialog::CEF_VERSION

Embedded CEF version string (may be rewritten by the host after startup).

Returns:

  • (String)

Examples:

UI::HtmlDialog::CEF_VERSION
UI::HtmlDialog::CHROME_VERSION

Embedded Chrome version string (may be rewritten by the host after startup).

Returns:

  • (String)

Examples:

UI::HtmlDialog::CHROME_VERSION

Class Method Summary # collapse

  • .new(properties = {}) ⇒ UI::HtmlDialog
    Hash keys: dialog_title / preferences_key / width / height / left / top / min_width / min_height / max_width / max_height / resizable / scrollable / use_content_size / style.

Instance Method Summary # collapse

Class Method Details

HtmlDialog.new(properties = {}) ⇒ dialog

Hash keys: dialog_title / preferences_key / width / height / left / top / min_width / min_height / max_width / max_height / resizable / scrollable / use_content_size / style.

Parameters:

  • properties (Hash)

Returns:

  • (UI::HtmlDialog)

Raises:

  • [RuntimeError] No UI bridge (headless test)

Examples:

UI::HtmlDialog.new(dialog_title: "Demo", width: 320, height: 240)

Instance Method Details

dialog.set_html(html) ⇒ nil

Load the HTML string.

Parameters:

  • html (String)

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.set_html("<p>hi</p>")

dialog.set_file(path) ⇒ nil

Load from a local file.

Parameters:

  • path (String)

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.set_file(File.join(__dir__, "ui.html"))

dialog.set_url(url) ⇒ nil

Load the URL.

Parameters:

  • url (String)

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.set_url("https://example.com")

dialog.show ⇒ nil

Non-modal display.

Returns:

  • (nil)

Examples:

dlg = UI::HtmlDialog.new
dlg.set_html("<p>hi</p>")
dlg.show

dialog.show_modal ⇒ nil

Shows the dialog modally. Afterward, #hide is unavailable.

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.show_modal

dialog.hide ⇒ nil

Hide the non-modal dialog box.

Returns:

  • (nil)

Raises:

  • [ArgumentError] Current is modal.

Examples:

dlg = UI::HtmlDialog.new
dlg.show
dlg.hide

dialog.close ⇒ nil

Close and destroy.

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.close

dialog.visible? ⇒ Boolean

Visibility.

Returns:

  • (Boolean)

Examples:

UI::HtmlDialog.new.visible?

dialog.bring_to_front ⇒ nil

Bring to front.

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.bring_to_front

dialog.center ⇒ true

Center in the viewport.

Returns:

  • (true)

Examples:

UI::HtmlDialog.new.center

dialog.set_size(width, height) ⇒ true

Set the window size.

Parameters:

  • width (Integer)
  • height (Integer)

Returns:

  • (true)

Examples:

UI::HtmlDialog.new.set_size(400, 300)

dialog.get_size ⇒ Array<Integer>, nil

[width, height]。

Returns:

  • (Array<Integer>, nil)

Examples:

UI::HtmlDialog.new.get_size

dialog.set_position(left, top) ⇒ true

Set the window position.

Parameters:

  • left (Integer)
  • top (Integer)

Returns:

  • (true)

Examples:

UI::HtmlDialog.new.set_position(80, 80)

dialog.get_position ⇒ Array<Integer>, nil

[left, top]。

Returns:

  • (Array<Integer>, nil)

Examples:

UI::HtmlDialog.new.get_position

dialog.get_content_size ⇒ Array<Integer>, nil

Size of the content area.

Returns:

  • (Array<Integer>, nil)

Examples:

UI::HtmlDialog.new.get_content_size

dialog.set_content_size(width, height) ⇒ nil

Set the content area size.

Parameters:

  • width (Integer)
  • height (Integer)

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.set_content_size(400, 300)

dialog.execute_script(script) ⇒ nil

Execute JavaScript in the page.

Parameters:

  • script (String)

Returns:

  • (nil)

Examples:

UI::HtmlDialog.new.execute_script("console.log(1)")

dialog.add_action_callback(name) {|context, *args| } ⇒ true

Register a JS-callable callback. The block's first parameter is currently nil.

Parameters:

  • name (String)

Returns:

  • (true)

Yields:

  • @yieldparam context [nil]

Raises:

  • [ArgumentError] No block provided

Examples:

dlg = UI::HtmlDialog.new
dlg.add_action_callback("ok") { |_, value| puts value }

dialog.set_on_closed { } ⇒ true

A block to be called when the dialog is closed.

Returns:

  • (true)

Raises:

  • [ArgumentError] No block provided

Examples:

UI::HtmlDialog.new.set_on_closed { puts "closed" }

dialog.set_can_close { } ⇒ true

Returns false to prevent closing.

Returns:

  • (true)

Yields:

  • @yieldreturn [Boolean]

Raises:

  • [ArgumentError] No block provided

Examples:

UI::HtmlDialog.new.set_can_close { true }