Class: CDK::SCROLLER

Inherits:
CDKOBJS show all
Defined in:
lib/cdk/components/scroller.rb

Direct Known Subclasses

RADIO, SCROLL, SELECTION

Instance Attribute Summary

Attributes included from HasTitle

#title_attrib

Attributes included from HasScreen

#is_visible, #screen, #screen_index

Attributes included from ExitConditions

#exit_type

Attributes included from Bindings

#binding_list

Attributes included from Focusable

#accepts_focus, #has_focus

Attributes included from Borders

#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #border_size, #box

Instance Method Summary collapse

Methods inherited from CDKOBJS

#object_type, #setBackgroundColor, #timeout, #validCDKObject, #validObjType

Methods included from WindowHooks

#destroy, #draw, #erase, #refreshData, #saveData

Methods included from WindowInput

#getc, #getch, #inject, #setPostProcess, #setPreProcess

Methods included from HasTitle

#cleanTitle, #drawTitle, #init_title, #setTitle

Methods included from HasScreen

#SCREEN_XPOS, #SCREEN_YPOS, #init_screen, #wrefresh

Methods included from ExitConditions

#init_exit_conditions, #resetExitType, #setExitType

Methods included from Bindings

#bind, #bindableObject, #checkBind, #cleanBindings, #init_bindings, #isBind, #unbind

Methods included from Focusable

#focus, #init_focus, #unfocus

Methods included from Borders

#getBox, #init_borders, #setBXattr, #setBox, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar

Methods included from Movement

#move, #move_specific, #position

Methods included from Converters

#char2Chtype, #charOf, #chtype2Char, #chtype2String, #decode_attribute, #encode_attribute

Methods included from Justifications

#justify_string

Methods included from Alignments

#alignxy

Constructor Details

#initializeSCROLLER

Returns a new instance of SCROLLER.



4
5
6
# File 'lib/cdk/components/scroller.rb', line 4

def initialize
  super()
end

Instance Method Details

#getCurrentItemObject

Get/Set the current item number of the scroller.



175
176
177
# File 'lib/cdk/components/scroller.rb', line 175

def getCurrentItem
  @current_item
end

#KEY_DOWNObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cdk/components/scroller.rb', line 30

def KEY_DOWN
  if @list_size > 0
    if @current_item < @list_size - 1
      if @current_high == @view_size - 1
        if @current_top < @max_top_item
          @current_top += 1
          @current_item += 1
        else
          CDK.Beep
        end
      else
        @current_item += 1
        @current_high += 1
      end
    else
      CDK.Beep
    end
  else
    CDK.Beep
  end
end

#KEY_ENDObject



118
119
120
121
122
123
124
125
126
127
# File 'lib/cdk/components/scroller.rb', line 118

def KEY_END
  if @max_top_item == -1
    @current_top = 0
    @current_item = @last_item - 1
  else
    @current_top = @max_top_item
    @current_item = @last_item
  end
  @current_high = @view_size - 1
end

#KEY_HOMEObject



112
113
114
115
116
# File 'lib/cdk/components/scroller.rb', line 112

def KEY_HOME
  @current_top = 0
  @current_item = 0
  @current_high = 0
end

#KEY_LEFTObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cdk/components/scroller.rb', line 52

def KEY_LEFT
  if @list_size > 0
    if @left_char == 0
      CDK.Beep
    else
      @left_char -= 1
    end
  else
    CDK.Beep
  end
end

#KEY_NPAGEObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cdk/components/scroller.rb', line 93

def KEY_NPAGE
  if @list_size > 0
    if @current_top < @max_top_item
      if @current_top + @view_size - 1 <= @max_top_item
        @current_top += @view_size - 1
        @current_item += @view_size - 1
      else
        @current_top = @max_top_item
        @current_item = @last_item
        @current_high = @view_size - 1
      end
    else
      CDK.Beep
    end
  else
    CDK.Beep
  end
end

#KEY_PPAGEObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cdk/components/scroller.rb', line 76

def KEY_PPAGE
  if @list_size > 0
    if @current_top > 0
      if @current_top >= @view_size - 1
        @current_top -= @view_size - 1
        @current_item -= @view_size - 1
      else
        self.KEY_HOME
      end
    else
      CDK.Beep
    end
  else
    CDK.Beep
  end
end

#KEY_RIGHTObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cdk/components/scroller.rb', line 64

def KEY_RIGHT
  if @list_size > 0
    if @left_char >= @max_left_char
      CDK.Beep
    else
      @left_char += 1
    end
  else
    CDK.Beep
  end
end

#KEY_UPObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cdk/components/scroller.rb', line 8

def KEY_UP
  if @list_size > 0
    if @current_item > 0
      if @current_high == 0
        if @current_top != 0
          @current_top -= 1
          @current_item -= 1
        else
          CDK.Beep
        end
      else
        @current_item -= 1
        @current_high -= 1
      end
    else
      CDK.Beep
    end
  else
    CDK.Beep
  end
end

#maxViewSizeObject



129
130
131
# File 'lib/cdk/components/scroller.rb', line 129

def maxViewSize
  return @box_height - (2 * @border_size + @title_lines)
end

#setCurrentItem(item) ⇒ Object



179
180
181
# File 'lib/cdk/components/scroller.rb', line 179

def setCurrentItem(item)
  self.setPosition(item);
end

#setPosition(item) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/cdk/components/scroller.rb', line 157

def setPosition(item)
  if item <= 0
    self.KEY_HOME
  elsif item > @list_size - 1
    @current_top = @max_top_item
    @current_item = @list_size - 1
    @current_high = @view_size - 1
  elsif item >= @current_top && item < @current_top + @view_size
    @current_item = item
    @current_high = item - @current_top
  else
    @current_top = item - (@view_size - 1)
    @current_item = item
    @current_high = @view_size - 1
  end
end

#setViewSize(list_size) ⇒ Object

Set variables that depend upon the list_size



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/cdk/components/scroller.rb', line 134

def setViewSize(list_size)
  @view_size = self.maxViewSize
  @list_size = list_size
  @last_item = list_size - 1
  @max_top_item = list_size - @view_size

  if list_size < @view_size
    @view_size = list_size
    @max_top_item = 0
  end

  if @list_size > 0 && self.maxViewSize > 0
    @step = 1.0 * self.maxViewSize / @list_size
    @toggle_size = if @list_size > self.maxViewSize
                   then 1
                   else @step.ceil
                   end
  else
    @step = 1
    @toggle_size = 1
  end
end