Class: RubyCurses::CheckBoxCellRenderer
- Inherits:
-
ListCellRenderer
- Object
- ListCellRenderer
- RubyCurses::CheckBoxCellRenderer
- Includes:
- ConfigSetup, Utils
- Defined in:
- lib/rbcurse/checkboxcellrenderer.rb
Overview
This is a basic list cell renderer that will render the to_s value of anything. Using alignment one can use for numbers too. However, for booleans it will print true and false. If editing, you may want checkboxes
Instance Method Summary collapse
- #getvalue ⇒ Object
- #init_vars ⇒ Object
-
#initialize(boolean = nil, config = {}, &block) ⇒ CheckBoxCellRenderer
constructor
A new instance of CheckBoxCellRenderer.
- #repaint(graphic, r = @row, c = @col, row_index = -1,, value = @value, focussed = false, selected = false) ⇒ Object
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 inherited from ListCellRenderer
Constructor Details
#initialize(boolean = nil, config = {}, &block) ⇒ CheckBoxCellRenderer
Returns a new instance of CheckBoxCellRenderer.
24 25 26 27 28 29 30 31 32 |
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 24 def initialize boolean=nil, config={}, &block @value = boolean @text = "" # what if someone wants to show a label later. ??? XXX @editable = false @focusable = false config_setup config # @config.each_pair { |k,v| variable_set(k,v) } instance_eval &block if block_given? init_vars end |
Instance Method Details
#getvalue ⇒ Object
38 39 40 |
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 38 def getvalue @value end |
#init_vars ⇒ Object
33 34 35 36 37 |
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 33 def init_vars @justify ||= :left @display_length ||= 5 @surround_chars = ['[',']'] end |
#repaint(graphic, r = @row, c = @col, row_index = -1,, value = @value, focussed = false, selected = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 44 def repaint graphic, r=@row,c=@col, row_index=-1,value=@value, focussed=false, selected=false #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} " prepare_default_colors focussed, selected = value ? "X" : " " # HOW TO DO THE TEXT ??? XXX # the space in dtext next line is a cheat, to clear off the space that the # editor is leaving. dtext = " " #@display_length.nil? ? @text : "%-*s" % [@display_length, @text] if @align_right #@text_offset = 0 #@col_offset = dtext.length + @surround_chars[0].length + 1 str = "#{dtext} " + @surround_chars[0] + + @surround_chars[1] else pretext = @surround_chars[0] + + @surround_chars[1] #@text_offset = pretext.length + 1 #@col_offset = @surround_chars[0].length #@surround_chars[0] + buttontext + @surround_chars[1] + " #{@text}" str = pretext + " #{dtext}" end graphic.printstring r, c, str, @color_pair,@attr end |