slithernix-cdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ require_relative 'cdk_objs'
2
+ module CDK
3
+ class SCROLLER < CDK::CDKOBJS
4
+ def initialize
5
+ super()
6
+ end
7
+
8
+ def KEY_UP
9
+ if @list_size > 0
10
+ if @current_item > 0
11
+ if @current_high == 0
12
+ if @current_top != 0
13
+ @current_top -= 1
14
+ @current_item -= 1
15
+ else
16
+ CDK.Beep
17
+ end
18
+ else
19
+ @current_item -= 1
20
+ @current_high -= 1
21
+ end
22
+ else
23
+ CDK.Beep
24
+ end
25
+ else
26
+ CDK.Beep
27
+ end
28
+ end
29
+
30
+ def KEY_DOWN
31
+ if @list_size > 0
32
+ if @current_item < @list_size - 1
33
+ if @current_high == @view_size - 1
34
+ if @current_top < @max_top_item
35
+ @current_top += 1
36
+ @current_item += 1
37
+ else
38
+ CDK.Beep
39
+ end
40
+ else
41
+ @current_item += 1
42
+ @current_high += 1
43
+ end
44
+ else
45
+ CDK.Beep
46
+ end
47
+ else
48
+ CDK.Beep
49
+ end
50
+ end
51
+
52
+ def KEY_LEFT
53
+ if @list_size > 0
54
+ if @left_char == 0
55
+ CDK.Beep
56
+ else
57
+ @left_char -= 1
58
+ end
59
+ else
60
+ CDK.Beep
61
+ end
62
+ end
63
+
64
+ def KEY_RIGHT
65
+ if @list_size > 0
66
+ if @left_char >= @max_left_char
67
+ CDK.Beep
68
+ else
69
+ @left_char += 1
70
+ end
71
+ else
72
+ CDK.Beep
73
+ end
74
+ end
75
+
76
+ def KEY_PPAGE
77
+ if @list_size > 0
78
+ if @current_top > 0
79
+ if @current_top >= @view_size - 1
80
+ @current_top -= @view_size - 1
81
+ @current_item -= @view_size - 1
82
+ else
83
+ self.KEY_HOME
84
+ end
85
+ else
86
+ CDK.Beep
87
+ end
88
+ else
89
+ CDK.Beep
90
+ end
91
+ end
92
+
93
+ def KEY_NPAGE
94
+ if @list_size > 0
95
+ if @current_top < @max_top_item
96
+ if @current_top + @view_size - 1 <= @max_top_item
97
+ @current_top += @view_size - 1
98
+ @current_item += @view_size - 1
99
+ else
100
+ @current_top = @max_top_item
101
+ @current_item = @last_item
102
+ @current_high = @view_size - 1
103
+ end
104
+ else
105
+ CDK.Beep
106
+ end
107
+ else
108
+ CDK.Beep
109
+ end
110
+ end
111
+
112
+ def KEY_HOME
113
+ @current_top = 0
114
+ @current_item = 0
115
+ @current_high = 0
116
+ end
117
+
118
+ def KEY_END
119
+ if @max_top_item == -1
120
+ @current_top = 0
121
+ @current_item = @last_item - 1
122
+ else
123
+ @current_top = @max_top_item
124
+ @current_item = @last_item
125
+ end
126
+ @current_high = @view_size - 1
127
+ end
128
+
129
+ def maxViewSize
130
+ return @box_height - (2 * @border_size + @title_lines)
131
+ end
132
+
133
+ # Set variables that depend upon the list_size
134
+ def setViewSize(list_size)
135
+ @view_size = self.maxViewSize
136
+ @list_size = list_size
137
+ @last_item = list_size - 1
138
+ @max_top_item = list_size - @view_size
139
+
140
+ if list_size < @view_size
141
+ @view_size = list_size
142
+ @max_top_item = 0
143
+ end
144
+
145
+ if @list_size > 0 && self.maxViewSize > 0
146
+ @step = 1.0 * self.maxViewSize / @list_size
147
+ @toggle_size = if @list_size > self.maxViewSize
148
+ then 1
149
+ else @step.ceil
150
+ end
151
+ else
152
+ @step = 1
153
+ @toggle_size = 1
154
+ end
155
+ end
156
+
157
+ def setPosition(item)
158
+ if item <= 0
159
+ self.KEY_HOME
160
+ elsif item > @list_size - 1
161
+ @current_top = @max_top_item
162
+ @current_item = @list_size - 1
163
+ @current_high = @view_size - 1
164
+ elsif item >= @current_top && item < @current_top + @view_size
165
+ @current_item = item
166
+ @current_high = item - @current_top
167
+ else
168
+ @current_top = item - (@view_size - 1)
169
+ @current_item = item
170
+ @current_high = @view_size - 1
171
+ end
172
+ end
173
+
174
+ # Get/Set the current item number of the scroller.
175
+ def getCurrentItem
176
+ @current_item
177
+ end
178
+
179
+ def setCurrentItem(item)
180
+ self.setPosition(item);
181
+ end
182
+ end
183
+ end