Class: RubyCurses::Field
- Defined in:
- lib/rbcurse/core/widgets/rwidget.rb
Overview
Text edit field NOTE: To get value use getvalue() TODO - test text_variable TODO: some methods should return self, so chaining can be done. Not sure if the return value of the
fire_handler is being checked.
NOTE: i have just added repain_required check in Field before repaint
this may mean in some places field does not paint. repaint_require will have to be set
to true in those cases. this was since field was overriding a popup window that was not modal.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
actual buffer being used for storage.
-
#datatype ⇒ Object
attr_reader :curpos # cursor position in buffer current, in WIDGET.
- #field_col ⇒ Object readonly
- #form ⇒ Object readonly
-
#handler ⇒ Object
readonly
event handler.
-
#original_value ⇒ Object
readonly
value on entering field.
-
#overwrite_mode ⇒ Object
true or false INSERT OVERWRITE MODE.
-
#type(dtype) ⇒ Object
readonly
define a datatype, currently only influences chars allowed integer and float.
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
-
#addcol(num) ⇒ Object
add a column to cursor position.
-
#cursor_backward ⇒ Object
$log.debug “ crusor FORWARD cp:#@curpos pcol:#@pcol b.l:#@[email protected] d_l:#@display_length fc:#@[email protected]”.
-
#cursor_end ⇒ Object
goto end of field, “end” is a keyword so could not use it.
- #cursor_forward ⇒ Object
-
#cursor_home ⇒ Object
position cursor at start of field.
- #delete_at(index = @curpos) ⇒ Object
-
#delete_curr_char ⇒ Object
# this is perfect if not scrolling, but now needs changes if @curpos > 0 @curpos -= 1 addcol -1 end.
- #delete_eol ⇒ Object
- #delete_prev_char ⇒ Object
-
#getvalue ⇒ Object
converts back into original type changed to convert on 2009-01-06 23:39.
-
#handle_key(ch) ⇒ Object
field.
- #init_vars ⇒ Object
-
#initialize(form = nil, config = {}, &block) ⇒ Field
constructor
A new instance of Field.
- #map_keys ⇒ Object
-
#modified? ⇒ Boolean
overriding widget, check for value change 2009-01-18 12:25.
-
#on_enter ⇒ Object
save original value on enter, so we can check for modified.
-
#on_leave ⇒ Object
upon leaving a field returns false if value not valid as per values or valid_regex 2008-12-22 12:40 if null_allowed, don’t validate, but do fire_handlers.
-
#position_label ⇒ Object
FIXME this may not work since i have disabled -1, now i do not set row and col.
-
#putc(c) ⇒ Object
TODO : sending c>=0 allows control chars to go.
-
#putch(char) ⇒ Fixnum
add a char to field, and validate NOTE: this should return self for chaining operations and throw an exception if disabled or exceeding size.
-
#repaint ⇒ Object
Note that some older widgets like Field repaint every time the form.repaint + is called, whether updated or not.
-
#restore_original_value ⇒ Object
silently restores value without firing handlers, use if exception and you want old value.
-
#set_buffer(value) ⇒ Object
should this do a dup ?? YES set value of Field fires CHANGE handler.
- #set_focusable(tf) ⇒ Object
-
#set_form_col(col1 = @curpos) ⇒ Object
sets the visual cursor on the window at correct place added here since we need to account for pcol.
-
#set_label(label) ⇒ Object
create a label linked to this field Typically one passes a Label, but now we can pass just a String, a label is created NOTE: 2011-10-20 when field attached to some container, label won’t be attached FIXME this may not work since i have disabled -1, now i do not set row and col 2011-11-5.
-
#text(*val) ⇒ Object
(also: #default)
Use this to set a default text to the field.
- #text=(val) ⇒ Object
-
#text_variable(tv) ⇒ Object
Set Variable as value.
-
#undo_delete_eol ⇒ Object
does an undo on delete_eol, not a real undo.
Methods inherited from Widget
#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height, #height=, #hide, #leave, #move, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn
Methods included from Utils
#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Constructor Details
#initialize(form = nil, config = {}, &block) ⇒ Field
Returns a new instance of Field.
2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2098 def initialize form=nil, config={}, &block @form = form @buffer = String.new #@type=config.fetch("type", :varchar) @row = 0 @col = 0 #@bgcolor = $def_bg_color #@color = $def_fg_color @editable = true @focusable = true @event_args = {} # arguments passed at time of binding, to use when firing event map_keys init_vars @_events ||= [] @_events.push(:CHANGE) super @display_length ||= 20 @maxlen ||= @display_length end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
actual buffer being used for storage
2060 2061 2062 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2060 def buffer @buffer end |
#datatype ⇒ Object
attr_reader :curpos # cursor position in buffer current, in WIDGET
2087 2088 2089 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2087 def datatype @datatype end |
#field_col ⇒ Object (readonly)
2091 2092 2093 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2091 def field_col @field_col end |
#form ⇒ Object (readonly)
2083 2084 2085 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2083 def form @form end |
#handler ⇒ Object (readonly)
event handler
2084 2085 2086 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2084 def handler @handler end |
#original_value ⇒ Object (readonly)
value on entering field
2088 2089 2090 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2088 def original_value @original_value end |
#overwrite_mode ⇒ Object
true or false INSERT OVERWRITE MODE
2089 2090 2091 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2089 def overwrite_mode @overwrite_mode end |
#type(dtype) ⇒ Object (readonly)
define a datatype, currently only influences chars allowed integer and float. what about allowing a minus sign?
2085 2086 2087 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2085 def type @type end |
Instance Method Details
#addcol(num) ⇒ Object
add a column to cursor position. Field
2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2481 def addcol num if num < 0 if @form.col <= @col + @col_offset # $log.debug " error trying to cursor back #{@form.col}" return -1 end elsif num > 0 if @form.col >= @col + @col_offset + @display_length # $log.debug " error trying to cursor forward #{@form.col}" return -1 end end @form.addcol num end |
#cursor_backward ⇒ Object
$log.debug “ crusor FORWARD cp:#@curpos pcol:#@pcol b.l:#RubyCurses::Field.@[email protected] d_l:#@display_length fc:#RubyCurses::Field.@[email protected]”
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2441 def cursor_backward if @curpos > 0 @curpos -= 1 if @pcol > 0 and @form.col == @col + @col_offset @pcol -= 1 end addcol -1 elsif @pcol > 0 # added 2008-11-26 23:05 @pcol -= 1 end # $log.debug " crusor back cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}" =begin # this is perfect if not scrolling, but now needs changes if @curpos > 0 @curpos -= 1 addcol -1 end =end end |
#cursor_end ⇒ Object
goto end of field, “end” is a keyword so could not use it.
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2394 def cursor_end blen = @buffer.rstrip.length if blen < @display_length set_form_col blen else # there is a problem here FIXME. @pcol = blen-@display_length #set_form_col @display_length-1 set_form_col blen end @curpos = blen # this is position in array where editing or motion is to happen regardless of what you see # regardless of pcol (panning) # $log.debug " crusor END cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}" #set_form_col @buffer.length end |
#cursor_forward ⇒ Object
2432 2433 2434 2435 2436 2437 2438 2439 2440 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2432 def cursor_forward if @curpos < @buffer.length if addcol(1)==-1 # go forward if you can, else scroll @pcol += 1 if @pcol < @display_length end @curpos += 1 end # $log.debug " crusor FORWARD cp:#{@curpos} pcol:#{@pcol} b.l:#{@buffer.length} d_l:#{@display_length} fc:#{@form.col}" end |
#cursor_home ⇒ Object
position cursor at start of field
2387 2388 2389 2390 2391 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2387 def cursor_home @curpos = 0 @pcol = 0 set_form_col 0 end |
#delete_at(index = @curpos) ⇒ Object
2207 2208 2209 2210 2211 2212 2213 2214 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2207 def delete_at index=@curpos return -1 if !@editable char = @buffer.slice!(index,1) #$log.debug " delete at #{index}: #{@buffer.length}: #{@buffer}" @modified = true #fire_handler :CHANGE, self # 2008-12-09 14:51 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, char) # 2010-09-11 13:01 end |
#delete_curr_char ⇒ Object
# this is perfect if not scrolling, but now needs changes
if @curpos > 0
@curpos -= 1
addcol -1
end
2460 2461 2462 2463 2464 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2460 def delete_curr_char return -1 unless @editable delete_at set_modified end |
#delete_eol ⇒ Object
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2422 def delete_eol return -1 unless @editable pos = @curpos-1 @delete_buffer = @buffer[@curpos..-1] # if pos is 0, pos-1 becomes -1, end of line! @buffer = pos == -1 ? "" : @buffer[0..pos] #fire_handler :CHANGE, self # 2008-12-09 14:51 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :DELETE, 0, @delete_buffer) # 2010-09-11 13:01 return @delete_buffer end |
#delete_prev_char ⇒ Object
2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2465 def delete_prev_char return -1 if !@editable return if @curpos <= 0 # if we've panned, then unpan, and don't move cursor back # Otherwise, adjust cursor (move cursor back as we delete) adjust = true if @pcol > 0 @pcol -= 1 adjust = false end @curpos -= 1 if @curpos > 0 delete_at addcol -1 if adjust # move visual cursor back set_modified end |
#getvalue ⇒ Object
converts back into original type
changed to convert on 2009-01-06 23:39
2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2243 def getvalue dt = @datatype || String case dt.to_s when "String" return @buffer when "Fixnum" return @buffer.to_i when "Float" return @buffer.to_f else return @buffer.to_s end end |
#handle_key(ch) ⇒ Object
field
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2363 def handle_key ch @repaint_required = true #map_keys unless @keys_mapped # moved to init case ch when 32..126 #$log.debug("FIELD: ch #{ch} ,at #{@curpos}, buffer:[#{@buffer}] bl: #{@buffer.to_s.length}") putc ch when 27 # cannot bind it set_buffer @original_value else ret = super return ret end 0 # 2008-12-16 23:05 without this -1 was going back so no repaint end |
#init_vars ⇒ Object
2117 2118 2119 2120 2121 2122 2123 2124 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2117 def init_vars @pcol = 0 # needed for horiz scrolling @curpos = 0 # current cursor position in buffer # this is the index where characters are put or deleted # # when user edits @modified = false @repaint_required = true end |
#map_keys ⇒ Object
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2345 def map_keys return if @keys_mapped bind_key(FFI::NCurses::KEY_LEFT, :cursor_backward ) bind_key(FFI::NCurses::KEY_RIGHT, :cursor_forward ) bind_key(FFI::NCurses::KEY_BACKSPACE, :delete_prev_char ) bind_key(127, :delete_prev_char ) bind_key(330, :delete_curr_char ) bind_key(?\C-a, :cursor_home ) bind_key(?\C-e, :cursor_end ) bind_key(?\C-k, :delete_eol ) bind_key(?\C-_, :undo_delete_eol ) #bind_key(27){ set_buffer @original_value } bind_key(?\C-g, 'revert'){ set_buffer @original_value } # 2011-09-29 V1.3.1 ESC did not work @keys_mapped = true end |
#modified? ⇒ Boolean
overriding widget, check for value change
2009-01-18 12:25
2539 2540 2541 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2539 def modified? getvalue() != @original_value end |
#on_enter ⇒ Object
save original value on enter, so we can check for modified.
2009-01-18 12:25
2011-10-9 I have changed to take @buffer since getvalue returns a datatype
and this causes a crash in set_original on cursor forward.
2531 2532 2533 2534 2535 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2531 def on_enter #@original_value = getvalue.dup rescue getvalue @original_value = @buffer.dup # getvalue.dup rescue getvalue super end |
#on_leave ⇒ Object
upon leaving a field returns false if value not valid as per values or valid_regex 2008-12-22 12:40 if null_allowed, don’t validate, but do fire_handlers
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2498 def on_leave val = getvalue #$log.debug " FIELD ON LEAVE:#{val}. #{@values.inspect}" valid = true if val.to_s.empty? && @null_allowed #$log.debug " empty and null allowed" else if !@values.nil? valid = @values.include? val raise FieldValidationException, "Field value (#{val}) not in values: #{@values.join(',')}" unless valid end if !@valid_regex.nil? valid = @valid_regex.match(val.to_s) raise FieldValidationException, "Field not matching regex #{@valid_regex}" unless valid end # added valid_range for numerics 2011-09-29 if !@valid_range.nil? valid = @valid_range.include?(val.to_i) raise FieldValidationException, "Field not matching range #{@valid_range}" unless valid end end # here is where we should set the forms modified to true - 2009-01 if modified? set_modified true end # if super fails we would have still set modified to true super #return valid end |
#position_label ⇒ Object
FIXME this may not work since i have disabled -1, now i do not set row and col
2283 2284 2285 2286 2287 2288 2289 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2283 def position_label $log.debug "XXX: LABEL row #{@label.row}, #{@label.col} " @label.row @row unless @label.row #if @label.row == -1 @label.col @col-(@label.name.length+1) unless @label.col #if @label.col == -1 @label.label_for(self) # this line got deleted when we redid stuff ! $log.debug " XXX: LABEL row #{@label.row}, #{@label.col} " end |
#putc(c) ⇒ Object
TODO : sending c>=0 allows control chars to go. Should be >= ?A i think.
2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2191 def putc c if c >= 0 and c <= 127 ret = putch c.chr if ret == 0 if addcol(1) == -1 # if can't go forward, try scrolling # scroll if exceeding display len but less than max len if @curpos > @display_length && @curpos <= @maxlen @pcol += 1 if @pcol < @display_length end end set_modified return 0 # 2010-09-11 12:59 else would always return -1 end end return -1 end |
#putch(char) ⇒ Fixnum
add a char to field, and validate NOTE: this should return self for chaining operations and throw an exception if disabled or exceeding size
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2161 def putch char return -1 if !@editable return -1 if !@overwrite_mode && (@buffer.length >= @maxlen) if @chars_allowed != nil return if char.match(@chars_allowed).nil? end # added insert or overwrite mode 2010-03-17 20:11 oldchar = nil if @overwrite_mode oldchar = @buffer[@curpos] @buffer[@curpos] = char else @buffer.insert(@curpos, char) end oldcurpos = @curpos $log.warn "XXX: FIELD CURPOS #{@curpos} " @curpos += 1 if @curpos < @maxlen @modified = true #$log.debug " FIELD FIRING CHANGE: #{char} at new #{@curpos}: bl:#{@buffer.length} buff:[#{@buffer}]" # i have no way of knowing what change happened and what char was added deleted or changed #fire_handler :CHANGE, self # 2008-12-09 14:51 if @overwrite_mode fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :DELETE, 0, oldchar) # 2010-09-11 12:43 end fire_handler :CHANGE, InputDataEvent.new(oldcurpos,@curpos, self, :INSERT, 0, char) # 2010-09-11 12:43 0 end |
#repaint ⇒ Object
Note that some older widgets like Field repaint every time the form.repaint + is called, whether updated or not. I can’t remember why this is, but + currently I’ve not implemented events with these widgets. 2010-01-03 15:00
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2295 def repaint return unless @repaint_required # 2010-11-20 13:13 its writing over a window i think TESTING if @label_unattached alert "came here unattachd" @label.set_form(@form) end if @label_unplaced alert "came here unplaced" position_label end @bgcolor ||= $def_bg_color @color ||= $def_fg_color $log.debug("repaint FIELD: #{id}, #{name}, #{row} #{col},pcol:#{@pcol}, #{focusable} st: #{@state} ") #return if display_length <= 0 # added 2009-02-17 00:17 sometimes editor comp has 0 and that # becomes negative below, no because editing still happens @display_length = 1 if display_length == 0 printval = getvalue_for_paint().to_s # added 2009-01-06 23:27 printval = show()*printval.length unless @show.nil? if !printval.nil? if printval.length > display_length # only show maxlen printval = printval[@pcol..@pcol+display_length-1] else printval = printval[@pcol..-1] end end acolor = @color_pair || get_color($datacolor, @color, @bgcolor) if @state == :HIGHLIGHTED _bgcolor = @highlight_background || @bgcolor _color = @highlight_foreground || @color acolor = get_color(acolor, _color, _bgcolor) end @graphic = @form.window if @graphic.nil? ## cell editor listbox hack #$log.debug " Field g:#{@graphic}. r,c,displen:#{@row}, #{@col}, #{@display_length} c:#{@color} bg:#{@bgcolor} a:#{@attr} :#{@name} " r = row c = col if label.is_a? String lcolor = @label_color_pair || $datacolor # this should be the same color as window bg XXX lattr = @label_attr || NORMAL @graphic.printstring row, col, label, lcolor, lattr c += label.length + 2 @col_offset = c-@col # required so cursor lands in right place end @graphic.printstring r, c, sprintf("%-*s", display_length, printval), acolor, @attr @field_col = c @repaint_required = false end |
#restore_original_value ⇒ Object
silently restores value without firing handlers, use if exception and you want old value
2218 2219 2220 2221 2222 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2218 def restore_original_value @buffer = @original_value.dup #@curpos = 0 # this would require restting setformcol @repaint_required = true end |
#set_buffer(value) ⇒ Object
should this do a dup ?? YES set value of Field fires CHANGE handler
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2227 def set_buffer value @repaint_required = true @datatype = value.class #$log.debug " FIELD DATA #{@datatype}" @delete_buffer = @buffer.dup @buffer = value.to_s.dup # don't allow setting of value greater than maxlen @buffer = @buffer[0,@maxlen] if @maxlen && @buffer.length > @maxlen @curpos = 0 # hope @delete_buffer is not overwritten fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :DELETE, 0, @delete_buffer) # 2010-09-11 13:01 fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos, self, :INSERT, 0, @buffer) # 2010-09-11 13:01 self # 2011-10-2 end |
#set_focusable(tf) ⇒ Object
2342 2343 2344 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2342 def set_focusable(tf) @focusable = tf end |
#set_form_col(col1 = @curpos) ⇒ Object
sets the visual cursor on the window at correct place added here since we need to account for pcol. 2011-12-7 NOTE be careful of curpos - pcol being less than 0
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2412 def set_form_col col1=@curpos @curpos = col1 || 0 # NOTE we set the index of cursor here c = @col + @col_offset + @curpos - @pcol min = @col + @col_offset max = min + @display_length c = min if c < min c = max if c > max $log.debug " #{@name} FIELD set_form_col #{c}, curpos #{@curpos} , #{@col} + #{@col_offset} pcol:#{@pcol} " setrowcol nil, c end |
#set_label(label) ⇒ Object
create a label linked to this field Typically one passes a Label, but now we can pass just a String, a label is created NOTE: 2011-10-20 when field attached to some container, label won’t be attached FIXME this may not work since i have disabled -1, now i do not set row and col 2011-11-5
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2263 def set_label label # added case for user just using a string case label when String # what if no form at this point @label_unattached = true unless @form label = Label.new @form, {:text => label} end @label = label # in the case of app it won't be set yet FIXME # So app sets label to 0 and t his won't trigger # can this be delayed to when paint happens XXX if @row position_label else @label_unplaced = true end label end |
#text(*val) ⇒ Object Also known as: default
Use this to set a default text to the field. This does not imply that if the field is left blank, this value will be used. It only provides this value for editing when field is shown.
2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2546 def text(*val) if val.empty? return getvalue() else return unless val # added 2010-11-17 20:11, dup will fail on nil return unless val[0] s = val[0].dup set_buffer(s) end end |
#text=(val) ⇒ Object
2557 2558 2559 2560 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2557 def text=(val) return unless val # added 2010-11-17 20:11, dup will fail on nil set_buffer(val.dup) end |
#text_variable(tv) ⇒ Object
Set Variable as value.
This allows using Field as a proxy
@param [Variable] variable containing text value
2131 2132 2133 2134 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2131 def text_variable tv @text_variable = tv set_buffer tv.value end |
#undo_delete_eol ⇒ Object
does an undo on delete_eol, not a real undo
2379 2380 2381 2382 2383 2384 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 2379 def undo_delete_eol return if @delete_buffer.nil? #oldvalue = @buffer @buffer.insert @curpos, @delete_buffer fire_handler :CHANGE, InputDataEvent.new(@curpos,@curpos+@delete_buffer.length, self, :INSERT, 0, @delete_buffer) # 2010-09-11 13:01 end |