class RNDK::Fslider

Public Class Methods

new(screen, config={}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

SCAN_FMT() click to toggle source
# File lib/rndk/fslider.rb, line 90
def SCAN_FMT
  '%g%c'
end
draw_field() click to toggle source

This draws the widget.

# 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) click to toggle source
# 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
getDigits() click to toggle source
# File lib/rndk/fslider.rb, line 86
def getDigits
  return @digits
end
setDigits(digits) click to toggle source
# File lib/rndk/fslider.rb, line 82
def setDigits(digits)
  @digits = [0, digits].max
end