Method: CDK::SLIDER#initialize
- Defined in:
- lib/cdk/slider.rb
#initialize(cdkscreen, xplace, yplace, title, label, filler, field_width, start, low, high, inc, fast_inc, box, shadow) ⇒ SLIDER
Returns a new instance of SLIDER.
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 42 43 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cdk/slider.rb', line 5 def initialize(cdkscreen, xplace, yplace, title, label, filler, field_width, start, low, high, inc, fast_inc, box, shadow) super() parent_width = cdkscreen.window.getmaxx parent_height = cdkscreen.window.getmaxy bindings = { 'u' => Ncurses::KEY_UP, 'U' => Ncurses::KEY_PPAGE, CDK::BACKCHAR => Ncurses::KEY_PPAGE, CDK::FORCHAR => Ncurses::KEY_NPAGE, 'g' => Ncurses::KEY_HOME, '^' => Ncurses::KEY_HOME, 'G' => Ncurses::KEY_END, '$' => Ncurses::KEY_END, } self.setBox(box) box_height = @border_size * 2 + 1 # Set some basic values of the widget's data field. @label = [] @label_len = 0 @label_win = nil high_value_len = self.formattedSize(high) # If the field_width is a negative will be COLS-field_width, # otherwise field_width will be the given width. field_width = CDK.setWidgetDimension(parent_width, field_width, 0) # Translate the label string to a chtype array. if !(label.nil?) && label.size > 0 label_len = [] @label = CDK.char2Chtype(label, label_len, []) @label_len = label_len[0] box_width = @label_len + field_width + high_value_len + 2 * @border_size else box_width = field_width + high_value_len + 2 * @border_size end old_width = box_width box_width = self.setTitle(title, box_width) horizontal_adjust = (box_width - old_width) / 2 box_height += @title_lines # Make sure we didn't extend beyond the dimensions of the window. box_width = [box_width, parent_width].min box_height = [box_height, parent_height].min field_width = [field_width, box_width - @label_len - high_value_len - 1].min # Rejustify the x and y positions if we need to. xtmp = [xplace] ytmp = [yplace] CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height) xpos = xtmp[0] ypos = ytmp[0] # Make the widget's window. @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos) # Is the main window nil? if @win.nil? self.destroy return nil end # Create the widget's label window. if @label.size > 0 @label_win = @win.subwin(1, @label_len, ypos + @title_lines + @border_size, xpos + horizontal_adjust + @border_size) if @label_win.nil? self.destroy return nil end end # Create the widget's data field window. @field_win = @win.subwin(1, field_width + high_value_len - 1, ypos + @title_lines + @border_size, xpos + @label_len + horizontal_adjust + @border_size) if @field_win.nil? self.destroy return nil end @field_win.keypad(true) @win.keypad(true) # Create the widget's data field. @screen = cdkscreen @window = cdkscreen.window @shadow_win = nil @box_width = box_width @box_height = box_height @field_width = field_width - 1 @filler = filler @low = low @high = high @current = start @inc = inc @fastinc = fast_inc @accepts_focus = true @input_window = @win @shadow = shadow @field_edit = 0 # Set the start value. if start < low @current = low end # Do we want a shadow? if shadow @shadow_win = Ncurses::WINDOW.new(box_height, box_width, ypos + 1, xpos + 1) if @shadow_win.nil? self.destroy return nil end end # Setup the key bindings. bindings.each do |from, to| self.bind(:SLIDER, from, :getc, to) end cdkscreen.register(:SLIDER, self) end |