Module: BorderTitle

Included in:
RubyCurses::Box, RubyCurses::MessageBox, RubyCurses::TextPad
Defined in:
lib/rbcurse/core/include/bordertitle.rb

Overview

I am moving the common title and border printing stuff into a separate module.

Instance Method Summary collapse

Instance Method Details

#bordertitle_initObject



9
10
11
12
13
# File 'lib/rbcurse/core/include/bordertitle.rb', line 9

def bordertitle_init
  @_bordertitle_init_called = true
  @row_offset = @col_offset = 0 if @suppress_borders 
  @internal_width = 1 if @suppress_borders # the other programs have zero not 1 NOTE
end

why the dash does it reduce height by one.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rbcurse/core/include/bordertitle.rb', line 15

def print_borders
  bordertitle_init unless @_bordertitle_init_called
  raise ArgumentError, "Graphic not set" unless @graphic
  raise "#{self} needs width" unless @width
  raise "#{self} needs height" unless @height
  width = @width
  height = @height-1
  window = @graphic
  startcol = @col 
  startrow = @row 
  @color_pair = get_color($datacolor)
  bordercolor = @border_color || @color_pair
  borderatt = @border_attrib || Ncurses::A_NORMAL
  window.print_border startrow, startcol, height, width, bordercolor, borderatt
  print_title
end


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rbcurse/core/include/bordertitle.rb', line 31

def print_title
  bordertitle_init unless @_bordertitle_init_called
  return unless @title
  raise "#{self} needs width" unless @width
  @color_pair ||= get_color($datacolor) # should we not use this ??? XXX 
  #$log.debug " print_title #{@row}, #{@col}, #{@width}  "
  # check title.length and truncate if exceeds width
  _title = @title
  if @title.length > @width - 2
    _title = @title[0..@width-2]
  end
  @graphic.printstring( @row, @col+(@width-_title.length)/2, _title, @color_pair, @title_attrib) unless @title.nil?
end