class Canis::ListRenderer

Takes care of rendering the list.

In the case of a List we take care of selected indices. Also, focussed row is shown in bold, although we can make that optional and configurable A user wanting a different rendering of listboxes may either extend this class or completely replace it and set it as the renderer.

Attributes

left_margin_text[RW]

text to be placed in the left margin. This requires that a left margin be set in the source object.

row_focussed_attr[RW]

Public Class Methods

new(source) click to toggle source
# File lib/canis/core/widgets/listbox.rb, line 225
def initialize source
  @source = source
  # internal width based on both borders - earlier internal_width which we need
  @int_w = 3 
  # 3 leaves a blank black in popuplists as in testlistbox.rb F4
  # setting it as 2 means that in some cases, the next line first character
  #   gets overwritten with traversal
  #@int_w = 2
end

Public Instance Methods

_clear_row(pad, lineno) click to toggle source

clear row before writing so previous contents are erased and don't show through I could do this everytime i write but trying to make it faster and only call this if fire_row_changed is called. NOTE: in clear_row one is supposed to clear to the width of the pad, not window

otherwise on scrolling you might get black bg if you have some other color bg.
This is mostly important if you have a bgcolor that is different from the terminal
bgcolor.

@param - pad @param - line number (index of row to clear)

# File lib/canis/core/widgets/listbox.rb, line 313
def _clear_row pad, lineno
  raise "unused"
  @color_pair ||= get_color($datacolor, @source.color, @source.bgcolor)
  cp = @color_pair
  att = NORMAL
  @_clearstring ||= " " * (@source.width - @left_margin - @int_w)
  # with int_w = 3 we get that one space in popuplist
  # added attr on 2014-05-02 - 00:16 otherwise a list inside a white bg messagebox shows
  # empty rows in black bg.
  FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
  FFI::NCurses.mvwaddstr(pad,lineno, @left_margin, @_clearstring) 
  FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
end
pre_render() click to toggle source

This is called prior to render_all, and may not be called when a single row is rendered

as in fire_row_changed
Calls superclass method
# File lib/canis/core/widgets/listbox.rb, line 236
def pre_render
  super
  @selected_indices = @source.selected_indices
  @left_margin = @source.left_margin
  @bg = @source.bgcolor
  @fg = @source.color
  @attr = NORMAL
  @row_focussed_attr ||= $row_focussed_attr
end
render(pad, lineno, text) click to toggle source

@param pad for calling print methods on @param lineno the line number on the pad to print on @param text data to print

# File lib/canis/core/widgets/listbox.rb, line 255
    def render pad, lineno, text
      sele = false
=begin
      bg = @source.bgcolor
      fg = @source.color
      att = NORMAL
      cp = get_color($datacolor, fg, bg)
=end
      bg = @bg || @source.bgcolor
      fg = @fg || @source.color
      att = @attr || NORMAL
      cp = get_color($datacolor, fg, bg)

      if @selected_indices.include? lineno
        # print selected row in reverse
        sele = true
        fg = @source.selected_color || fg
        bg = @source.selected_bgcolor || bg
        att = @source.selected_attr || REVERSE
        cp = get_color($datacolor, fg, bg)

      elsif lineno == @source.current_index 
        # print focussed row in different attrib
        if @source.should_show_focus
          # bold was supposed to be if the object loses focus, but although render is called
          #  however, padrefresh is not happening since we do not paint on exiting a widget
          att = BOLD
          if @source.focussed
            att = @row_focussed_attr 
          end
        end
        # take current index into account as BOLD
        # and oldindex as normal
      end
      FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
      FFI::NCurses.mvwaddstr(pad, lineno, 0, @left_margin_text) if @left_margin_text
      FFI::NCurses.mvwaddstr(pad, lineno, @left_margin, text)
      FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)

      # the above only sets the attrib under the text not the whole line, we
      # need the whole line to be REVERSE
      # Strangely in testlistbox1 unselecting removes the entire lines REVERSE
      # but in testlistbox.rb the previous selected lines REV only partially goes
      # so we have to make the entire line in current attrib
      sele = true
      if sele
        FFI::NCurses.mvwchgat(pad, y=lineno, x=@left_margin, @source.width - @left_margin - @int_w, att, cp, nil)
      end
    end