class Iup::Tabs
Tabs
is a container for multiple widgets, placing the widgets in layers with a single layer visible. The user can change the visible layer by selecting a tab.
Attributes¶ ↑
- clientoffset
-
read-only, returns current offset of box in its client as “widthxheight”.
- clientsize
-
read-only, returns current size of box as “widthxheight”.
- count
-
read-only Returns the number of tabs.
- expand
-
Allows control to fill available space in indicated direction. Values 'no' / 'horizontal' / 'vertical' / 'yes'.
- padding
-
Margin in x and y directions, value as “mxn”.
- position
-
read-only returns position in pixels within client window
- rastersize
-
Size of the control, in pixels, value as “widthxheight”.
- screenposition
-
read-only returns position in pixels on screen as “x,y”.
- showclose
-
'no' / 'yes', shows the 'close' button on each tab. Clicking this hides tab unless
tabclose_cb
defined. - taborientation
-
'horizontal' / 'vertical'.
- tabtype
-
'top' / 'bottom' / 'left' / 'right', indicates position of tabs.
- tip
-
Tooltip string.
Public Class Methods
Creates an instance of the tabs control.
- *widgets
-
one or more child widgets
- block
-
optional block to set up the control's attributes.
# File lib/wrapped/tabs.rb, line 32 def initialize *widgets, &block @handle = IupLib.IupTabs *widget_list(widgets) @widgets = widgets # store the widgets # run any provided block on instance, to set up further attributes self.instance_eval &block if block_given? end
Public Instance Methods
Callback called when the user clicks on some tab using the right mouse button. rightclick_cb
takes a 1-argument callback, the argument being the tab number that was clicked
# File lib/wrapped/tabs.rb, line 96 def rightclick_cb callback unless callback.arity == 1 raise ArgumentError, 'rightclick_cb callback must take 1 argument, the tab number' end cb = Proc.new do |ih, tn| callback.call tn end define_callback cb, 'RIGHTCLICK_CB', :i_i end
Callback called when the user shifts the active tab. tabchange_cb
takes a 2-argument callback, the new selected tab, and the old selected tab.
# File lib/wrapped/tabs.rb, line 109 def tabchange_cb callback unless callback.arity == 2 raise ArgumentError, 'tabchange_cb callback must take 2 argument, the new and old tab handles' end cb = Proc.new do |ih, hnew, hold| new_tab = @widgets.find {|widget| widget.handle.address == hnew.address} old_tab = @widgets.find {|widget| widget.handle.address == hold.address} callback.call new_tab, old_tab end define_callback cb, 'TABCHANGE_CB', :pp_i end
Callback called when the user shifts the active tab. Called only when TABCHANGE_CB is not defined. tabchangepos_cb
takes a 2-argument callback, the new selected tab number and the old selected tab number.
# File lib/wrapped/tabs.rb, line 125 def tabchangepos_cb callback unless callback.arity == 2 raise ArgumentError, 'tabchangepos_cb callback must take 2 argument, the new and old tab numbers' end cb = Proc.new do |ih, tnew, told| callback.call tnew, told end define_callback cb, 'TABCHANGEPOS_CB', :ii_i end
Callback called when the user clicks on the close button (since 3.10). Called only when SHOWCLOSE=Yes. Callback takes one argument, the tab number.
# File lib/wrapped/tabs.rb, line 138 def tabclose_cb callback unless callback.arity == 1 raise ArgumentError, 'tabclose_cb callback must take 1 argument, the tab number' end cb = Proc.new do |ih, tn| callback.call tn end define_callback cb, 'TABCLOSE_CB', :i_i end
Sets the title of a tab:
- index
-
the index of the tab (0-indexed)
- title
-
text to use for the title
- image
-
optional image
# File lib/wrapped/tabs.rb, line 62 def tabtitle index, title, image=nil IupLib.IupSetAttribute @handle, "TABTITLE#{index}", title attribute_reference "TABIMAGE#{index}", ImageWidget, image end
If val given, sets visibility of tab index, else returns its visibility.
# File lib/wrapped/tabs.rb, line 70 def tabvisible index, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "TABVISIBLE#{index}").first else IupLib.IupSetAttribute @handle, "TABVISIBLE#{index}", val end end
If val given, changes visible tab to its position (0-indexed). Otherwise, returns currently visible tab position.
# File lib/wrapped/tabs.rb, line 82 def valuepos val=nil if val.nil? result = IupLib.IupGetAttribute(@handle, 'VALUEPOS').first result.to_i else IupLib.IupSetAttribute @handle, 'VALUEPOS', val.to_s end end