Class: RubyCurses::CheckBoxCellRenderer

Inherits:
ListCellRenderer show all
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

Methods inherited from ListCellRenderer

#create_color_pairs, #prepare_default_colors, #select_colors

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Constructor Details

#initialize(boolean = nil, config = {}, &block) ⇒ CheckBoxCellRenderer

Returns a new instance of CheckBoxCellRenderer.



12
13
14
15
16
17
18
19
20
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 12

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

#getvalueObject



26
27
28
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 26

def getvalue
  @value
end

#init_varsObject



21
22
23
24
25
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 21

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rbcurse/checkboxcellrenderer.rb', line 32

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

  buttontext = 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] + buttontext + @surround_chars[1] 
  else
    pretext = @surround_chars[0] + buttontext + @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