Class: Iup::Link
Overview
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
-
Simply displays the URL, and opens it when clicked.
-
Displays the word “Source” but opens URL when clicked.
-
Displays the word “Source” but overrides
actionso the URL is not opened when clicked.
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action(callback) ⇒ Object
action callback is called when the link is clicked.
-
#initialize(url, text = nil, &block) ⇒ Link
constructor
Creates an instance of Link.
Methods included from ButtonCallback
Methods included from DragDropAttributes
#dragbegin_cb, #dragdata_cb, #dragdatasize_cb, #dragend_cb, #dropdata_cb, #dropmotion_cb
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_readonly, #define_id_writeonly, #define_property_attribute, #define_property_writeonly, #define_readonly, #define_writeonly
Methods included from ImageAttributes
Methods included from AttributeReference
Methods inherited from Widget
#assign_handle, #enterwindow_cb, #getfocus_cb, #help_cb, #k_any, #killfocus_cb, #leavewindow_cb, #map_cb, #open_controls, #unmap_cb
Methods included from CallbackSetter
Constructor Details
#initialize(url, text = nil, &block) ⇒ Link
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
35 36 37 38 39 40 |
# 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 |
Instance Method Details
#action(callback) ⇒ Object
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.
49 50 51 52 53 54 55 56 57 |
# 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 |