Class: RubyCurses::ToggleButton
- Defined in:
- lib/rbcurse/core/widgets/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
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #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?)
added for some standardization 2010-09-07 20:28 alias :text :getvalue # NEXT VERSION change existing text to label.
-
#fire ⇒ Object
called on :PRESS event caller should check state of itemevent passed to block.
- #getvalue ⇒ Object
- #getvalue_for_paint ⇒ Object
-
#handle_key(ch) ⇒ Object
toggle button handle key.
-
#initialize(form, config = {}, &block) ⇒ ToggleButton
constructor
item_event.
-
#toggle ⇒ Object
toggle the button value.
Methods inherited from Button
#action, #bind_hotkey, button_layout, #command, #default_button, #mnemonic, #repaint, #text
Methods inherited from Widget
#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #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, config = {}, &block) ⇒ ToggleButton
item_event
3094 3095 3096 3097 3098 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3094 def initialize form, config={}, &block super @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
3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3155 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?
added for some standardization 2010-09-07 20:28 alias :text :getvalue # NEXT VERSION change existing text to label
is the button on or off added 2008-12-09 19:05
3108 3109 3110 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3108 def checked? @value end |
#fire ⇒ Object
called on :PRESS event caller should check state of itemevent passed to block
3143 3144 3145 3146 3147 3148 3149 3150 3151 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3143 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
3099 3100 3101 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3099 def getvalue @value ? @onvalue : @offvalue end |
#getvalue_for_paint ⇒ Object
3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3113 def getvalue_for_paint unless @display_length if @onvalue && @offvalue @display_length = [ @onvalue.length, @offvalue.length ].max end end = getvalue().center(@display_length) @text_offset = @surround_chars[0].length @surround_chars[0] + + @surround_chars[1] end |
#handle_key(ch) ⇒ Object
toggle button handle key
3127 3128 3129 3130 3131 3132 3133 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3127 def handle_key ch if ch == 32 toggle else super end end |
#toggle ⇒ Object
toggle the button value
3137 3138 3139 |
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3137 def toggle fire end |