class Canis::ApplicationHeader
Maintain an application header on the top of an application. Application related text may be placed in the left, center or right slots.
Example¶ ↑
a = ApplicationHeader.new
“MyApp v1.0”, :text_center => “Application Name”, :text_right => “module”,
:color => :white, :bgcolor => :blue
# Later as user traverses a list or table, update row number on app header a.text_right “Row #{n}”
Public Class Methods
new(form, text1, config={})
click to toggle source
@param text1 String
text on left of header
Calls superclass method
# File lib/canis/core/widgets/applicationheader.rb, line 43 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 ||= "" # 2016-01-13 - added since "1" was giving problems in mvhline in some cases @space_char = " ".codepoints.first end
Public Instance Methods
getvalue()
click to toggle source
returns value of text1, i.e. text on left of header
# File lib/canis/core/widgets/applicationheader.rb, line 67 def getvalue @text1 end
print_center(htext, r = 0, c = 0)
click to toggle source
internal method, called by repaint to print text_center in the center
# File lib/canis/core/widgets/applicationheader.rb, line 106 def print_center(htext, r = 0, c = 0) win = @window len = win.getmaxx len = Ncurses.COLS-0 if len == 0 || len > Ncurses.COLS # win.printstring r, ((len-htext.length)/2).floor, htext, @color_pair, @attr end
print_header(htext, r = 0, c = 0)
click to toggle source
internal method, called by repain to print text1 and text2 on left side
# File lib/canis/core/widgets/applicationheader.rb, line 98 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, htext, @color_pair, @attr end
print_top_right(htext)
click to toggle source
internal method to print text_right
# File lib/canis/core/widgets/applicationheader.rb, line 114 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
repaint()
click to toggle source
XXX need to move wrapping etc up and done once.
# File lib/canis/core/widgets/applicationheader.rb, line 73 def repaint return unless @repaint_required # 2014-08-10 - 14:53 changing bgcolor or color resets color_pair, so this must be reset if nil @color_pair ||= get_color $bottomcolor, @color, @bgcolor #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) # 2016-01-13 - changed since "1" was giving problems in mvhline in some cases #@window.mvhline(@row, @col, 1, len) @window.mvhline(@row, @col, @space_char, 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