Class: MittensUi::WebLink

Inherits:
Core
  • Object
show all
Defined in:
lib/mittens_ui/web_link.rb

Overview

A clickable hyperlink widget that opens a URL in the user’s default browser. Wraps Gtk::LinkButton.

Examples:

Basic usage

MittensUi::WebLink.new("Open Google", "https://google.com")

With layout options

MittensUi::WebLink.new(
  "Docs",
  "https://docs.example.com",
  top: 10,
  bottom: 10,
  width: :half
)

Instance Attribute Summary collapse

Attributes inherited from Core

#core_widget

Instance Method Summary collapse

Methods inherited from Core

#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #render, #shortcuts, #show

Methods included from Helpers

#icon_map, #list_system_icons, #set_margin_from_opts_for

Constructor Details

#initialize(name, url, options = {}) ⇒ WebLink

Creates a new WebLink widget.

Parameters:

  • name (String)

    The visible label of the link

  • url (String)

    The URL to open when clicked

  • options (Hash) (defaults to: {})

    configuration options



40
41
42
43
44
45
# File 'lib/mittens_ui/web_link.rb', line 40

def initialize(name, url, options = {})
  @name = name || ''
  @url  = url  || ''
  @web_link = Gtk::LinkButton.new(@url, @name)
  super(@web_link, options)
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



33
34
35
# File 'lib/mittens_ui/web_link.rb', line 33

def url
  @url
end

Instance Method Details

#open_urlvoid

This method returns an undefined value.

Opens the set @url link in a web browser.



50
51
52
53
# File 'lib/mittens_ui/web_link.rb', line 50

def open_url
  launcher = Gtk::UriLauncher.new(@url)
  launcher.launch
end