Class: RNDK::Scroller
Overview
Note:
Do not instantiate this class!
Use it's subclasses.
Common actions and functionality between
scrolling Widgets.
Instance Attribute Summary
Attributes inherited from Widget
#BXAttr, #HZChar, #LLChar, #LRChar, #ULChar, #URChar, #VTChar, #accepts_focus, #binding_list, #border_size, #box, #exit_type, #has_focus, #is_visible, #screen, #screen_index, #supported_signals, #widget_type
Instance Method Summary
collapse
Methods inherited from Widget
#Screen_XPOS, #Screen_YPOS, #after_processing, #before_processing, #bind_key, #bind_signal, #bindable_widget, #clean_bindings, #clean_title, #destroy, #draw, #draw_title, #erase, #focus, #get_box, #getch, #inject, #is_bound?, #move, #position, #refresh_data, #run_key_binding, #run_signal_binding, #save_data, #setBXattr, #setHZchar, #setLLchar, #setLRchar, #setULchar, #setURchar, #setVTchar, #set_bg_color, #set_box, #set_exit_type, #set_title, #unbind_key, #unfocus, #valid?, #valid_type?
Constructor Details
Returns a new instance of Scroller.
12
13
14
|
# File 'lib/rndk/scroller.rb', line 12
def initialize
super()
end
|
Instance Method Details
#get_current_item ⇒ Object
Get/Set the current item number of the scroller.
183
184
185
|
# File 'lib/rndk/scroller.rb', line 183
def get_current_item
@current_item
end
|
#max_view_size ⇒ Object
137
138
139
|
# File 'lib/rndk/scroller.rb', line 137
def max_view_size
return @box_height - (2 * @border_size + @title_lines)
end
|
120
121
122
123
124
|
# File 'lib/rndk/scroller.rb', line 120
def scroll_begin
@current_top = 0
@current_item = 0
@current_high = 0
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rndk/scroller.rb', line 38
def scroll_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
RNDK.beep
end
else
@current_item += 1
@current_high += 1
end
else
RNDK.beep
end
else
RNDK.beep
end
end
|
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/rndk/scroller.rb', line 126
def scroll_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
|
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/rndk/scroller.rb', line 60
def scroll_left
if @list_size > 0
if @left_char == 0
RNDK.beep
else
@left_char -= 1
end
else
RNDK.beep
end
end
|
#scroll_page_down ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/rndk/scroller.rb', line 101
def scroll_page_down
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
RNDK.beep
end
else
RNDK.beep
end
end
|
#scroll_page_up ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/rndk/scroller.rb', line 84
def scroll_page_up
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.scroll_begin
end
else
RNDK.beep
end
else
RNDK.beep
end
end
|
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/rndk/scroller.rb', line 72
def scroll_right
if @list_size > 0
if @left_char >= @max_left_char
RNDK.beep
else
@left_char += 1
end
else
RNDK.beep
end
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rndk/scroller.rb', line 16
def scroll_up
if @list_size > 0
if @current_item > 0
if @current_high == 0
if @current_top != 0
@current_top -= 1
@current_item -= 1
else
RNDK.beep
end
else
@current_item -= 1
@current_high -= 1
end
else
RNDK.beep
end
else
RNDK.beep
end
end
|
#set_current_item(item) ⇒ Object
187
188
189
|
# File 'lib/rndk/scroller.rb', line 187
def set_current_item(item)
self.set_position(item);
end
|
#set_position(item) ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/rndk/scroller.rb', line 165
def set_position(item)
if item <= 0
self.scroll_begin
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
|
#set_view_size(list_size) ⇒ Object
Set variables that depend upon the list_size
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/rndk/scroller.rb', line 142
def set_view_size(list_size)
@view_size = self.max_view_size
@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.max_view_size > 0
@step = 1.0 * self.max_view_size / @list_size
@toggle_size = if @list_size > self.max_view_size
then 1
else @step.ceil
end
else
@step = 1
@toggle_size = 1
end
end
|