class Iup::Text
A Text
control is one of the more complex controls, because it can be displayed in a variety of ways:
(1) a single line, for inputting a single line of text.
Text.new do expand 'horizontal' nc 5 end
(2) a multi-line control, to act more like an editor.
Text.new do multiline 'yes' expand 'yes' size '200x100' end
(3) a spin box, for selecting one of several values.
Text.new do spin 'yes' spinmax 20 spinmin 10 expand 'horizontal' spin_cb ->(v){ puts "spin control is now #{v}" DEFAULT } end
Attributes¶ ↑
- alignment
-
Sets the alignment of text within control, options ALEFT, ACENTER, ARIGHT or none.
- append
-
write-only appends given string to end of text.
- autohide
-
If set, scrollbars are only shown if necessary, values 'yes' / 'no'.
- border
-
Sets border around text, values 'yes' / 'no'.
- canfocus
-
If set, the control can gain focus, values 'yes' / 'no'.
- caret
-
'col' in single-line mode, sets column number of caret; 'lin,col' in multi-line mode, sets line and column number of caret.
- caretpos
-
Index of character of the insertion point.
- clipboard
-
'clear' / 'copy' / 'cut' / 'paste', write-only access the clipboard with the current selection.
- count
-
read-only number of characters in text.
- expand
-
Allows control to fill available space in indicated direction. Values 'no' / 'horizontal' / 'vertical' / 'yes'.
- formatting
-
Set to 'yes' in multi-line mode, to allow control to use formatting of text.
- insert
-
write-only Places a given string at current caret position, overwriting any current selection.
- linecount
-
read-only returns number of lines of text.
- linevalue
-
read-only returns line of text where the caret is.
- mask
-
Defines a mask to filter text input.
- multiline
-
'no' / 'yes'
- nc
-
Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
- overwrite
-
'off' / 'on', used when formatting=yes.
- padding
-
Margin in x and y directions, value as “mxn”.
- password
-
'yes' / 'no', if set, masks the input text as “*”.
- position
-
read-only returns position in pixels within client window as “x,y”.
- rastersize
-
Size of the list, in pixels, value as “widthxheight”.
- readonly
-
'yes' / 'no'.
- screenposition
-
read-only returns position in pixels on screen as “x,y”.
- scrollbar
-
In multi-line mode, selects 'no' / 'horizontal' / 'vertical' / 'yes' (for both) scrollbars.
- scrollto
-
write-only 'col' Scrolls to make given column number visible, in single-line mode. 'lin/col' Scrolls to make line and column number visible, in multi-line mode.
- scrolltopos
-
write-only Scrolls to make character 'number' visible.
- selectedtext
-
Reads or overwrites the current selection. Does nothing if no text is selected.
- selection
-
Selects text as 'col1:col2' (single-line) / 'lin1,col1:lin2,col2' (multi-line) / 'all' / 'none'.
- selectionpos
-
Selects text between character positions: 'pos1:pos2' / 'all' / 'none'.
- spin
-
'no' / 'yes', attaches a spin control to the text box.
- spinalign
-
'right' / 'left', with respect to the text (GTK always 'right').
- spinauto
-
'yes' / 'no', updates value of control when spin buttons used. When 'no', “spin_cb” must adjust the value.
- spininc
-
Increment value, defaults to 1.
- spinmax
-
Maximum spin value, defaults to 100.
- spinmin
-
Minimum spin value, defaults to 1.
- spinvalue
-
Current value of spin, defaults to 1.
- spinwrap
-
'no' / 'yes', automatically wraps spin at ends of range, when set.
- tabsize
-
In multi-line mode, controls number of spaces used for a tab, defaults to 8.
- tip
-
Tooltip string.
- value
-
Retrieves or sets the text.
- valuemasked
-
Retrieves or sets the text, applying
MASK
when setting. - visiblecolumns
-
The minimum number of visible columns, defaults to 5.
- visiblelines
-
The minimum number of visible lines, when dropdown=no.
- wordwrap
-
'no' / 'yes', when multiline=yes.
Public Class Methods
# File lib/wrapped/text.rb, line 102 def initialize &block @handle = IupLib.IupText nil # run any provided block on instance, to set up further attributes self.instance_eval &block if block_given? end
Public Instance Methods
Action generated when the text is edited, but before its value is actually changed. action takes a 2-argument callback, the character typed and the new value.
# File lib/wrapped/text.rb, line 160 def action callback unless callback.arity == 2 raise ArgumentError, 'action callback must take 2 argument: (character, new-text)' end cb = Proc.new do |ih, c, text| callback.call c, text end define_callback cb, 'ACTION', :is_i end
Action generated when the caret/cursor position is changed. caret_cb
takes a callback which accepts 3 arguments (line, column, position) of caret
# File lib/wrapped/text.rb, line 174 def caret_cb callback unless callback.arity == 3 raise ArgumentError, 'caret_cb callback must take 3 arguments: (line, column, position)' end cb = Proc.new do |ih, lin, col, pos| callback.call lin, col, pos end define_callback cb, 'CARET_CB', :iii_i end
Action generated when the mouse is moved. Callback takes 3 arguments: (x, y, state)
- x
-
x position of mouse
- y
-
y position of mouse
- state
-
status of mouse buttons and certain keyboard keys at the moment the event was generated.
# File lib/wrapped/text.rb, line 192 def motion_cb callback unless callback.arity == 3 raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)' end cb = Proc.new do |ih, x, y, state| callback.call x, y, state end define_callback cb, 'MOTION_CB', :iis_i end
Action generated when a spin button is pressed. Valid only when SPIN=YES. spin takes a 1-argument callback, the value of spin.
# File lib/wrapped/text.rb, line 204 def spin_cb callback unless callback.arity == 1 raise ArgumentError, 'spin_cb callback must take 1 argument, the value' end cb = Proc.new do |ih, val| callback.call val end define_callback cb, 'SPIN_CB', :i_i end
Called after the value was interactively changed by the user.
# File lib/wrapped/text.rb, line 215 def valuechanged_cb callback unless callback.arity.zero? raise ArgumentError, 'valuechanged_cb callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'VALUECHANGED_CB', :plain end