Class: RubyCurses::ToggleButton
- Defined in:
- lib/rbcurse/rwidget.rb
Overview
A button that may be switched off an on. To be extended by RadioButton and checkbox. TODO: add editable here nd prevent toggling if not so.
Direct Known Subclasses
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary
Attributes inherited from Widget
#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state
Instance Method Summary collapse
-
#checked(tf) ⇒ Object
set the value to true or false user may programmatically want to check or uncheck.
-
#checked? ⇒ Boolean
(also: #selected?)
is the button on or off added 2008-12-09 19:05.
- #fire ⇒ Object
- #getvalue ⇒ Object
- #getvalue_for_paint ⇒ Object
- #handle_key(ch) ⇒ Object
-
#initialize(form, config = {}, &block) ⇒ ToggleButton
constructor
item_event.
-
#toggle ⇒ Object
toggle the button value.
Methods inherited from Button
#OLDunderline, #action, #bind_hotkey, button_layout, #command, #mnemonic, #repaint, #text
Methods inherited from Widget
#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #height, #height=, #hide, #init_vars, #is_double_buffered?, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(form, config = {}, &block) ⇒ ToggleButton
item_event
2426 2427 2428 2429 2430 |
# File 'lib/rbcurse/rwidget.rb', line 2426 def initialize form, config={}, &block super # no longer linked to text_variable, that was a misunderstanding @value ||= (@variable.nil? ? false : @variable.get_value(@name)==true) end |
Instance Method Details
#checked(tf) ⇒ Object
set the value to true or false user may programmatically want to check or uncheck
2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 |
# File 'lib/rbcurse/rwidget.rb', line 2471 def checked tf @value = tf if !@variable.nil? if @value @variable.set_value((@onvalue || 1), @name) else @variable.set_value((@offvalue || 0), @name) end end # call fire of button class 2008-12-09 17:49 end |
#checked? ⇒ Boolean Also known as: selected?
is the button on or off added 2008-12-09 19:05
2437 2438 2439 |
# File 'lib/rbcurse/rwidget.rb', line 2437 def checked? @value end |
#fire ⇒ Object
2459 2460 2461 2462 2463 2464 2465 2466 2467 |
# File 'lib/rbcurse/rwidget.rb', line 2459 def fire checked(!@value) # added ItemEvent on 2008-12-31 13:44 @item_event = ItemEvent.new self, self if @item_event.nil? @item_event.set(@value ? :SELECTED : :DESELECTED) fire_handler :PRESS, @item_event # should the event itself be ITEM_EVENT # fire_handler :PRESS, @form # super end |
#getvalue ⇒ Object
2431 2432 2433 |
# File 'lib/rbcurse/rwidget.rb', line 2431 def getvalue @value ? @onvalue : @offvalue end |
#getvalue_for_paint ⇒ Object
2442 2443 2444 2445 2446 |
# File 'lib/rbcurse/rwidget.rb', line 2442 def getvalue_for_paint = getvalue() @text_offset = @surround_chars[0].length @surround_chars[0] + + @surround_chars[1] end |
#handle_key(ch) ⇒ Object
2447 2448 2449 2450 2451 2452 2453 |
# File 'lib/rbcurse/rwidget.rb', line 2447 def handle_key ch if ch == 32 toggle else super end end |
#toggle ⇒ Object
toggle the button value
2456 2457 2458 |
# File 'lib/rbcurse/rwidget.rb', line 2456 def toggle fire end |