rndk 0.2.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +13 -4
- data/TODO +21 -1
- data/demos/appointment.rb +279 -299
- data/demos/clock.rb +13 -8
- data/demos/rss-reader.rb +84 -0
- data/examples/01-hello-world.rb +13 -11
- data/examples/02-colors.rb +14 -21
- data/examples/03-markup.rb +7 -7
- data/examples/04-quick-widgets.rb +2 -2
- data/examples/05-position-widget.rb +50 -31
- data/examples/06-callbacks.rb +77 -0
- data/examples/07-traverse.rb +90 -0
- data/examples/10-all-widgets.rb +165 -0
- data/examples/calendar.rb +20 -32
- data/examples/entry.rb +15 -20
- data/examples/label.rb +11 -11
- data/examples/scroll.rb +16 -60
- data/examples/slider.rb +18 -19
- data/examples/viewer.rb +65 -0
- data/lib/rndk.rb +28 -7
- data/lib/rndk/alphalist.rb +309 -313
- data/lib/rndk/button.rb +239 -157
- data/lib/rndk/buttonbox.rb +136 -103
- data/lib/rndk/calendar.rb +246 -203
- data/lib/rndk/core/color.rb +63 -13
- data/lib/rndk/core/display.rb +1 -1
- data/lib/rndk/core/draw.rb +11 -11
- data/lib/rndk/core/markup.rb +21 -21
- data/lib/rndk/core/quick_widgets.rb +75 -96
- data/lib/rndk/core/screen.rb +145 -102
- data/lib/rndk/core/traverse.rb +150 -136
- data/lib/rndk/core/utils.rb +5 -6
- data/lib/rndk/core/widget.rb +207 -191
- data/lib/rndk/core/widget_bind.rb +108 -0
- data/lib/rndk/dialog.rb +88 -56
- data/lib/rndk/entry.rb +79 -64
- data/lib/rndk/fscale.rb +38 -20
- data/lib/rndk/fslider.rb +38 -23
- data/lib/rndk/graph.rb +92 -53
- data/lib/rndk/itemlist.rb +80 -62
- data/lib/rndk/label.rb +111 -77
- data/lib/rndk/radio.rb +138 -128
- data/lib/rndk/scale.rb +123 -122
- data/lib/rndk/scroll.rb +444 -391
- data/lib/rndk/scroller.rb +21 -21
- data/lib/rndk/slider.rb +149 -140
- data/lib/rndk/template.rb +74 -61
- data/lib/rndk/version.rb +1 -1
- data/lib/rndk/viewer.rb +499 -298
- metadata +8 -14
- data/demos/fileview.rb +0 -141
- data/lib/rndk/dscale.rb +0 -13
- data/lib/rndk/fselect.rb +0 -938
- data/lib/rndk/histogram.rb +0 -412
- data/lib/rndk/marquee.rb +0 -244
- data/lib/rndk/matrix.rb +0 -1189
- data/lib/rndk/mentry.rb +0 -619
- data/lib/rndk/menu.rb +0 -478
- data/lib/rndk/selection.rb +0 -630
- data/lib/rndk/swindow.rb +0 -766
- data/lib/rndk/uscale.rb +0 -14
- data/lib/rndk/uslider.rb +0 -14
data/lib/rndk/scroller.rb
CHANGED
@@ -7,13 +7,13 @@ module RNDK
|
|
7
7
|
#
|
8
8
|
# @note Do **not** instantiate this class!
|
9
9
|
# Use it's subclasses.
|
10
|
-
class
|
10
|
+
class Scroller < Widget
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
super()
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def scroll_up
|
17
17
|
if @list_size > 0
|
18
18
|
if @current_item > 0
|
19
19
|
if @current_high == 0
|
@@ -35,7 +35,7 @@ module RNDK
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def scroll_down
|
39
39
|
if @list_size > 0
|
40
40
|
if @current_item < @list_size - 1
|
41
41
|
if @current_high == @view_size - 1
|
@@ -57,7 +57,7 @@ module RNDK
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def scroll_left
|
61
61
|
if @list_size > 0
|
62
62
|
if @left_char == 0
|
63
63
|
RNDK.beep
|
@@ -69,7 +69,7 @@ module RNDK
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
72
|
+
def scroll_right
|
73
73
|
if @list_size > 0
|
74
74
|
if @left_char >= @max_left_char
|
75
75
|
RNDK.beep
|
@@ -81,14 +81,14 @@ module RNDK
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def scroll_page_up
|
85
85
|
if @list_size > 0
|
86
86
|
if @current_top > 0
|
87
87
|
if @current_top >= @view_size - 1
|
88
88
|
@current_top -= @view_size - 1
|
89
89
|
@current_item -= @view_size - 1
|
90
90
|
else
|
91
|
-
self.
|
91
|
+
self.scroll_begin
|
92
92
|
end
|
93
93
|
else
|
94
94
|
RNDK.beep
|
@@ -98,7 +98,7 @@ module RNDK
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def scroll_page_down
|
102
102
|
if @list_size > 0
|
103
103
|
if @current_top < @max_top_item
|
104
104
|
if @current_top + @view_size - 1 <= @max_top_item
|
@@ -117,13 +117,13 @@ module RNDK
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
120
|
+
def scroll_begin
|
121
121
|
@current_top = 0
|
122
122
|
@current_item = 0
|
123
123
|
@current_high = 0
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
126
|
+
def scroll_end
|
127
127
|
if @max_top_item == -1
|
128
128
|
@current_top = 0
|
129
129
|
@current_item = @last_item - 1
|
@@ -134,13 +134,13 @@ module RNDK
|
|
134
134
|
@current_high = @view_size - 1
|
135
135
|
end
|
136
136
|
|
137
|
-
def
|
137
|
+
def max_view_size
|
138
138
|
return @box_height - (2 * @border_size + @title_lines)
|
139
139
|
end
|
140
140
|
|
141
141
|
# Set variables that depend upon the list_size
|
142
|
-
def
|
143
|
-
@view_size = self.
|
142
|
+
def set_view_size(list_size)
|
143
|
+
@view_size = self.max_view_size
|
144
144
|
@list_size = list_size
|
145
145
|
@last_item = list_size - 1
|
146
146
|
@max_top_item = list_size - @view_size
|
@@ -150,9 +150,9 @@ module RNDK
|
|
150
150
|
@max_top_item = 0
|
151
151
|
end
|
152
152
|
|
153
|
-
if @list_size > 0 && self.
|
154
|
-
@step = 1.0 * self.
|
155
|
-
@toggle_size = if @list_size > self.
|
153
|
+
if @list_size > 0 && self.max_view_size > 0
|
154
|
+
@step = 1.0 * self.max_view_size / @list_size
|
155
|
+
@toggle_size = if @list_size > self.max_view_size
|
156
156
|
then 1
|
157
157
|
else @step.ceil
|
158
158
|
end
|
@@ -162,9 +162,9 @@ module RNDK
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
def
|
165
|
+
def set_position(item)
|
166
166
|
if item <= 0
|
167
|
-
self.
|
167
|
+
self.scroll_begin
|
168
168
|
elsif item > @list_size - 1
|
169
169
|
@current_top = @max_top_item
|
170
170
|
@current_item = @list_size - 1
|
@@ -180,12 +180,12 @@ module RNDK
|
|
180
180
|
end
|
181
181
|
|
182
182
|
# Get/Set the current item number of the scroller.
|
183
|
-
def
|
183
|
+
def get_current_item
|
184
184
|
@current_item
|
185
185
|
end
|
186
186
|
|
187
|
-
def
|
188
|
-
self.
|
187
|
+
def set_current_item(item)
|
188
|
+
self.set_position(item);
|
189
189
|
end
|
190
190
|
|
191
191
|
end
|
data/lib/rndk/slider.rb
CHANGED
@@ -15,18 +15,18 @@ module RNDK
|
|
15
15
|
# Next Page:: Increments the field by the accelerated increment value.
|
16
16
|
# D:: Increments the field by the accelerated increment value.
|
17
17
|
# Ctrl-F:: Increments the field by the accelerated increment value.
|
18
|
-
# Home:: Sets the value to the
|
19
|
-
# g:: Sets the value to the
|
20
|
-
# End:: Sets the value to the
|
21
|
-
# G:: Sets the value to the
|
22
|
-
# $:: Sets the value to the
|
18
|
+
# Home:: Sets the value to the minimum value.
|
19
|
+
# g:: Sets the value to the minimum value.
|
20
|
+
# End:: Sets the value to the maximum value.
|
21
|
+
# G:: Sets the value to the maximum value.
|
22
|
+
# $:: Sets the value to the maximum value.
|
23
23
|
# Return:: Exits the widget and returns the current value. This also sets the widget data `exit_type` to `:NORMAL`.
|
24
24
|
# Tab:: Exits the widget and returns the current value. This also sets the widget data `exit_type` to `:NORMAL`.
|
25
25
|
# Escape:: Exits the widget and returns `nil`. Also sets the widget data `exit_type` to `:ESCAPE_HIT`.
|
26
26
|
# Ctrl-L:: Refreshes the screen.
|
27
27
|
#
|
28
28
|
# If the cursor is not pointing to the field's value,
|
29
|
-
# the
|
29
|
+
# the folminimuming key bindings apply.
|
30
30
|
#
|
31
31
|
# You may use the left/right arrows to move the cursor
|
32
32
|
# onto the field's value and modify it by typing characters
|
@@ -38,15 +38,15 @@ module RNDK
|
|
38
38
|
# D:: Increments the scale by the accelerated value.
|
39
39
|
# -:: Decrements the scale by the normal value.
|
40
40
|
# +:: Increments the scale by the normal value.
|
41
|
-
# 0:: Sets the scale to the
|
41
|
+
# 0:: Sets the scale to the minimum value.
|
42
42
|
#
|
43
43
|
class Slider < Widget
|
44
44
|
|
45
45
|
# Creates a new Slider Widget.
|
46
46
|
#
|
47
|
-
# * `
|
47
|
+
# * `x` is the x position - can be an integer or
|
48
48
|
# `RNDK::LEFT`, `RNDK::RIGHT`, `RNDK::CENTER`.
|
49
|
-
# * `
|
49
|
+
# * `y` is the y position - can be an integer or
|
50
50
|
# `RNDK::TOP`, `RNDK::BOTTOM`, `RNDK::CENTER`.
|
51
51
|
# * `title` can be more than one line - just split them
|
52
52
|
# with `\n`s.
|
@@ -59,54 +59,63 @@ module RNDK
|
|
59
59
|
# If it's a negative value, will create with full width
|
60
60
|
# minus that value.
|
61
61
|
# * `start` is the initial value of the widget.
|
62
|
-
# * `
|
62
|
+
# * `minimum`/`maximum` are the minimum and maximum values of
|
63
63
|
# the slider.
|
64
64
|
# * `inc` is the increment value.
|
65
65
|
# * `fast_inc` is the accelerated increment value.
|
66
66
|
# * `box` if the Widget is drawn with a box outside it.
|
67
67
|
# * `shadow` turns on/off the shadow around the Widget.
|
68
68
|
#
|
69
|
-
def initialize(
|
70
|
-
xplace,
|
71
|
-
yplace,
|
72
|
-
title,
|
73
|
-
label,
|
74
|
-
filler,
|
75
|
-
field_width,
|
76
|
-
start,
|
77
|
-
low,
|
78
|
-
high,
|
79
|
-
inc,
|
80
|
-
fast_inc,
|
81
|
-
box,
|
82
|
-
shadow)
|
69
|
+
def initialize(screen, config={})
|
83
70
|
super()
|
71
|
+
@widget_type = :slider
|
72
|
+
@supported_signals += [:before_input, :after_input]
|
73
|
+
|
74
|
+
x = 0
|
75
|
+
y = 0
|
76
|
+
title = "slider"
|
77
|
+
label = "label"
|
78
|
+
filler = ' '.ord | RNDK::Color[:reverse]
|
79
|
+
field_width = 0
|
80
|
+
start = 0
|
81
|
+
minimum = 0
|
82
|
+
maximum = 100
|
83
|
+
increment = 1
|
84
|
+
fast_increment = 5
|
85
|
+
box = true
|
86
|
+
shadow = false
|
87
|
+
|
88
|
+
config.each do |key, val|
|
89
|
+
x = val if key == :x
|
90
|
+
y = val if key == :y
|
91
|
+
title = val if key == :title
|
92
|
+
label = val if key == :label
|
93
|
+
filler = val if key == :filler
|
94
|
+
field_width = val if key == :field_width
|
95
|
+
start = val if key == :start
|
96
|
+
minimum = val if key == :minimum
|
97
|
+
maximum = val if key == :maximum
|
98
|
+
increment = val if key == :inc
|
99
|
+
fast_increment = val if key == :fast_inc
|
100
|
+
box = val if key == :box
|
101
|
+
shadow = val if key == :shadow
|
102
|
+
end
|
84
103
|
|
85
|
-
parent_width = Ncurses.getmaxx
|
86
|
-
parent_height = Ncurses.getmaxy
|
87
|
-
|
88
|
-
|
89
|
-
'u' => Ncurses::KEY_UP,
|
90
|
-
'U' => Ncurses::KEY_PPAGE,
|
91
|
-
RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
|
92
|
-
RNDK::FORCHAR => Ncurses::KEY_NPAGE,
|
93
|
-
'g' => Ncurses::KEY_HOME,
|
94
|
-
'^' => Ncurses::KEY_HOME,
|
95
|
-
'G' => Ncurses::KEY_END,
|
96
|
-
'$' => Ncurses::KEY_END,
|
97
|
-
}
|
98
|
-
self.set_box(box)
|
104
|
+
parent_width = Ncurses.getmaxx screen.window
|
105
|
+
parent_height = Ncurses.getmaxy screen.window
|
106
|
+
|
107
|
+
self.set_box box
|
99
108
|
box_height = @border_size * 2 + 1
|
100
109
|
|
101
110
|
# Set some basic values of the widget's data field.
|
102
111
|
@label = []
|
103
112
|
@label_len = 0
|
104
113
|
@label_win = nil
|
105
|
-
|
114
|
+
maximum_value_len = self.formattedSize maximum
|
106
115
|
|
107
116
|
# If the field_width is a negative will be COLS-field_width,
|
108
117
|
# otherwise field_width will be the given width.
|
109
|
-
field_width = RNDK.
|
118
|
+
field_width = RNDK.set_widget_dimension(parent_width, field_width, 0)
|
110
119
|
|
111
120
|
# Translate the label string to a chtype array.
|
112
121
|
if !(label.nil?) && label.size > 0
|
@@ -114,9 +123,9 @@ module RNDK
|
|
114
123
|
@label = RNDK.char2Chtype(label, label_len, [])
|
115
124
|
@label_len = label_len[0]
|
116
125
|
box_width = @label_len + field_width +
|
117
|
-
|
126
|
+
maximum_value_len + 2 * @border_size
|
118
127
|
else
|
119
|
-
box_width = field_width +
|
128
|
+
box_width = field_width + maximum_value_len + 2 * @border_size
|
120
129
|
end
|
121
130
|
|
122
131
|
old_width = box_width
|
@@ -128,12 +137,12 @@ module RNDK
|
|
128
137
|
# Make sure we didn't extend beyond the dimensions of the window.
|
129
138
|
box_width = [box_width, parent_width].min
|
130
139
|
box_height = [box_height, parent_height].min
|
131
|
-
field_width = [field_width, box_width - @label_len -
|
140
|
+
field_width = [field_width, box_width - @label_len - maximum_value_len - 1].min
|
132
141
|
|
133
142
|
# Rejustify the x and y positions if we need to.
|
134
|
-
xtmp = [
|
135
|
-
ytmp = [
|
136
|
-
RNDK.alignxy(
|
143
|
+
xtmp = [x]
|
144
|
+
ytmp = [y]
|
145
|
+
RNDK.alignxy(screen.window, xtmp, ytmp, box_width, box_height)
|
137
146
|
xpos = xtmp[0]
|
138
147
|
ypos = ytmp[0]
|
139
148
|
|
@@ -162,7 +171,7 @@ module RNDK
|
|
162
171
|
# Create the widget's data field window.
|
163
172
|
@field_win = Ncurses.subwin(@win,
|
164
173
|
1,
|
165
|
-
field_width +
|
174
|
+
field_width + maximum_value_len - 1,
|
166
175
|
ypos + @title_lines + @border_size,
|
167
176
|
xpos + @label_len + horizontal_adjust + @border_size)
|
168
177
|
|
@@ -174,26 +183,26 @@ module RNDK
|
|
174
183
|
Ncurses.keypad(@win, true)
|
175
184
|
|
176
185
|
# Create the widget's data field.
|
177
|
-
@screen =
|
178
|
-
@window =
|
186
|
+
@screen = screen
|
187
|
+
@window = screen.window
|
179
188
|
@shadow_win = nil
|
180
189
|
@box_width = box_width
|
181
190
|
@box_height = box_height
|
182
191
|
@field_width = field_width - 1
|
183
192
|
@filler = filler
|
184
|
-
@
|
185
|
-
@
|
193
|
+
@minimum = minimum
|
194
|
+
@maximum = maximum
|
186
195
|
@current = start
|
187
|
-
@
|
188
|
-
@
|
196
|
+
@increment = increment
|
197
|
+
@fast_increment = fast_increment
|
189
198
|
@accepts_focus = true
|
190
199
|
@input_window = @win
|
191
200
|
@shadow = shadow
|
192
201
|
@field_edit = 0
|
193
202
|
|
194
203
|
# Set the start value.
|
195
|
-
if start <
|
196
|
-
@current =
|
204
|
+
if start < minimum
|
205
|
+
@current = minimum
|
197
206
|
end
|
198
207
|
|
199
208
|
# Do we want a shadow?
|
@@ -209,11 +218,14 @@ module RNDK
|
|
209
218
|
end
|
210
219
|
|
211
220
|
# Setup the key bindings.
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
221
|
+
self.bind_key('u') { self.increment @increment }
|
222
|
+
self.bind_key('U') { self.increment @fast_increment }
|
223
|
+
self.bind_key('g') { @current = @minimum }
|
224
|
+
self.bind_key('^') { @current = @minimum }
|
225
|
+
self.bind_key('G') { @current = @maximum }
|
226
|
+
self.bind_key('$') { @current = @maximum }
|
227
|
+
|
228
|
+
screen.register(@widget_type, self)
|
217
229
|
end
|
218
230
|
|
219
231
|
# Activates the Widget, letting the user interact with it.
|
@@ -223,11 +235,11 @@ module RNDK
|
|
223
235
|
#
|
224
236
|
# @return The current value of the slider.
|
225
237
|
def activate(actions=[])
|
226
|
-
self.draw
|
238
|
+
self.draw
|
227
239
|
|
228
240
|
if actions.nil? || actions.size == 0
|
229
241
|
while true
|
230
|
-
input = self.getch
|
242
|
+
input = self.getch
|
231
243
|
|
232
244
|
# Inject the character into the widget.
|
233
245
|
ret = self.inject(input)
|
@@ -250,13 +262,13 @@ module RNDK
|
|
250
262
|
return nil
|
251
263
|
end
|
252
264
|
|
253
|
-
# Check if the value lies outside the
|
265
|
+
# Check if the value lies outside the minimum/maximum range. If so, force it in.
|
254
266
|
def limitCurrentValue
|
255
|
-
if @current < @
|
256
|
-
@current = @
|
267
|
+
if @current < @minimum
|
268
|
+
@current = @minimum
|
257
269
|
RNDK.beep
|
258
|
-
elsif @current > @
|
259
|
-
@current = @
|
270
|
+
elsif @current > @maximum
|
271
|
+
@current = @maximum
|
260
272
|
RNDK.beep
|
261
273
|
end
|
262
274
|
end
|
@@ -278,7 +290,7 @@ module RNDK
|
|
278
290
|
return false
|
279
291
|
end
|
280
292
|
ch = Ncurses.winch(@field_win)
|
281
|
-
if RNDK.
|
293
|
+
if RNDK.char_of(ch) != ' '
|
282
294
|
return true
|
283
295
|
end
|
284
296
|
if new_position > 1
|
@@ -287,13 +299,13 @@ module RNDK
|
|
287
299
|
return false
|
288
300
|
end
|
289
301
|
ch = Ncurses.winch(@field_win)
|
290
|
-
return RNDK.
|
302
|
+
return RNDK.char_of(ch) != ' '
|
291
303
|
end
|
292
304
|
return false
|
293
305
|
end
|
294
306
|
|
295
307
|
# Set the edit position. Normally the cursor is one cell to the right of
|
296
|
-
# the editable field. Moving it left, over the field,
|
308
|
+
# the editable field. Moving it left, over the field, alminimums the user to
|
297
309
|
# modify cells by typing in replacement characters for the field's value.
|
298
310
|
def setEditPosition(new_position)
|
299
311
|
if new_position < 0
|
@@ -351,8 +363,8 @@ module RNDK
|
|
351
363
|
end
|
352
364
|
if modify &&
|
353
365
|
((value, test) = temp.scanf(self.SCAN_FMT)).size == 2 &&
|
354
|
-
test == ' ' && value >= @
|
355
|
-
self.
|
366
|
+
test == ' ' && value >= @minimum && value <= @maximum
|
367
|
+
self.set_value(value)
|
356
368
|
result = true
|
357
369
|
end
|
358
370
|
return result
|
@@ -376,28 +388,24 @@ module RNDK
|
|
376
388
|
|
377
389
|
# @see Widget#inject
|
378
390
|
def inject input
|
379
|
-
pp_return =
|
391
|
+
pp_return = true
|
380
392
|
ret = nil
|
381
393
|
complete = false
|
382
394
|
|
383
|
-
|
384
|
-
self.set_exit_type(0)
|
395
|
+
self.set_exit_type 0
|
385
396
|
|
386
|
-
|
387
|
-
self.drawField
|
397
|
+
self.draw_field
|
388
398
|
|
389
399
|
# Check if there is a pre-process function to be called.
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
@pre_process_data, input)
|
394
|
-
end
|
400
|
+
keep_going = self.run_signal_binding(:before_input, input)
|
401
|
+
|
402
|
+
if keep_going
|
395
403
|
|
396
|
-
# Should we continue?
|
397
|
-
if pp_return != 0
|
398
404
|
# Check for a key binding.
|
399
|
-
if self.
|
400
|
-
|
405
|
+
if self.is_bound? input
|
406
|
+
self.run_key_binding input
|
407
|
+
#complete = true
|
408
|
+
|
401
409
|
else
|
402
410
|
case input
|
403
411
|
when Ncurses::KEY_LEFT
|
@@ -405,17 +413,17 @@ module RNDK
|
|
405
413
|
when Ncurses::KEY_RIGHT
|
406
414
|
self.setEditPosition(@field_edit - 1)
|
407
415
|
when Ncurses::KEY_DOWN
|
408
|
-
|
416
|
+
self.decrement @increment
|
409
417
|
when Ncurses::KEY_UP
|
410
|
-
|
411
|
-
when Ncurses::KEY_PPAGE
|
412
|
-
|
413
|
-
when Ncurses::KEY_NPAGE
|
414
|
-
|
418
|
+
self.increment @increment
|
419
|
+
when Ncurses::KEY_PPAGE, RNDK::BACKCHAR
|
420
|
+
self.increment @fast_increment
|
421
|
+
when Ncurses::KEY_NPAGE, RNDK::FORCHAR
|
422
|
+
self.decrement @fast_increment
|
415
423
|
when Ncurses::KEY_HOME
|
416
|
-
@current = @
|
424
|
+
@current = @minimum
|
417
425
|
when Ncurses::KEY_END
|
418
|
-
@current = @
|
426
|
+
@current = @maximum
|
419
427
|
when RNDK::KEY_TAB, RNDK::KEY_RETURN, Ncurses::KEY_ENTER
|
420
428
|
self.set_exit_type(input)
|
421
429
|
ret = @current
|
@@ -453,16 +461,12 @@ module RNDK
|
|
453
461
|
end
|
454
462
|
end
|
455
463
|
self.limitCurrentValue
|
456
|
-
|
457
|
-
# Should we call a post-process?
|
458
|
-
if !complete && !(@post_process_func.nil?)
|
459
|
-
@post_process_func.call(:slider, self, @post_process_data, input)
|
460
|
-
end
|
464
|
+
self.run_signal_binding(:after_input) if not complete
|
461
465
|
end
|
462
466
|
|
463
|
-
if
|
464
|
-
self.
|
465
|
-
self.set_exit_type
|
467
|
+
if not complete
|
468
|
+
self.draw_field
|
469
|
+
self.set_exit_type 0
|
466
470
|
end
|
467
471
|
|
468
472
|
@return_data = 0
|
@@ -470,24 +474,24 @@ module RNDK
|
|
470
474
|
end
|
471
475
|
|
472
476
|
# @see Widget#move
|
473
|
-
def move(
|
477
|
+
def move(x, y, relative, refresh_flag)
|
474
478
|
windows = [@win, @label_win, @field_win, @shadow_win]
|
475
479
|
|
476
|
-
self.move_specific(
|
480
|
+
self.move_specific(x, y, relative, refresh_flag, windows, [])
|
477
481
|
end
|
478
482
|
|
479
483
|
# Draws the Widget on the Screen.
|
480
484
|
#
|
481
485
|
# If `box` is true, it is drawn with a box.
|
482
|
-
def draw
|
486
|
+
def draw
|
483
487
|
|
484
488
|
# Draw the shadow.
|
485
489
|
Draw.drawShadow(@shadow_win) unless @shadow_win.nil?
|
486
490
|
|
487
491
|
# Box the widget if asked.
|
488
|
-
Draw.drawObjBox(@win, self) if box
|
492
|
+
Draw.drawObjBox(@win, self) if @box
|
489
493
|
|
490
|
-
self.
|
494
|
+
self.draw_title @win
|
491
495
|
|
492
496
|
# Draw the label.
|
493
497
|
unless @label_win.nil?
|
@@ -498,15 +502,15 @@ module RNDK
|
|
498
502
|
Ncurses.wrefresh @win
|
499
503
|
|
500
504
|
# Draw the field window.
|
501
|
-
self.
|
505
|
+
self.draw_field
|
502
506
|
end
|
503
507
|
|
504
508
|
# This draws the widget.
|
505
|
-
def
|
506
|
-
step = 1.0 * @field_width / (@
|
509
|
+
def draw_field
|
510
|
+
step = 1.0 * @field_width / (@maximum - @minimum)
|
507
511
|
|
508
512
|
# Determine how many filler characters need to be drawn.
|
509
|
-
filler_characters = (@current - @
|
513
|
+
filler_characters = (@current - @minimum) * step
|
510
514
|
|
511
515
|
Ncurses.werase(@field_win)
|
512
516
|
|
@@ -517,14 +521,14 @@ module RNDK
|
|
517
521
|
|
518
522
|
# Draw the value in the field.
|
519
523
|
Draw.writeCharAttrib(@field_win, @field_width, 0, @current.to_s,
|
520
|
-
|
524
|
+
RNDK::Color[:normal], RNDK::HORIZONTAL, 0, @current.to_s.size)
|
521
525
|
|
522
526
|
self.moveToEditPosition(@field_edit)
|
523
527
|
Ncurses.wrefresh(@field_win)
|
524
528
|
end
|
525
529
|
|
526
530
|
# This sets the background attribute of the widget.
|
527
|
-
def
|
531
|
+
def set_bg_color(attrib)
|
528
532
|
# Set the widget's background attribute.
|
529
533
|
Ncurses.wbkgd(@win, attrib)
|
530
534
|
Ncurses.wbkgd(@field_win, attrib)
|
@@ -533,7 +537,7 @@ module RNDK
|
|
533
537
|
|
534
538
|
# @see Widget#destroy
|
535
539
|
def destroy
|
536
|
-
self.
|
540
|
+
self.clean_title
|
537
541
|
@label = []
|
538
542
|
|
539
543
|
# Clean up the windows.
|
@@ -543,15 +547,15 @@ module RNDK
|
|
543
547
|
RNDK.window_delete(@win)
|
544
548
|
|
545
549
|
# Clean the key bindings.
|
546
|
-
self.clean_bindings
|
550
|
+
self.clean_bindings
|
547
551
|
|
548
|
-
# Unregister this
|
549
|
-
|
552
|
+
# Unregister this widget.
|
553
|
+
@screen.unregister self
|
550
554
|
end
|
551
555
|
|
552
556
|
# @see Widget#erase
|
553
557
|
def erase
|
554
|
-
if self.
|
558
|
+
if self.valid?
|
555
559
|
RNDK.window_erase @label_win
|
556
560
|
RNDK.window_erase @field_win
|
557
561
|
RNDK.window_erase @lwin
|
@@ -563,52 +567,52 @@ module RNDK
|
|
563
567
|
return value.to_s.size
|
564
568
|
end
|
565
569
|
|
566
|
-
# This function sets the
|
567
|
-
def set(
|
568
|
-
self.
|
569
|
-
self.
|
570
|
+
# This function sets the minimum/maximum/current values of the widget.
|
571
|
+
def set(minimum, maximum, value, box)
|
572
|
+
self.setMinimumMaximum(minimum, maximum)
|
573
|
+
self.set_value(value)
|
570
574
|
self.set_box(box)
|
571
575
|
end
|
572
576
|
|
573
577
|
# This sets the widget's value.
|
574
|
-
def
|
578
|
+
def set_value(value)
|
575
579
|
@current = value
|
576
580
|
self.limitCurrentValue
|
577
581
|
end
|
578
582
|
|
579
|
-
def
|
583
|
+
def get_value
|
580
584
|
return @current
|
581
585
|
end
|
582
586
|
|
583
|
-
# This function sets the
|
584
|
-
def
|
587
|
+
# This function sets the minimum/maximum values of the widget.
|
588
|
+
def setMinimumMaximum(minimum, maximum)
|
585
589
|
# Make sure the values aren't out of bounds.
|
586
|
-
if
|
587
|
-
@
|
588
|
-
@
|
589
|
-
elsif
|
590
|
-
@
|
591
|
-
@
|
590
|
+
if minimum <= maximum
|
591
|
+
@minimum = minimum
|
592
|
+
@maximum = maximum
|
593
|
+
elsif minimum > maximum
|
594
|
+
@minimum = maximum
|
595
|
+
@maximum = minimum
|
592
596
|
end
|
593
597
|
|
594
598
|
# Make sure the user hasn't done something silly.
|
595
599
|
self.limitCurrentValue
|
596
600
|
end
|
597
601
|
|
598
|
-
def
|
599
|
-
return @
|
602
|
+
def getMinimumValue
|
603
|
+
return @minimum
|
600
604
|
end
|
601
605
|
|
602
|
-
def
|
603
|
-
return @
|
606
|
+
def getMaximumValue
|
607
|
+
return @maximum
|
604
608
|
end
|
605
609
|
|
606
610
|
def focus
|
607
|
-
self.draw
|
611
|
+
self.draw
|
608
612
|
end
|
609
613
|
|
610
614
|
def unfocus
|
611
|
-
self.draw
|
615
|
+
self.draw
|
612
616
|
end
|
613
617
|
|
614
618
|
def SCAN_FMT
|
@@ -619,8 +623,13 @@ module RNDK
|
|
619
623
|
super(@win)
|
620
624
|
end
|
621
625
|
|
622
|
-
def
|
623
|
-
|
626
|
+
def decrement by
|
627
|
+
@current = @current - by if (@current - by) < @current
|
624
628
|
end
|
629
|
+
|
630
|
+
def increment by
|
631
|
+
@current = @current + by if (@current + by) > @current
|
632
|
+
end
|
633
|
+
|
625
634
|
end
|
626
635
|
end
|