Module: CDK::HasTitle

Included in:
CDKOBJS
Defined in:
lib/cdk/mixins/has_title.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#title_attribObject

Returns the value of attribute title_attrib.



3
4
5
# File 'lib/cdk/mixins/has_title.rb', line 3

def title_attrib
  @title_attrib
end

Instance Method Details

#cleanTitleObject

Remove storage for the widget’s title.



60
61
62
# File 'lib/cdk/mixins/has_title.rb', line 60

def cleanTitle
  @title_lines = ''
end

#drawTitle(win) ⇒ Object

Draw the widget’s title



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cdk/mixins/has_title.rb', line 46

def drawTitle(win)
  (0...@title_lines).each do |x|
    Draw.writeChtypeAttrib(@win,
        @title_pos[x] + @border_size,
                    x + @border_size,
                           @title[x],
                        title_attrib,
                     CDK::HORIZONTAL,
                                   0,
                       @title_len[x])
  end
end

#init_titleObject



5
6
7
# File 'lib/cdk/mixins/has_title.rb', line 5

def init_title
  @title_attrib = Ncurses::A_NORMAL
end

#setTitle(title, box_width) ⇒ Object

Set the widget’s title.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cdk/mixins/has_title.rb', line 10

def setTitle (title, box_width)
  if !title.nil? 
    temp = title.split("\n")
    @title_lines = temp.size
    
    if box_width >= 0
      max_width = 0
      temp.each do |line|
        len = []
        align = []
        holder = char2Chtype(line, len, align)
        max_width = [len[0], max_width].max
      end
      box_width = [box_width, max_width + 2 * @border_size].max
    else
      box_width = -(box_width - 1)
    end

    # For each line in the title convert from string to chtype array
    title_width = box_width - (2 * @border_size)
    @title = []
    @title_pos = []
    @title_len = []
    (0...@title_lines).each do |x|
      len_x = []
      pos_x = []
      @title << char2Chtype(temp[x], len_x, pos_x)
      @title_len.concat(len_x)
      @title_pos << justify_string(title_width, len_x[0], pos_x[0])
    end
  end

  return box_width
end