Class: Iup::Text
- Includes:
- ButtonCallback, DragDropAttributes
- Defined in:
- lib/wrapped/text.rb
Overview
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.
Iup::Text.new do |t|
t. = 'horizontal'
end
(2) a multi-line control, to act more like an editor.
Iup::Text.new do |t|
t.multiline = 'yes'
t. = 'yes'
t.size = '200x100'
end
(3) a spin box, for selecting one of several values: this example supports the range 10 to 20 and reports the current value as it changes.
Iup::Text.new do |t|
t.spin = 'yes'
t.spinmax = 20
t.spinmin = 10
t. = 'horizontal'
t.spin_cb = ->(v){
puts "spin control is now #{v}"
Iup::DEFAULT
}
end
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action=(callback) ⇒ Object
–.
-
#alignment ⇒ Object
:attr: alignment Sets the alignment of text within control, options ‘ALEFT’ / ‘ACENTER’ / ‘ARIGHT’.
-
#append ⇒ Object
:attr_writer: append Appends given string to end of text.
-
#autohide ⇒ Object
:attr: autohide If set, scrollbars are only shown if necessary, values ‘yes’ / ‘no’.
-
#border ⇒ Object
:attr: border Sets border around text, values ‘yes’ / ‘no’.
-
#canfocus ⇒ Object
:attr: canfocus If set, the control can gain focus, values ‘yes’ / ‘no’.
-
#caret ⇒ Object
:attr: caret Character position of insertion point: + ‘col’ in single-line mode, sets column number of caret; + ‘lin,col’ in multi-line mode, sets line and column number of caret.
-
#caret_cb=(callback) ⇒ Object
–.
-
#caretpos ⇒ Object
:attr: caretpos Index of character of the insertion point: uses a 0-based index of entire text value.
-
#clipboard ⇒ Object
:attr_writer: clipboard ‘clear’ / ‘copy’ / ‘cut’ / ‘paste’, access the clipboard with the current selection.
-
#count ⇒ Object
:attr_reader: count Number of characters and line-breaks in text.
-
#expand ⇒ Object
:attr: expand Allows control to fill available space in indicated direction.
-
#formatting ⇒ Object
:attr: formatting Set to ‘yes’ in multi-line mode, to allow control to use formatting of text.
-
#initialize {|_self| ... } ⇒ Text
constructor
Creates a new instance.
-
#insert ⇒ Object
:attr_writer: insert Places a given string at current caret position, overwriting any current selection.
-
#linecount ⇒ Object
:attr_reader: linecount Returns number of lines of text.
-
#linevalue ⇒ Object
:attr_reader: linevalue Returns line of text where the caret is.
-
#mask ⇒ Object
:attr: mask Defines a mask to filter text input.
-
#motion_cb=(callback) ⇒ Object
–.
-
#multiline ⇒ Object
:attr: multiline Set multiline text input, values ‘no’ / ‘yes’.
-
#nc ⇒ Object
:attr: nc Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
-
#overwrite ⇒ Object
:attr: overwrite ‘off’ / ‘on’, used when formatting=yes.
-
#padding ⇒ Object
:attr: padding Margin in x and y directions, value as “mxn”.
-
#password ⇒ Object
:attr: password ‘yes’ / ‘no’, if set, masks the input text as “*”.
-
#position ⇒ Object
:attr_reader: position Returns position in pixels within client window as “x,y”.
-
#rastersize ⇒ Object
:attr: rastersize Size in pixels within client window, value as “widthxheight”.
-
#readonly ⇒ Object
:attr: readonly User cannot change the contents, values ‘yes’ / ‘no’.
-
#screenposition ⇒ Object
:attr_reader: screenposition Returns position in pixels on screen as “x,y”.
-
#scrollbar ⇒ Object
:attr: scrollbar In multi-line mode, selects ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’ (for both) scrollbars.
-
#scrollto ⇒ Object
:attr_writer: scrollto * ‘col’ Scrolls to make given column number visible, in single-line mode.
-
#scrolltopos ⇒ Object
:attr_writer: scrolltopos Scrolls to make character ‘number’ visible.
-
#selectedtext ⇒ Object
:attr: selectedtext Reads or overwrites the current selection.
-
#selection ⇒ Object
:attr: selection Selects text as ‘col1:col2’ (single-line) / ‘lin1,col1:lin2,col2’ (multi-line) / ‘all’ / ‘none’.
-
#selectionpos ⇒ Object
:attr: selectionpos Selects text between character positions: ‘pos1:pos2’ / ‘all’ / ‘none’.
-
#spin ⇒ Object
:attr: spin ‘no’ / ‘yes’, attaches a spin control to the text box.
-
#spin_cb=(callback) ⇒ Object
–.
-
#spinalign ⇒ Object
:attr: spinalign ‘right’ / ‘left’, with respect to the text (GTK always ‘right’).
-
#spinauto ⇒ Object
:attr: spinauto ‘yes’ / ‘no’, updates value of control when spin buttons used.
-
#spininc ⇒ Object
:attr: spininc Increment value, defaults to 1.
-
#spinmax ⇒ Object
:attr: spinmax Maximum spin value, defaults to 100.
-
#spinmin ⇒ Object
:attr: spinmin Minimum spin value, defaults to 1.
-
#spinvalue ⇒ Object
:attr: spinvalue Current value of spin, defaults to 1.
-
#spinwrap ⇒ Object
:attr: spinwrap ‘no’ / ‘yes’, automatically wraps spin at ends of range, when set.
-
#tabsize ⇒ Object
:attr: tabsize In multi-line mode, controls number of spaces used for a tab, defaults to 8.
-
#tip ⇒ Object
:attr: tip Tooltip string.
-
#value ⇒ Object
:attr: value Retrieves or sets the text.
-
#valuechanged_cb=(callback) ⇒ Object
–.
-
#valuemasked ⇒ Object
:attr_writer: valuemasked Retrieves or sets the text, applying
MASKwhen setting. -
#visiblecolumns ⇒ Object
:attr: visiblecolumns The minimum number of visible columns, defaults to 5.
-
#visiblelines ⇒ Object
:attr: visiblelines The minimum number of visible lines, when dropdown=no.
-
#wordwrap ⇒ Object
:attr: wordwrap Forces a word wrap of lines longer than width of control.
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 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 {|_self| ... } ⇒ Text
Creates a new instance. If a block is given, the new instance is yielded to it.
40 41 42 43 44 45 |
# File 'lib/wrapped/text.rb', line 40 def initialize @handle = IupLib.IupText(nil) # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
295 296 297 298 299 300 301 302 303 |
# File 'lib/wrapped/text.rb', line 295 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 |
#alignment ⇒ Object
:attr: alignment Sets the alignment of text within control, options ‘ALEFT’ / ‘ACENTER’ / ‘ARIGHT’.
52 |
# File 'lib/wrapped/text.rb', line 52 define_attribute :alignment |
#append ⇒ Object
:attr_writer: append Appends given string to end of text.
57 |
# File 'lib/wrapped/text.rb', line 57 define_writer :append |
#autohide ⇒ Object
:attr: autohide If set, scrollbars are only shown if necessary, values ‘yes’ / ‘no’.
62 |
# File 'lib/wrapped/text.rb', line 62 define_attribute :autohide |
#border ⇒ Object
:attr: border Sets border around text, values ‘yes’ / ‘no’.
67 |
# File 'lib/wrapped/text.rb', line 67 define_attribute :border |
#canfocus ⇒ Object
:attr: canfocus If set, the control can gain focus, values ‘yes’ / ‘no’.
72 |
# File 'lib/wrapped/text.rb', line 72 define_attribute :canfocus |
#caret ⇒ Object
:attr: caret Character position of insertion point: + ‘col’ in single-line mode, sets column number of caret; + ‘lin,col’ in multi-line mode, sets line and column number of caret.
79 |
# File 'lib/wrapped/text.rb', line 79 define_attribute :caret |
#caret_cb=(callback) ⇒ Object
–
318 319 320 321 322 323 324 325 326 |
# File 'lib/wrapped/text.rb', line 318 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 |
#caretpos ⇒ Object
:attr: caretpos Index of character of the insertion point: uses a 0-based index of entire text value.
84 |
# File 'lib/wrapped/text.rb', line 84 define_attribute :caretpos |
#clipboard ⇒ Object
:attr_writer: clipboard ‘clear’ / ‘copy’ / ‘cut’ / ‘paste’, access the clipboard with the current selection.
89 |
# File 'lib/wrapped/text.rb', line 89 define_writer :clipboard |
#count ⇒ Object
:attr_reader: count Number of characters and line-breaks in text.
94 |
# File 'lib/wrapped/text.rb', line 94 define_reader :count |
#expand ⇒ Object
:attr: expand Allows control to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
100 |
# File 'lib/wrapped/text.rb', line 100 define_attribute :expand |
#formatting ⇒ Object
:attr: formatting Set to ‘yes’ in multi-line mode, to allow control to use formatting of text.
105 |
# File 'lib/wrapped/text.rb', line 105 define_attribute :formatting |
#insert ⇒ Object
:attr_writer: insert Places a given string at current caret position, overwriting any current selection.
110 |
# File 'lib/wrapped/text.rb', line 110 define_writer :insert |
#linecount ⇒ Object
:attr_reader: linecount Returns number of lines of text.
115 |
# File 'lib/wrapped/text.rb', line 115 define_reader :linecount |
#linevalue ⇒ Object
:attr_reader: linevalue Returns line of text where the caret is.
120 |
# File 'lib/wrapped/text.rb', line 120 define_reader :linevalue |
#mask ⇒ Object
:attr: mask Defines a mask to filter text input. See pre-defined masks.
126 |
# File 'lib/wrapped/text.rb', line 126 define_attribute :mask |
#motion_cb=(callback) ⇒ Object
–
337 338 339 340 341 342 343 344 345 |
# File 'lib/wrapped/text.rb', line 337 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 |
#multiline ⇒ Object
:attr: multiline Set multiline text input, values ‘no’ / ‘yes’.
131 |
# File 'lib/wrapped/text.rb', line 131 define_attribute :multiline |
#nc ⇒ Object
:attr: nc Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
136 |
# File 'lib/wrapped/text.rb', line 136 define_attribute :nc |
#overwrite ⇒ Object
:attr: overwrite ‘off’ / ‘on’, used when formatting=yes.
141 |
# File 'lib/wrapped/text.rb', line 141 define_attribute :overwrite |
#padding ⇒ Object
:attr: padding Margin in x and y directions, value as “mxn”.
146 |
# File 'lib/wrapped/text.rb', line 146 define_attribute :padding |
#password ⇒ Object
:attr: password ‘yes’ / ‘no’, if set, masks the input text as “*”.
151 |
# File 'lib/wrapped/text.rb', line 151 define_attribute :password |
#position ⇒ Object
:attr_reader: position Returns position in pixels within client window as “x,y”.
156 |
# File 'lib/wrapped/text.rb', line 156 define_reader :position |
#rastersize ⇒ Object
:attr: rastersize Size in pixels within client window, value as “widthxheight”.
161 |
# File 'lib/wrapped/text.rb', line 161 define_attribute :rastersize |
#readonly ⇒ Object
:attr: readonly User cannot change the contents, values ‘yes’ / ‘no’.
166 |
# File 'lib/wrapped/text.rb', line 166 define_attribute :readonly |
#screenposition ⇒ Object
:attr_reader: screenposition Returns position in pixels on screen as “x,y”.
171 |
# File 'lib/wrapped/text.rb', line 171 define_reader :screenposition |
#scrollbar ⇒ Object
:attr: scrollbar In multi-line mode, selects ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’ (for both) scrollbars.
176 |
# File 'lib/wrapped/text.rb', line 176 define_attribute :scrollbar |
#scrollto ⇒ Object
:attr_writer: scrollto
-
‘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.
182 |
# File 'lib/wrapped/text.rb', line 182 define_writer :scrollto |
#scrolltopos ⇒ Object
:attr_writer: scrolltopos Scrolls to make character ‘number’ visible.
187 |
# File 'lib/wrapped/text.rb', line 187 define_writer :scrolltopos |
#selectedtext ⇒ Object
:attr: selectedtext Reads or overwrites the current selection. Does nothing if no text is selected.
193 |
# File 'lib/wrapped/text.rb', line 193 define_attribute :selectedtext |
#selection ⇒ Object
:attr: selection Selects text as ‘col1:col2’ (single-line) / ‘lin1,col1:lin2,col2’ (multi-line) / ‘all’ / ‘none’.
198 |
# File 'lib/wrapped/text.rb', line 198 define_attribute :selection |
#selectionpos ⇒ Object
:attr: selectionpos Selects text between character positions: ‘pos1:pos2’ / ‘all’ / ‘none’.
203 |
# File 'lib/wrapped/text.rb', line 203 define_attribute :selectionpos |
#spin ⇒ Object
:attr: spin ‘no’ / ‘yes’, attaches a spin control to the text box.
208 |
# File 'lib/wrapped/text.rb', line 208 define_attribute :spin |
#spin_cb=(callback) ⇒ Object
–
355 356 357 358 359 360 361 362 363 |
# File 'lib/wrapped/text.rb', line 355 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 |
#spinalign ⇒ Object
:attr: spinalign ‘right’ / ‘left’, with respect to the text (GTK always ‘right’).
213 |
# File 'lib/wrapped/text.rb', line 213 define_attribute :spinalign |
#spinauto ⇒ Object
:attr: spinauto ‘yes’ / ‘no’, updates value of control when spin buttons used. When ‘no’, “spin_cb” must adjust the value.
219 |
# File 'lib/wrapped/text.rb', line 219 define_attribute :spinauto |
#spininc ⇒ Object
:attr: spininc Increment value, defaults to 1.
224 |
# File 'lib/wrapped/text.rb', line 224 define_attribute :spininc |
#spinmax ⇒ Object
:attr: spinmax Maximum spin value, defaults to 100.
229 |
# File 'lib/wrapped/text.rb', line 229 define_attribute :spinmax |
#spinmin ⇒ Object
:attr: spinmin Minimum spin value, defaults to 1.
234 |
# File 'lib/wrapped/text.rb', line 234 define_attribute :spinmin |
#spinvalue ⇒ Object
:attr: spinvalue Current value of spin, defaults to 1.
239 |
# File 'lib/wrapped/text.rb', line 239 define_attribute :spinvalue |
#spinwrap ⇒ Object
:attr: spinwrap ‘no’ / ‘yes’, automatically wraps spin at ends of range, when set.
244 |
# File 'lib/wrapped/text.rb', line 244 define_attribute :spinwrap |
#tabsize ⇒ Object
:attr: tabsize In multi-line mode, controls number of spaces used for a tab, defaults to 8.
249 |
# File 'lib/wrapped/text.rb', line 249 define_attribute :tabsize |
#tip ⇒ Object
:attr: tip Tooltip string.
254 |
# File 'lib/wrapped/text.rb', line 254 define_attribute :tip |
#value ⇒ Object
:attr: value Retrieves or sets the text.
259 |
# File 'lib/wrapped/text.rb', line 259 define_attribute :value |
#valuechanged_cb=(callback) ⇒ Object
–
372 373 374 375 376 377 378 379 380 |
# File 'lib/wrapped/text.rb', line 372 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 |
#valuemasked ⇒ Object
:attr_writer: valuemasked Retrieves or sets the text, applying MASK when setting.
264 |
# File 'lib/wrapped/text.rb', line 264 define_writer :valuemasked |
#visiblecolumns ⇒ Object
:attr: visiblecolumns The minimum number of visible columns, defaults to 5.
269 |
# File 'lib/wrapped/text.rb', line 269 define_attribute :visiblecolumns |
#visiblelines ⇒ Object
:attr: visiblelines The minimum number of visible lines, when dropdown=no.
274 |
# File 'lib/wrapped/text.rb', line 274 define_attribute :visiblelines |
#wordwrap ⇒ Object
:attr: wordwrap Forces a word wrap of lines longer than width of control. Values ‘no’ / ‘yes’, when multiline=yes.
280 |
# File 'lib/wrapped/text.rb', line 280 define_attribute :wordwrap |