Class: Canis::ApplicationHeader
- Defined in:
- lib/canis/core/widgets/applicationheader.rb
Overview
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”
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state
Instance Method Summary collapse
-
#getvalue ⇒ Object
returns value of text1, i.e.
-
#initialize(form, text1, config = {}, &block) ⇒ ApplicationHeader
constructor
A new instance of ApplicationHeader.
-
#print_center(htext, r = 0, c = 0) ⇒ Object
internal method, called by repaint to print text_center in the center.
-
#print_header(htext, r = 0, c = 0) ⇒ Object
internal method, called by repain to print text1 and text2 on left side.
-
#print_top_right(htext) ⇒ Object
internal method to print text_right.
-
#repaint ⇒ Object
XXX need to move wrapping etc up and done once.
Methods inherited from Widget
#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #getvalue_for_paint, #handle_key, #hide, #init_vars, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form, text1, config = {}, &block) ⇒ ApplicationHeader
Returns a new instance of ApplicationHeader.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 |
Instance Method Details
#getvalue ⇒ Object
returns value of text1, i.e. text on left of header
67 68 69 |
# File 'lib/canis/core/widgets/applicationheader.rb', line 67 def getvalue @text1 end |
#print_center(htext, r = 0, c = 0) ⇒ Object
internal method, called by repaint to print text_center in the center
106 107 108 109 110 111 112 |
# 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) ⇒ Object
internal method, called by repain to print text1 and text2 on left side
98 99 100 101 102 103 104 |
# 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) ⇒ Object
internal method to print text_right
114 115 116 117 118 119 120 |
# 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 ⇒ Object
XXX need to move wrapping etc up and done once.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 |