class Iup::Link

A Link is a static control, a kind of Label, which displays an underlined clickable text. When clicked, the Link can open a url.

The control can show the actual link, or an alternative piece of text. A custom action can be provided, which must return DEFAULT to also open the URL, or IGNORE if the URL should not be opened.

For example:

link1 = Link.new 'https://ruby-lang.org'               # <1>

link2 = Link.new 'https://ruby-lang.org', 'Source' do  # <2>
  tip 'Link is https://ruby-lang.org'
end

link3 = Link.new 'https://ruby-lang.org', 'Source' do  # <3>
  action ->(url) {
    puts "you clicked on #{title} with URL: #{url}"
    IGNORE # return DEFAULT if you also want link to be opened
  }
end
  1. Simply displays the URL, and opens it when clicked.

  2. Displays the word “Source” but opens URL when clicked.

  3. Displays the word “Source” but overrides action so the URL is not opened when clicked.

Public Class Methods

new(url, text=nil, &block) click to toggle source

Creates an instance of Link.

url

the URL to display / follow.

text

optional text to display in place of URL

block

optional block to set up link's parameters

# File lib/wrapped/link.rb, line 35
def initialize url, text=nil, &block
  @handle = IupLib.IupLink url, text

  # run any provided block on instance, to set up further attributes
  self.instance_eval &block if block_given?
end

Public Instance Methods

action(callback) click to toggle source

action callback is called when the link is clicked. The action callback takes a single argument, the url of the link. Return IUP_CLOSE to process link. If returns IUP_DEFAULT, or link is not defined, the IupHelp function will be called.

# File lib/wrapped/link.rb, line 49
def action callback
  unless callback.arity == 1
    raise ArgumentError, 'action callback must take 1 argument: the url'
  end
  cb = Proc.new do |ih, url|
    callback.call url 
  end
  define_callback cb, 'ACTION', :s_i
end