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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -4
  3. data/TODO +21 -1
  4. data/demos/appointment.rb +279 -299
  5. data/demos/clock.rb +13 -8
  6. data/demos/rss-reader.rb +84 -0
  7. data/examples/01-hello-world.rb +13 -11
  8. data/examples/02-colors.rb +14 -21
  9. data/examples/03-markup.rb +7 -7
  10. data/examples/04-quick-widgets.rb +2 -2
  11. data/examples/05-position-widget.rb +50 -31
  12. data/examples/06-callbacks.rb +77 -0
  13. data/examples/07-traverse.rb +90 -0
  14. data/examples/10-all-widgets.rb +165 -0
  15. data/examples/calendar.rb +20 -32
  16. data/examples/entry.rb +15 -20
  17. data/examples/label.rb +11 -11
  18. data/examples/scroll.rb +16 -60
  19. data/examples/slider.rb +18 -19
  20. data/examples/viewer.rb +65 -0
  21. data/lib/rndk.rb +28 -7
  22. data/lib/rndk/alphalist.rb +309 -313
  23. data/lib/rndk/button.rb +239 -157
  24. data/lib/rndk/buttonbox.rb +136 -103
  25. data/lib/rndk/calendar.rb +246 -203
  26. data/lib/rndk/core/color.rb +63 -13
  27. data/lib/rndk/core/display.rb +1 -1
  28. data/lib/rndk/core/draw.rb +11 -11
  29. data/lib/rndk/core/markup.rb +21 -21
  30. data/lib/rndk/core/quick_widgets.rb +75 -96
  31. data/lib/rndk/core/screen.rb +145 -102
  32. data/lib/rndk/core/traverse.rb +150 -136
  33. data/lib/rndk/core/utils.rb +5 -6
  34. data/lib/rndk/core/widget.rb +207 -191
  35. data/lib/rndk/core/widget_bind.rb +108 -0
  36. data/lib/rndk/dialog.rb +88 -56
  37. data/lib/rndk/entry.rb +79 -64
  38. data/lib/rndk/fscale.rb +38 -20
  39. data/lib/rndk/fslider.rb +38 -23
  40. data/lib/rndk/graph.rb +92 -53
  41. data/lib/rndk/itemlist.rb +80 -62
  42. data/lib/rndk/label.rb +111 -77
  43. data/lib/rndk/radio.rb +138 -128
  44. data/lib/rndk/scale.rb +123 -122
  45. data/lib/rndk/scroll.rb +444 -391
  46. data/lib/rndk/scroller.rb +21 -21
  47. data/lib/rndk/slider.rb +149 -140
  48. data/lib/rndk/template.rb +74 -61
  49. data/lib/rndk/version.rb +1 -1
  50. data/lib/rndk/viewer.rb +499 -298
  51. metadata +8 -14
  52. data/demos/fileview.rb +0 -141
  53. data/lib/rndk/dscale.rb +0 -13
  54. data/lib/rndk/fselect.rb +0 -938
  55. data/lib/rndk/histogram.rb +0 -412
  56. data/lib/rndk/marquee.rb +0 -244
  57. data/lib/rndk/matrix.rb +0 -1189
  58. data/lib/rndk/mentry.rb +0 -619
  59. data/lib/rndk/menu.rb +0 -478
  60. data/lib/rndk/selection.rb +0 -630
  61. data/lib/rndk/swindow.rb +0 -766
  62. data/lib/rndk/uscale.rb +0 -14
  63. data/lib/rndk/uslider.rb +0 -14
@@ -11,56 +11,77 @@ module RNDK
11
11
 
12
12
  # Creates a Label Widget.
13
13
  #
14
- # * `xplace` is the x position - can be an integer or `RNDK::LEFT`,
14
+ # * `x` is the x position - can be an integer or `RNDK::LEFT`,
15
15
  # `RNDK::RIGHT`, `RNDK::CENTER`.
16
- # * `yplace` is the y position - can be an integer or `RNDK::TOP`,
16
+ # * `y` is the y position - can be an integer or `RNDK::TOP`,
17
17
  # `RNDK::BOTTOM`, `RNDK::CENTER`.
18
- # * `message` is an Array of Strings with all the lines you'd want
19
- # to show. RNDK markup applies (see RNDK#Markup).
18
+ # * `message` is an Array of Strings with all the lines you'd
19
+ # want to show. RNDK markup applies (see RNDK#Markup).
20
20
  # * `box` if the Widget is drawn with a box outside it.
21
21
  # * `shadow` turns on/off the shadow around the Widget.
22
22
  #
23
23
  # If the Widget cannot be created, returns `nil`.
24
- def initialize(rndkscreen, xplace, yplace, mesg, box, shadow)
25
- return nil if mesg.class != Array or mesg.empty?
26
-
24
+ def initialize(screen, config={})
27
25
  super()
28
- rows = mesg.size
26
+ @widget_type = :label
27
+ @supported_signals += [:before_message_change]
28
+
29
+ # This is UGLY AS HELL
30
+ # But I don't have time to clean this up right now
31
+ # (lots of widgets, you know) :(
32
+ x = 0
33
+ y = 0
34
+ text = "label"
35
+ box = true
36
+ shadow = false
37
+
38
+ config.each do |key, val|
39
+ x = val if key == :x
40
+ y = val if key == :y
41
+ text = val if key == :text
42
+ box = val if key == :box
43
+ shadow = val if key == :shadow
44
+ end
45
+ # End of darkness
46
+
47
+ # Adjusting if the user sent us a String
48
+ text = [text] if text.class == String
49
+ return nil if text.class != Array or text.empty?
50
+ rows = text.size
29
51
 
30
- parent_width = Ncurses.getmaxx rndkscreen.window
31
- parent_height = Ncurses.getmaxy rndkscreen.window
52
+ parent_width = Ncurses.getmaxx screen.window
53
+ parent_height = Ncurses.getmaxy screen.window
32
54
  box_width = -2**30 # -INFINITY
33
55
  box_height = 0
34
- xpos = [xplace]
35
- ypos = [yplace]
36
- x = 0
56
+ x = [x]
57
+ y = [y]
37
58
 
38
59
  self.set_box box
39
60
  box_height = rows + 2*@border_size
40
61
 
41
- @info = []
42
- @info_len = []
43
- @info_pos = []
62
+ @text = []
63
+ @text_len = []
64
+ @text_pos = []
44
65
 
45
66
  # Determine the box width.
46
67
  (0...rows).each do |x|
47
68
 
48
69
  # Translate the string to a chtype array
49
- info_len = []
50
- info_pos = []
51
- @info << RNDK.char2Chtype(mesg[x], info_len, info_pos)
52
- @info_len << info_len[0]
53
- @info_pos << info_pos[0]
70
+ text_len = []
71
+ text_pos = []
72
+ @text << RNDK.char2Chtype(text[x], text_len, text_pos)
73
+ @text_len << text_len[0]
74
+ @text_pos << text_pos[0]
54
75
 
55
- box_width = [box_width, @info_len[x]].max
76
+ box_width = [box_width, @text_len[x]].max
56
77
  end
57
78
  box_width += 2 * @border_size
58
79
 
59
80
  # Create the string alignments.
60
81
  (0...rows).each do |x|
61
- @info_pos[x] = RNDK.justifyString(box_width - 2*@border_size,
62
- @info_len[x],
63
- @info_pos[x])
82
+ @text_pos[x] = RNDK.justifyString(box_width - 2*@border_size,
83
+ @text_len[x],
84
+ @text_pos[x])
64
85
  end
65
86
 
66
87
  # Make sure we didn't extend beyond the dimensions of the window.
@@ -74,20 +95,23 @@ module RNDK
74
95
  end
75
96
 
76
97
  # Rejustify the x and y positions if we need to
77
- RNDK.alignxy(rndkscreen.window, xpos, ypos, box_width, box_height)
78
-
79
- @screen = rndkscreen
80
- @parent = rndkscreen.window
81
- @win = Ncurses.newwin(box_height, box_width, ypos[0], xpos[0])
82
- @shadow_win = nil
83
- @xpos = xpos[0]
84
- @ypos = ypos[0]
85
- @rows = rows
98
+ RNDK.alignxy(screen.window, x, y, box_width, box_height)
99
+
100
+ @screen = screen
101
+ @parent = screen.window
102
+ @win = Ncurses.newwin(box_height,
103
+ box_width,
104
+ y[0],
105
+ x[0])
106
+ @shadow_win = nil
107
+ @x = x[0]
108
+ @y = y[0]
109
+ @rows = rows
86
110
  @box_width = box_width
87
111
  @box_height = box_height
88
112
  @input_window = @win
89
- @has_focus = false
90
- @shadow = shadow
113
+ @has_focus = false
114
+ @shadow = shadow
91
115
 
92
116
  if @win.nil?
93
117
  self.destroy
@@ -100,77 +124,83 @@ module RNDK
100
124
  if shadow
101
125
  @shadow_win = Ncurses.newwin(box_height,
102
126
  box_width,
103
- ypos[0] + 1,
104
- xpos[0] + 1)
127
+ y[0] + 1,
128
+ x[0] + 1)
105
129
  end
106
130
 
107
131
  # Register this
108
- rndkscreen.register(:label, self)
132
+ screen.register(@widget_type, self)
109
133
  end
110
134
 
111
135
  # Obsolete entrypoint which calls Label#draw.
112
136
  def activate(actions=[])
113
- self.draw @box
137
+ self.draw
114
138
  end
115
139
 
116
140
  # Sets multiple attributes of the Widget.
117
141
  #
118
142
  # See Label#initialize.
119
- def set(mesg, box)
120
- self.set_message mesg
121
- self.set_box box
143
+ def set(config)
144
+ # This is UGLY ATTRIBUTESS HELL
145
+ # But I don't have time to clean this up right now
146
+ # (lots of widgets, you know) :(
147
+ text = @text
148
+ box = @box
149
+ shadow = @shadow
150
+
151
+ config.each do |key, val|
152
+ text = val if key == :text
153
+ box = val if key == :box
154
+ shadow = val if key == :shadow
155
+ end
156
+
157
+ self.set_message text if text != @text
158
+ self.set_box box if box != @box
122
159
  end
123
160
 
124
161
  # Sets the contents of the Label Widget.
125
- # @note `info` is an Array of Strings.
126
- def set_message info
127
- return if info.class != Array or info.empty?
162
+ # @note `text` is an Array of Strings.
163
+ def set_message text
164
+ return if text.class != Array or text.empty?
165
+
166
+ keep_going = self.run_signal_binding(:before_message_change)
167
+ return if not keep_going
128
168
 
129
- info_size = info.size
130
169
  # Clean out the old message.
131
170
  (0...@rows).each do |x|
132
- @info[x] = ''
133
- @info_pos[x] = 0
134
- @info_len[x] = 0
171
+ @text[x] = ''
172
+ @text_pos[x] = 0
173
+ @text_len[x] = 0
135
174
  end
136
175
 
137
- @rows = if info_size < @rows
138
- then info_size
176
+ @rows = if text.size < @rows
177
+ then text.size
139
178
  else @rows
140
179
  end
141
180
 
142
181
  # Copy in the new message.
143
182
  (0...@rows).each do |x|
144
- info_len = []
145
- info_pos = []
146
- @info[x] = RNDK.char2Chtype(info[x], info_len, info_pos)
147
- @info_len[x] = info_len[0]
148
- @info_pos[x] = RNDK.justifyString(@box_width - 2 * @border_size,
149
- @info_len[x],
150
- info_pos[0])
183
+ text_len = []
184
+ text_pos = []
185
+ @text[x] = RNDK.char2Chtype(text[x], text_len, text_pos)
186
+ @text_len[x] = text_len[0]
187
+ @text_pos[x] = RNDK.justifyString(@box_width - 2 * @border_size,
188
+ @text_len[x],
189
+ text_pos[0])
151
190
  end
152
191
 
153
192
  # Redraw the label widget.
154
193
  self.erase
155
- self.draw @box
194
+ self.draw
156
195
  end
157
196
 
158
197
  # Returns current contents of the Widget.
159
- def get_message(size)
160
- size << @rows
161
- return @info
162
- end
163
-
164
- def object_type
165
- :label
166
- end
167
-
168
- def position
169
- super(@win)
198
+ def get_message
199
+ @text
170
200
  end
171
201
 
172
202
  # Sets the background attribute/color of the widget.
173
- def set_bg_attrib attrib
203
+ def set_bg_color attrib
174
204
  Ncurses.wbkgd(@win, attrib)
175
205
  end
176
206
 
@@ -188,12 +218,12 @@ module RNDK
188
218
  # Draw in the message.
189
219
  (0...@rows).each do |x|
190
220
  Draw.writeChtype(@win,
191
- @info_pos[x] + @border_size,
221
+ @text_pos[x] + @border_size,
192
222
  x + @border_size,
193
- @info[x],
223
+ @text[x],
194
224
  RNDK::HORIZONTAL,
195
225
  0,
196
- @info_len[x])
226
+ @text_len[x])
197
227
  end
198
228
 
199
229
  Ncurses.wrefresh @win
@@ -211,9 +241,9 @@ module RNDK
211
241
  RNDK.window_delete @shadow_win
212
242
  RNDK.window_delete @win
213
243
 
214
- self.clean_bindings :label
244
+ self.clean_bindings
215
245
 
216
- RNDK::Screen.unregister(:label, self)
246
+ @screen.unregister self
217
247
  end
218
248
 
219
249
  # Waits for the user to press a key.
@@ -235,6 +265,10 @@ module RNDK
235
265
  code
236
266
  end
237
267
 
268
+ def position
269
+ super(@win)
270
+ end
271
+
238
272
  end
239
273
  end
240
274
 
@@ -1,41 +1,64 @@
1
1
  require 'rndk/scroller'
2
2
 
3
3
  module RNDK
4
- class RADIO < SCROLLER
5
- def initialize(rndkscreen, xplace, yplace, splace, height, width, title,
6
- list, list_size, choice_char, def_item, highlight, box, shadow)
4
+
5
+ class Radio < Scroller
6
+
7
+ def initialize(screen, config={})
7
8
  super()
8
- parent_width = Ncurses.getmaxx(rndkscreen.window)
9
- parent_height = Ncurses.getmaxy(rndkscreen.window)
9
+ @widget_type = :radio
10
+ @supported_signals += [:before_input, :after_input]
11
+
12
+ x = 0
13
+ y = 0
14
+ splace = RNDK::RIGHT
15
+ width = 0
16
+ height = 0
17
+ title = "radio"
18
+ items = []
19
+ choice_char = '#'.ord | RNDK::Color[:reverse]
20
+ default = 0
21
+ highlight = RNDK::Color[:reverse]
22
+ box = true
23
+ shadow = false
24
+
25
+ config.each do |key, val|
26
+ x = val if key == :x
27
+ y = val if key == :y
28
+ splace = val if key == :splace
29
+ width = val if key == :width
30
+ height = val if key == :height
31
+ title = val if key == :title
32
+ items = val if key == :items
33
+ choice_char = val if key == :choice_char
34
+ default = val if key == :default
35
+ highlight = val if key == :highlight
36
+ box = val if key == :box
37
+ shadow = val if key == :shadow
38
+ end
39
+
40
+ items_size = items.size
41
+ parent_width = Ncurses.getmaxx(screen.window)
42
+ parent_height = Ncurses.getmaxy(screen.window)
10
43
  box_width = width
11
44
  box_height = height
12
45
  widest_item = 0
13
46
 
14
- bindings = {
15
- RNDK::BACKCHAR => Ncurses::KEY_PPAGE,
16
- RNDK::FORCHAR => Ncurses::KEY_NPAGE,
17
- 'g' => Ncurses::KEY_HOME,
18
- '1' => Ncurses::KEY_HOME,
19
- 'G' => Ncurses::KEY_END,
20
- '<' => Ncurses::KEY_HOME,
21
- '>' => Ncurses::KEY_END,
22
- }
23
-
24
- self.set_box(box)
47
+ self.set_box box
25
48
 
26
49
  # If the height is a negative value, height will be ROWS-height,
27
50
  # otherwise the height will be the given height.
28
- box_height = RNDK.setWidgetDimension(parent_height, height, 0)
51
+ box_height = RNDK.set_widget_dimension(parent_height, height, 0)
29
52
 
30
53
  # If the width is a negative value, the width will be COLS-width,
31
54
  # otherwise the width will be the given width.
32
- box_width = RNDK.setWidgetDimension(parent_width, width, 5)
55
+ box_width = RNDK.set_widget_dimension(parent_width, width, 5)
33
56
 
34
57
  box_width = self.set_title(title, box_width)
35
58
 
36
59
  # Set the box height.
37
60
  if @title_lines > box_height
38
- box_height = @title_lines + [list_size, 8].min + 2 * @border_size
61
+ box_height = @title_lines + [items_size, 8].min + 2 * @border_size
39
62
  end
40
63
 
41
64
  # Adjust the box width if there is a scroll bar.
@@ -50,21 +73,21 @@ module RNDK
50
73
  @box_width = [box_width, parent_width].min
51
74
  @box_height = [box_height, parent_height].min
52
75
 
53
- self.setViewSize(list_size)
76
+ self.set_view_size(items_size)
54
77
 
55
78
  # Each item in the needs to be converted to chtype array
56
- widest_item = self.createList(list, list_size, @box_width)
79
+ widest_item = self.create_items(items, @box_width)
57
80
  if widest_item > 0
58
81
  self.updateViewWidth(widest_item)
59
- elsif list_size > 0
82
+ elsif items_size > 0
60
83
  self.destroy
61
84
  return nil
62
85
  end
63
86
 
64
87
  # Rejustify the x and y positions if we need to.
65
- xtmp = [xplace]
66
- ytmp = [yplace]
67
- RNDK.alignxy(rndkscreen.window, xtmp, ytmp, @box_width, @box_height)
88
+ xtmp = [x]
89
+ ytmp = [y]
90
+ RNDK.alignxy(screen.window, xtmp, ytmp, @box_width, @box_height)
68
91
  xpos = xtmp[0]
69
92
  ypos = ytmp[0]
70
93
 
@@ -82,18 +105,18 @@ module RNDK
82
105
 
83
106
  # Create the scrollbar window.
84
107
  if splace == RNDK::RIGHT
85
- @scrollbar_win = Ncurses.subwin(@win, self.maxViewSize, 1,
108
+ @scrollbar_win = Ncurses.subwin(@win, self.max_view_size, 1,
86
109
  self.Screen_YPOS(ypos), xpos + @box_width - @border_size - 1)
87
110
  elsif splace == RNDK::LEFT
88
- @scrollbar_win = Ncurses.subwin(@win, self.maxViewSize, 1,
111
+ @scrollbar_win = Ncurses.subwin(@win, self.max_view_size, 1,
89
112
  self.Screen_YPOS(ypos), self.Screen_XPOS(xpos))
90
113
  else
91
114
  @scrollbar_win = nil
92
115
  end
93
116
 
94
117
  # Set the rest of the variables
95
- @screen = rndkscreen
96
- @parent = rndkscreen.window
118
+ @screen = screen
119
+ @parent = screen.window
97
120
  @scrollbar_placement = splace
98
121
  @widest_item = widest_item
99
122
  @left_char = 0
@@ -102,12 +125,12 @@ module RNDK
102
125
  @choice_char = choice_char.ord
103
126
  @left_box_char = '['.ord
104
127
  @right_box_char = ']'.ord
105
- @def_item = def_item
128
+ @default = default
106
129
  @input_window = @win
107
130
  @accepts_focus = true
108
131
  @shadow = shadow
109
132
 
110
- self.setCurrentItem(0)
133
+ self.set_current_item(0)
111
134
 
112
135
  # Do we need to create the shadow?
113
136
  if shadow
@@ -116,11 +139,13 @@ module RNDK
116
139
  end
117
140
 
118
141
  # Setup the key bindings
119
- bindings.each do |from, to|
120
- self.bind(:RADIO, from, :getc, to)
121
- end
142
+ self.bind_key('g') { self.scroll_begin }
143
+ self.bind_key('1') { self.scroll_begin }
144
+ self.bind_key('G') { self.scroll_end }
145
+ self.bind_key('<') { self.scroll_begin }
146
+ self.bind_key('>') { self.scroll_end }
122
147
 
123
- rndkscreen.register(:RADIO, self)
148
+ screen.register(@widget_type, self)
124
149
  end
125
150
 
126
151
  # Put the cursor on the currently-selected item.
@@ -134,14 +159,14 @@ module RNDK
134
159
  end
135
160
 
136
161
  # This actually manages the radio widget.
137
- def activate(actions)
138
- # Draw the radio list.
139
- self.draw(@box)
162
+ def activate(actions=[])
163
+ # Draw the radio items.
164
+ self.draw
140
165
 
141
166
  if actions.nil? || actions.size == 0
142
167
  while true
143
168
  self.fixCursorPosition
144
- input = self.getch([])
169
+ input = self.getch
145
170
 
146
171
  # Inject the character into the widget.
147
172
  ret = self.inject(input)
@@ -164,47 +189,38 @@ module RNDK
164
189
  end
165
190
 
166
191
  # This injects a single character into the widget.
167
- def inject(input)
168
- pp_return = 1
169
- ret = -1
192
+ def inject input
193
+ pp_return = true
194
+ ret = false
170
195
  complete = false
171
196
 
172
197
  # Set the exit type
173
198
  self.set_exit_type(0)
174
199
 
175
- # Draw the widget list
176
- self.drawList(@box)
200
+ # Draw the widget items
201
+ self.draw_items(@box)
177
202
 
178
- # Check if there is a pre-process function to be called
179
- unless @pre_process_func.nil?
180
- # Call the pre-process function.
181
- pp_return = @pre_process_func.call(:RADIO, self,
182
- @pre_process_data, input)
183
- end
203
+ # Check if there is a pre-process function to be called.
204
+ keep_going = self.run_signal_binding(:before_input, input)
205
+
206
+ if keep_going
184
207
 
185
- # Should we continue?
186
- if pp_return != 0
187
208
  # Check for a predefined key binding.
188
- if self.checkBind(:RADIO, input)
189
- complete = true
209
+ if self.is_bound? input
210
+ self.run_key_binding input
211
+ #complete = true
190
212
  else
191
213
  case input
192
- when Ncurses::KEY_UP
193
- self.KEY_UP
194
- when Ncurses::KEY_DOWN
195
- self.KEY_DOWN
196
- when Ncurses::KEY_RIGHT
197
- self.KEY_RIGHT
198
- when Ncurses::KEY_LEFT
199
- self.KEY_LEFT
200
- when Ncurses::KEY_PPAGE
201
- self.KEY_PPAGE
202
- when Ncurses::KEY_NPAGE
203
- self.KEY_NPAGE
204
- when Ncurses::KEY_HOME
205
- self.KEY_HOME
206
- when Ncurses::KEY_END
207
- self.KEY_END
214
+ when Ncurses::KEY_UP then self.scroll_up
215
+ when Ncurses::KEY_DOWN then self.scroll_down
216
+ when Ncurses::KEY_RIGHT then self.scroll_right
217
+ when Ncurses::KEY_LEFT then self.scroll_left
218
+ when Ncurses::KEY_HOME then self.scroll_begin
219
+ when Ncurses::KEY_END then self.scroll_end
220
+ when Ncurses::KEY_PPAGE, RNDK::BACKCHAR
221
+ self.scroll_page_up
222
+ when Ncurses::KEY_NPAGE, RNDK::FORCHAR
223
+ self.scroll_page_down
208
224
  when '$'.ord
209
225
  @left_char = @max_left_char
210
226
  when '|'.ord
@@ -213,7 +229,7 @@ module RNDK
213
229
  @selected_item = @current_item
214
230
  when RNDK::KEY_ESC
215
231
  self.set_exit_type(input)
216
- ret = -1
232
+ ret = false
217
233
  complete = true
218
234
  when Ncurses::ERR
219
235
  self.set_exit_type(input)
@@ -229,13 +245,11 @@ module RNDK
229
245
  end
230
246
 
231
247
  # Should we call a post-process?
232
- if !complete && !(@post_process_func.nil?)
233
- @post_process_func.call(:RADIO, self, @post_process_data, input)
234
- end
248
+ self.run_signal_binding(:after_input) if not complete
235
249
  end
236
250
 
237
- if !complete
238
- self.drawList(@box)
251
+ if not complete
252
+ self.draw_items(@box)
239
253
  self.set_exit_type(0)
240
254
  end
241
255
 
@@ -245,34 +259,32 @@ module RNDK
245
259
  end
246
260
 
247
261
  # This moves the radio field to the given location.
248
- def move(xplace, yplace, relative, refresh_flag)
262
+ def move(x, y, relative, refresh_flag)
249
263
  windows = [@win, @scrollbar_win, @shadow_win]
250
- self.move_specific(xplace, yplace, relative, refresh_flag,
264
+ self.move_specific(x, y, relative, refresh_flag,
251
265
  windows, subwidgets)
252
266
  end
253
267
 
254
268
  # This function draws the radio widget.
255
- def draw(box)
269
+ def draw
256
270
  # Do we need to draw in the shadow?
257
- if !(@shadow_win.nil?)
258
- Draw.drawShadow(@shadow_win)
259
- end
271
+ Draw.drawShadow(@shadow_win) unless @shadow_win.nil?
260
272
 
261
- self.drawTitle(@win)
273
+ self.draw_title @win
262
274
 
263
- # Draw in the radio list.
264
- self.drawList(@box)
275
+ # Draw in the radio items.
276
+ self.draw_items @box
265
277
  end
266
278
 
267
- # This redraws the radio list.
268
- def drawList(box)
279
+ # This redraws the radio items.
280
+ def draw_items(box)
269
281
  scrollbar_adj = if @scrollbar_placement == RNDK::LEFT then 1 else 0 end
270
282
  screen_pos = 0
271
283
 
272
- # Draw the list
284
+ # Draw the items
273
285
  (0...@view_size).each do |j|
274
286
  k = j + @current_top
275
- if k < @list_size
287
+ if k < @items_size
276
288
  xpos = self.Screen_XPOS(0)
277
289
  ypos = self.Screen_YPOS(j)
278
290
 
@@ -301,7 +313,7 @@ module RNDK
301
313
  # Highlight the current item
302
314
  if @has_focus
303
315
  k = @current_item
304
- if k < @list_size
316
+ if k < @items_size
305
317
  screen_pos = self.ScreenPOS(k, scrollbar_adj)
306
318
  ypos = self.Screen_YPOS(@current_high)
307
319
 
@@ -326,7 +338,7 @@ module RNDK
326
338
  Ncurses.mvwvline(@scrollbar_win,
327
339
  @toggle_pos,
328
340
  0,
329
- ' '.ord | Ncurses::A_REVERSE,
341
+ ' '.ord | RNDK::Color[:reverse],
330
342
  @toggle_size)
331
343
  end
332
344
 
@@ -339,7 +351,7 @@ module RNDK
339
351
  end
340
352
 
341
353
  # This sets the background attribute of the widget.
342
- def set_bg_attrib(attrib)
354
+ def set_bg_color(attrib)
343
355
  Ncurses.wbkgd(@win, attrib)
344
356
  Ncurses.wbkgd(@scrollbar_win, attrib) unless @scrollbar_win.nil?
345
357
  end
@@ -350,7 +362,7 @@ module RNDK
350
362
 
351
363
  # This function destroys the radio widget.
352
364
  def destroy
353
- self.cleanTitle
365
+ self.clean_title
354
366
  self.destroyInfo
355
367
 
356
368
  # Clean up the windows.
@@ -359,33 +371,31 @@ module RNDK
359
371
  RNDK.window_delete(@win)
360
372
 
361
373
  # Clean up the key bindings.
362
- self.clean_bindings(:RADIO)
374
+ self.clean_bindings
363
375
 
364
- # Unregister this object.
365
- RNDK::Screen.unregister(:RADIO, self)
376
+ # Unregister this widget.
377
+ @screen.unregister self
366
378
  end
367
379
 
368
380
  # This function erases the radio widget
369
381
  def erase
370
- if self.valid_widget?
382
+ if self.valid?
371
383
  RNDK.window_erase(@win)
372
384
  RNDK.window_erase(@shadow_win)
373
385
  end
374
386
  end
375
387
 
376
- # This sets various attributes of the radio list.
388
+ # This sets various attributes of the radio items.
377
389
  def set(highlight, choice_char, box)
378
390
  self.set_highlight(highlight)
379
391
  self.setChoiceCHaracter(choice_char)
380
392
  self.set_box(box)
381
393
  end
382
394
 
383
- # This sets the radio list items.
384
- def setItems(list, list_size)
385
- widest_item = self.createList(list, list_size, @box_width)
386
- if widest_item <= 0
387
- return
388
- end
395
+ # This sets the radio items items.
396
+ def set_items(items)
397
+ widest_item = self.create_items(items, @box_width)
398
+ return if widest_item <= 0
389
399
 
390
400
  # Clean up the display.
391
401
  (0...@view_size).each do |j|
@@ -393,23 +403,23 @@ module RNDK
393
403
  RNDK::HORIZONTAL, 0, @box_width - @border_size)
394
404
  end
395
405
 
396
- self.setViewSize(list_size)
406
+ self.set_view_size(items_size)
397
407
 
398
- self.setCurrentItem(0)
408
+ self.set_current_item(0)
399
409
  @left_char = 0
400
410
  @selected_item = 0
401
411
 
402
412
  self.updateViewWidth(widest_item)
403
413
  end
404
414
 
405
- def getItems(list)
406
- (0...@list_size).each do |j|
407
- list << RNDK.chtype2Char(@item[j])
415
+ def getItems(items)
416
+ (0...@items_size).each do |j|
417
+ items << RNDK.chtype2Char(@item[j])
408
418
  end
409
- return @list_size
419
+ return @items_size
410
420
  end
411
421
 
412
- # This sets the highlight bar of the radio list.
422
+ # This sets the highlight bar of the radio items.
413
423
  def set_highlight(highlight)
414
424
  @highlight = highlight
415
425
  end
@@ -418,7 +428,7 @@ module RNDK
418
428
  return @highlight
419
429
  end
420
430
 
421
- # This sets the character to use when selecting na item in the list.
431
+ # This sets the character to use when selecting na item in the items.
422
432
  def setChoiceCharacter(character)
423
433
  @choice_char = character
424
434
  end
@@ -428,7 +438,7 @@ module RNDK
428
438
  end
429
439
 
430
440
  # This sets the character to use to drw the left side of the choice box
431
- # on the list
441
+ # on the items
432
442
  def setLeftBrace(character)
433
443
  @left_box_char = character
434
444
  end
@@ -438,7 +448,7 @@ module RNDK
438
448
  end
439
449
 
440
450
  # This sets the character to use to draw the right side of the choice box
441
- # on the list
451
+ # on the items
442
452
  def setRightBrace(character)
443
453
  @right_box_char = character
444
454
  end
@@ -448,8 +458,8 @@ module RNDK
448
458
  end
449
459
 
450
460
  # This sets the current highlighted item of the widget
451
- def setCurrentItem(item)
452
- self.setPosition(item)
461
+ def set_current_item(item)
462
+ self.set_position(item)
453
463
  @selected_item = item
454
464
  end
455
465
 
@@ -467,32 +477,32 @@ module RNDK
467
477
  end
468
478
 
469
479
  def focus
470
- self.drawList(@box)
480
+ self.draw_items(@box)
471
481
  end
472
482
 
473
483
  def unfocus
474
- self.drawList(@box)
484
+ self.draw_items(@box)
475
485
  end
476
486
 
477
- def createList(list, list_size, box_width)
487
+ def create_items(items, box_width)
478
488
  status = false
479
489
  widest_item = 0
480
490
 
481
- if list_size >= 0
482
- new_list = []
491
+ if items.size >= 0
492
+ new_items = []
483
493
  new_len = []
484
494
  new_pos = []
485
495
 
486
496
  # Each item in the needs to be converted to chtype array
487
497
  status = true
488
498
  box_width -= 2 + @border_size
489
- (0...list_size).each do |j|
499
+ (0...items.size).each do |j|
490
500
  lentmp = []
491
501
  postmp = []
492
- new_list << RNDK.char2Chtype(list[j], lentmp, postmp)
502
+ new_items << RNDK.char2Chtype(items[j], lentmp, postmp)
493
503
  new_len << lentmp[0]
494
504
  new_pos << postmp[0]
495
- if new_list[j].nil? || new_list[j].size == 0
505
+ if new_items[j].nil? || new_items[j].size == 0
496
506
  status = false
497
507
  break
498
508
  end
@@ -501,11 +511,12 @@ module RNDK
501
511
  end
502
512
  if status
503
513
  self.destroyInfo
504
- @item = new_list
514
+ @item = new_items
505
515
  @item_len = new_len
506
516
  @item_pos = new_pos
507
517
  end
508
518
  end
519
+ @items_size = items.size
509
520
 
510
521
  return (if status then widest_item else 0 end)
511
522
  end
@@ -531,8 +542,7 @@ module RNDK
531
542
  @item_pos[n] - @left_char + scrollbar_adj + @border_size
532
543
  end
533
544
 
534
- def object_type
535
- :RADIO
536
- end
545
+
546
+
537
547
  end
538
548
  end