Class: RubyCurses::ApplicationHeader

Inherits:
Widget show all
Defined in:
lib/rbcurse/core/widgets/applicationheader.rb

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

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #handle_key, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #remove, #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, #width, #width=

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, text1, config = {}, &block) ⇒ ApplicationHeader

Returns a new instance of ApplicationHeader.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 29

def initialize form, text1, config={}, &block

  @name = "header"
  @text1 = text1
  # setting default first or else Widget will place its BW default
  @color, @bgcolor = ColorMap.get_colors_for_pair $bottomcolor
  super form, config, &block
  @color_pair = get_color $bottomcolor, @color, @bgcolor
  @window = form.window
  @editable = false
  @focusable = false
  @cols ||= Ncurses.COLS-1
  @row ||= 0
  @col ||= 0
  @repaint_required = true
  #@color_pair ||= $bottomcolor  # XXX this was forcing the color
  #pair
  @text2 ||= ""
  @text_center ||= ""
  @text_right ||= ""
end

Instance Method Details

#getvalueObject



50
51
52
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 50

def getvalue
  @text1
end


84
85
86
87
88
89
90
91
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 84

def print_center(htext, r = 0, c = 0)
  win = @window
  len = win.getmaxx
  len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS
  #
  #@form.window.printstring r, c, "%-*s" % [len, htext], @color_pair, @attr
  win.printstring r, ((len-htext.length)/2).floor, htext, @color_pair, @attr
end


76
77
78
79
80
81
82
83
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 76

def print_header(htext, r = 0, c = 0)
  #win = @window
  #len = @window.width
  #len = Ncurses.COLS-0 if len == 0
  #
  #@form.window.printstring r, c, "%-*s" % [len, htext], @color_pair, @attr
  @form.window.printstring r, c, htext, @color_pair, @attr
end


92
93
94
95
96
97
98
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 92

def print_top_right(htext)
  hlen = htext.length
  len = @window.getmaxx # width was not changing when resize happens
  len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS
  $log.debug " def print_top_right(#{htext}) #{len} #{Ncurses.COLS} "
  @form.window.printstring 0, len-hlen, htext, @color_pair, @attr
end

#repaintObject

XXX need to move wrapping etc up and done once.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rbcurse/core/widgets/applicationheader.rb', line 56

def repaint
  return unless @repaint_required
 
  #print_header(htext, posy = 0, posx = 0)
  att = get_attrib @attr
  len = @window.width
  len = Ncurses.COLS-0 if len == 0
  # print a bar across the screen 
  @window.attron(Ncurses.COLOR_PAIR(@color_pair) | att)
  @window.mvhline(@row, @col, 1, len)
  @window.attroff(Ncurses.COLOR_PAIR(@color_pair) | att)
  #print_header(@text1 + " %15s " % @text2 + " %20s" % @text_center , posy=0, posx=0)

  # Now print the text in the correct positions with no padding, else some terminal
  # will blacken the text out.
  print_header("#{@text1}  #{@text2}") # + " %20s" % @text_center , posy=0, posx=0)
  print_center("#{@text_center}") # + " %20s" % @text_center , posy=0, posx=0)
  print_top_right(@text_right)
  @repaint_required = false
end