Class: Canis::ToggleButton
- Defined in:
- lib/canis/core/widgets/rwidget.rb
Overview
A button that may be switched off an on. To be extended by RadioButton and checkbox. WARNING, pls do not override text
otherwise checkboxes etc will stop functioning. TODO: add editable here nd prevent toggling if not so.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #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
A new instance of ToggleButton.
-
#toggle ⇒ Object
toggle the button value.
Methods inherited from Button
#action, #bind_hotkey, button_layout, #command, #default_button, #map_keys, #mnemonic, #repaint, #text
Methods inherited from Widget
#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #hide, #init_vars, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #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, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form, config = {}, &block) ⇒ ToggleButton
Returns a new instance of ToggleButton.
3378 3379 3380 3381 3382 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3378 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
3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3439 def checked tf @value = tf if @variable if @value @variable.set_value((@onvalue || 1), @name) else @variable.set_value((@offvalue || 0), @name) end end 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
3395 3396 3397 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3395 def checked? @value end |
#fire ⇒ Object
called on :PRESS event caller should check state of itemevent passed to block
3430 3431 3432 3433 3434 3435 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3430 def fire checked(!@value) @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 end |
#getvalue ⇒ Object
3383 3384 3385 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3383 def getvalue @value ? @onvalue : @offvalue end |
#getvalue_for_paint ⇒ Object
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3400 def getvalue_for_paint unless @width if @onvalue && @offvalue @width = [ @onvalue.length, @offvalue.length ].max end end = getvalue().center(@width) @text_offset = @surround_chars[0].length @surround_chars[0] + + @surround_chars[1] end |
#handle_key(ch) ⇒ Object
toggle button handle key
3414 3415 3416 3417 3418 3419 3420 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3414 def handle_key ch if ch == 32 toggle else super end end |
#toggle ⇒ Object
toggle the button value
3424 3425 3426 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3424 def toggle fire end |