Class: Iup::Link
Overview
A static control, a kind of label which displays an underlined clickable text. When clicked, the text is opened in the browser as a url.
Example
(1) Display clickable link:
Iup::Link.new('https://www.ruby-lang.org')
(2) Display text instead of link, and custom callback on click:
Iup::Link.new('https://www.ruby-lang.org', 'Ruby Home') do |l|
l.action = ->(url) {
puts "you clicked on #{l.title} with URL: #{url}"
Iup::IGNORE # return DEFAULT if you also want link to be opened
}
end
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action=(callback) ⇒ Object
–.
-
#initialize(url, text = nil) {|_self| ... } ⇒ Link
constructor
Creates a new link instance.
Methods inherited from Label
#alignment, #ellipsis, #expand, #padding, #position, #rastersize, #screenposition, #separator, #spacing, #tip, #title
Methods included from ButtonCallback
Methods included from DragDropAttributes
#dragbegin_cb=, #dragdata_cb=, #dragdatasize_cb=, #dragend_cb=, #dragsource, #dragsourcemove, #dragtypes, #dropdata_cb=, #dropmotion_cb=, #droptarget, #droptypes
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_reader, #define_id_writer, #define_property_attribute, #define_property_reader, #define_property_writer, #define_reader, #define_writer
Methods included from ImageAttributes
#image, #image=, #iminactive, #iminactive=, #impress, #impress=
Methods included from AttributeReference
Methods inherited from Widget
#active, #assign_handle, #bgcolor, #destroy, #enterwindow_cb=, #fgcolor, #font, #getfocus_cb=, #help_cb=, #k_any=, #killfocus_cb=, #leavewindow_cb=, #map_cb=, #maxsize, #minsize, #open_controls, #size, #unmap_cb=, #visible, #wid, #zorder
Methods included from CallbackSetter
Constructor Details
#initialize(url, text = nil) {|_self| ... } ⇒ Link
Creates a new link instance. If a block is given, the new instance is yielded to it.
-
url- the URL to display / follow. -
text- optional text to display in place of URL
27 28 29 30 31 32 |
# File 'lib/wrapped/link.rb', line 27 def initialize url, text=nil @handle = IupLib.IupLink(url, text) # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
44 45 46 47 48 49 50 51 52 |
# File 'lib/wrapped/link.rb', line 44 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 |