Class: Iup::Tabs

Inherits:
Widget show all
Includes:
AttributeReference
Defined in:
lib/wrapped/tabs.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods included from AttributeReference

#attribute_reference

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 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 CallbackSetter

#define_callback

Constructor Details

#initialize(*widgets, &block) ⇒ Tabs

Creates an instance of the tabs control.

*widgets

one or more child widgets

block

optional block to set up the control’s attributes.



32
33
34
35
36
37
38
# 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

Instance Method Details

#countObject

:nodoc:



45
46
47
48
# File 'lib/wrapped/tabs.rb', line 45

def count # :nodoc:
  result = IupLib.IupGetAttribute(@handle, 'COUNT').first
  return result.to_i
end

#rightclick_cb(callback) ⇒ Object

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



96
97
98
99
100
101
102
103
104
# 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

#tabchange_cb(callback) ⇒ Object

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.



109
110
111
112
113
114
115
116
117
118
119
# 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

#tabchangepos_cb(callback) ⇒ Object

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.



125
126
127
128
129
130
131
132
133
# 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

#tabclose_cb(callback) ⇒ Object

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.



138
139
140
141
142
143
144
145
146
# 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

#tabtitle(index, title, image = nil) ⇒ Object

Sets the title of a tab:

index

the index of the tab (0-indexed)

title

text to use for the title

image

optional image



62
63
64
65
# 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

#tabvisible(index, val = nil) ⇒ Object

If val given, sets visibility of tab index, else returns its visibility.



70
71
72
73
74
75
76
# 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

#valuepos(val = nil) ⇒ Object

If val given, changes visible tab to its position (0-indexed). Otherwise, returns currently visible tab position.



82
83
84
85
86
87
88
89
# 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