Class: RNDK::Fslider

Inherits:
Slider show all
Defined in:
lib/rndk/fslider.rb

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 Slider

Decrement, Increment, #activate, #decrement, #destroy, #draw, #erase, #focus, #formattedSize, #getMaximumValue, #getMinimumValue, #get_value, #increment, #inject, #limitCurrentValue, #move, #moveToEditPosition, #performEdit, #position, removeChar, #set, #setEditPosition, #setMinimumMaximum, #set_bg_color, #set_value, #unfocus, #validEditPosition

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

#initialize(screen, config = {}) ⇒ Fslider

Returns a new instance of Fslider.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rndk/fslider.rb', line 5

def initialize(screen, config={})
  x           = 0
  y           = 0
  title       = "fslider"
  label       = "label"
  filler      = ' '.ord | RNDK::Color[:reverse]
  field_width = 0
  start       = 0
  low         = 0
  high        = 100
  inc         = 1
  fast_inc    = 5
  digits      = 3
  box         = true
  shadow      = false

  config.each do |key, val|
    x           = val if key == :x
    y           = val if key == :y
    title       = val if key == :title
    label       = val if key == :label
    filler      = val if key == :filler
    field_width = val if key == :field_width
    start       = val if key == :start
    low         = val if key == :low
    high        = val if key == :high
    inc         = val if key == :inc
    fast_inc    = val if key == :fast_inc
    digits      = val if key == :digits
    box         = val if key == :box
    shadow      = val if key == :shadow
  end

  @digits = digits
  super(screen, x, y, title, label, filler, field_width, start, low, high, inc, fast_inc, box, shadow)
  @widget_type = :fslider
end

Instance Method Details

#draw_fieldObject

This draws the widget.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rndk/fslider.rb', line 44

def draw_field
  step = 1.0 * @field_width / (@high - @low)

  # Determine how many filler characters need to be drawn.
  filler_characters = (@current - @low) * step

  Ncurses.werase(@field_win)

  # Add the character to the window.
  (0...filler_characters).each do |x|
    Ncurses.mvwaddch(@field_win, 0, x, @filler)
  end

  # Draw the value in the field.
  digits = [@digits, 30].min
  format = '%%.%if' % [digits]
  temp = format % [@current]

  Draw.writeCharAttrib(@field_win,
                       @field_width,
                       0,
                       temp,
                       RNDK::Color[:normal],
                       RNDK::HORIZONTAL,
                       0,
                       temp.size)

  self.moveToEditPosition(@field_edit)
  Ncurses.wrefresh(@field_win)
end

#formatted_size(value) ⇒ Object



75
76
77
78
79
80
# File 'lib/rndk/fslider.rb', line 75

def formatted_size(value)
  digits = [@digits, 30].min
  format = '%%.%if' % [digits]
  temp = format % [value]
  return temp.size
end

#getDigitsObject



86
87
88
# File 'lib/rndk/fslider.rb', line 86

def getDigits
  return @digits
end

#SCAN_FMTObject



90
91
92
# File 'lib/rndk/fslider.rb', line 90

def SCAN_FMT
  '%g%c'
end

#setDigits(digits) ⇒ Object



82
83
84
# File 'lib/rndk/fslider.rb', line 82

def setDigits(digits)
  @digits = [0, digits].max
end