Class: Iup::Text

Inherits:
Widget show all
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.expand = 'horizontal'
end

(2) a multi-line control, to act more like an editor.

Iup::Text.new do |t|
  t.multiline = 'yes'
  t.expand = '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.expand = 'horizontal'
  t.spin_cb = ->(v){
    puts "spin control is now #{v}"
    Iup::DEFAULT
  }
end

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods included from ButtonCallback

#button_cb=

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

#define_callback

Constructor Details

#initialize {|_self| ... } ⇒ Text

Creates a new instance. If a block is given, the new instance is yielded to it.

Yields:

  • (_self)

Yield Parameters:

  • _self (Iup::Text)

    the object that the method was called on



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

#alignmentObject

:attr: alignment Sets the alignment of text within control, options ‘ALEFT’ / ‘ACENTER’ / ‘ARIGHT’.



52
# File 'lib/wrapped/text.rb', line 52

define_attribute :alignment

#appendObject

:attr_writer: append Appends given string to end of text.



57
# File 'lib/wrapped/text.rb', line 57

define_writer :append

#autohideObject

:attr: autohide If set, scrollbars are only shown if necessary, values ‘yes’ / ‘no’.



62
# File 'lib/wrapped/text.rb', line 62

define_attribute :autohide

#borderObject

:attr: border Sets border around text, values ‘yes’ / ‘no’.



67
# File 'lib/wrapped/text.rb', line 67

define_attribute :border

#canfocusObject

:attr: canfocus If set, the control can gain focus, values ‘yes’ / ‘no’.



72
# File 'lib/wrapped/text.rb', line 72

define_attribute :canfocus

#caretObject

: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

#caretposObject

: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

#clipboardObject

: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

#countObject

:attr_reader: count Number of characters and line-breaks in text.



94
# File 'lib/wrapped/text.rb', line 94

define_reader :count

#expandObject

: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

#formattingObject

: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

#insertObject

: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

#linecountObject

:attr_reader: linecount Returns number of lines of text.



115
# File 'lib/wrapped/text.rb', line 115

define_reader :linecount

#linevalueObject

:attr_reader: linevalue Returns line of text where the caret is.



120
# File 'lib/wrapped/text.rb', line 120

define_reader :linevalue

#maskObject

: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

#multilineObject

:attr: multiline Set multiline text input, values ‘no’ / ‘yes’.



131
# File 'lib/wrapped/text.rb', line 131

define_attribute :multiline

#ncObject

: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

#overwriteObject

:attr: overwrite ‘off’ / ‘on’, used when formatting=yes.



141
# File 'lib/wrapped/text.rb', line 141

define_attribute :overwrite

#paddingObject

:attr: padding Margin in x and y directions, value as “mxn”.



146
# File 'lib/wrapped/text.rb', line 146

define_attribute :padding

#passwordObject

:attr: password ‘yes’ / ‘no’, if set, masks the input text as “*”.



151
# File 'lib/wrapped/text.rb', line 151

define_attribute :password

#positionObject

:attr_reader: position Returns position in pixels within client window as “x,y”.



156
# File 'lib/wrapped/text.rb', line 156

define_reader :position

#rastersizeObject

:attr: rastersize Size in pixels within client window, value as “widthxheight”.



161
# File 'lib/wrapped/text.rb', line 161

define_attribute :rastersize

#readonlyObject

:attr: readonly User cannot change the contents, values ‘yes’ / ‘no’.



166
# File 'lib/wrapped/text.rb', line 166

define_attribute :readonly

#screenpositionObject

:attr_reader: screenposition Returns position in pixels on screen as “x,y”.



171
# File 'lib/wrapped/text.rb', line 171

define_reader :screenposition

#scrollbarObject

: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

#scrolltoObject

: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

#scrolltoposObject

:attr_writer: scrolltopos Scrolls to make character ‘number’ visible.



187
# File 'lib/wrapped/text.rb', line 187

define_writer :scrolltopos

#selectedtextObject

: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

#selectionObject

: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

#selectionposObject

:attr: selectionpos Selects text between character positions: ‘pos1:pos2’ / ‘all’ / ‘none’.



203
# File 'lib/wrapped/text.rb', line 203

define_attribute :selectionpos

#spinObject

: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

#spinalignObject

:attr: spinalign ‘right’ / ‘left’, with respect to the text (GTK always ‘right’).



213
# File 'lib/wrapped/text.rb', line 213

define_attribute :spinalign

#spinautoObject

: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

#spinincObject

:attr: spininc Increment value, defaults to 1.



224
# File 'lib/wrapped/text.rb', line 224

define_attribute :spininc

#spinmaxObject

:attr: spinmax Maximum spin value, defaults to 100.



229
# File 'lib/wrapped/text.rb', line 229

define_attribute :spinmax

#spinminObject

:attr: spinmin Minimum spin value, defaults to 1.



234
# File 'lib/wrapped/text.rb', line 234

define_attribute :spinmin

#spinvalueObject

:attr: spinvalue Current value of spin, defaults to 1.



239
# File 'lib/wrapped/text.rb', line 239

define_attribute :spinvalue

#spinwrapObject

:attr: spinwrap ‘no’ / ‘yes’, automatically wraps spin at ends of range, when set.



244
# File 'lib/wrapped/text.rb', line 244

define_attribute :spinwrap

#tabsizeObject

: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

#tipObject

:attr: tip Tooltip string.



254
# File 'lib/wrapped/text.rb', line 254

define_attribute :tip

#valueObject

: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

#valuemaskedObject

:attr_writer: valuemasked Retrieves or sets the text, applying MASK when setting.



264
# File 'lib/wrapped/text.rb', line 264

define_writer :valuemasked

#visiblecolumnsObject

:attr: visiblecolumns The minimum number of visible columns, defaults to 5.



269
# File 'lib/wrapped/text.rb', line 269

define_attribute :visiblecolumns

#visiblelinesObject

:attr: visiblelines The minimum number of visible lines, when dropdown=no.



274
# File 'lib/wrapped/text.rb', line 274

define_attribute :visiblelines

#wordwrapObject

: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