Class: PPCurses::InputElement
- Inherits:
-
View
- Object
- Responder
- ResponderManager
- View
- PPCurses::InputElement
- Defined in:
- lib/ppcurses/form/input_element.rb
Instance Attribute Summary collapse
-
#cursor_location ⇒ Object
Stores the X location of the cursor relative to the value being displayed.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#label ⇒ Object
Returns the value of attribute label.
-
#selected ⇒ Object
Returns the value of attribute selected.
-
#size ⇒ Object
Returns the value of attribute size.
-
#value ⇒ Object
Returns the value of attribute value.
-
#value_start_point ⇒ Object
Returns the value of attribute value_start_point.
Attributes inherited from View
Attributes inherited from ResponderManager
Attributes inherited from Responder
Class Method Summary collapse
-
.new_decimal_only(label, size) ⇒ Object
Creates an InputElement that only allows a number but allows a decimal point.
-
.new_integer_only(label, size) ⇒ Object
Creates an InputElement that only allows integer input.
-
.new_time_only(label, size) ⇒ Object
Creates an InputElement that only allows time data E.G.
Instance Method Summary collapse
- #clear ⇒ Object
- #height ⇒ Object
-
#initialize(label, size) ⇒ InputElement
constructor
A new instance of InputElement.
- #key_down(key) ⇒ Object
- #passes_filter(key) ⇒ Object
- #set_curs_pos(screen) ⇒ Object
- #show(screen) ⇒ Object
Methods inherited from View
#display, #setFrameOrigin, #setFrameSize
Methods inherited from ResponderManager
#accepts_first_responder, #make_first_responder
Methods inherited from Responder
#accepts_first_responder, #become_first_responder, isa, #resign_first_responder
Constructor Details
#initialize(label, size) ⇒ InputElement
Returns a new instance of InputElement.
22 23 24 25 26 27 28 |
# File 'lib/ppcurses/form/input_element.rb', line 22 def initialize(label, size ) @label = label @size = size @selected = false @filter = nil self.clear end |
Instance Attribute Details
#cursor_location ⇒ Object
Stores the X location of the cursor relative to the value being displayed. If the cursor is in the middle of the string then subsequent keys will be added from this location, etc.
19 20 21 |
# File 'lib/ppcurses/form/input_element.rb', line 19 def cursor_location @cursor_location end |
#filter ⇒ Object
Returns the value of attribute filter.
10 11 12 |
# File 'lib/ppcurses/form/input_element.rb', line 10 def filter @filter end |
#label ⇒ Object
Returns the value of attribute label.
5 6 7 |
# File 'lib/ppcurses/form/input_element.rb', line 5 def label @label end |
#selected ⇒ Object
Returns the value of attribute selected.
8 9 10 |
# File 'lib/ppcurses/form/input_element.rb', line 8 def selected @selected end |
#size ⇒ Object
Returns the value of attribute size.
7 8 9 |
# File 'lib/ppcurses/form/input_element.rb', line 7 def size @size end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/ppcurses/form/input_element.rb', line 6 def value @value end |
#value_start_point ⇒ Object
Returns the value of attribute value_start_point.
12 13 14 |
# File 'lib/ppcurses/form/input_element.rb', line 12 def value_start_point @value_start_point end |
Class Method Details
.new_decimal_only(label, size) ⇒ Object
Creates an InputElement that only allows a number but allows a decimal point. I.E. 10.2
41 42 43 44 45 |
# File 'lib/ppcurses/form/input_element.rb', line 41 def InputElement.new_decimal_only( label, size) i_only = PPCurses::InputElement.new(label, size) i_only.filter = PPCurses::DecimalFilter.new i_only end |
.new_integer_only(label, size) ⇒ Object
Creates an InputElement that only allows integer input
32 33 34 35 36 |
# File 'lib/ppcurses/form/input_element.rb', line 32 def InputElement.new_integer_only( label, size) i_only = PPCurses::InputElement.new(label, size) i_only.filter = PPCurses::IntegerFilter.new i_only end |
.new_time_only(label, size) ⇒ Object
Creates an InputElement that only allows time data E.G. 20:10.20 == 20 hours, 10 minutes and 20 seconds
50 51 52 53 54 |
# File 'lib/ppcurses/form/input_element.rb', line 50 def InputElement.new_time_only( label, size) i_only = PPCurses::InputElement.new(label, size) i_only.filter = PPCurses::TimeFilter.new i_only end |
Instance Method Details
#clear ⇒ Object
135 136 137 138 |
# File 'lib/ppcurses/form/input_element.rb', line 135 def clear @value = '' @cursor_location = 0 end |
#height ⇒ Object
131 132 133 |
# File 'lib/ppcurses/form/input_element.rb', line 131 def height 1 end |
#key_down(key) ⇒ Object
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 |
# File 'lib/ppcurses/form/input_element.rb', line 66 def key_down( key ) if key == DELETE handle_delete return end if key == KEY_LEFT @cursor_location -= 1 unless @cursor_location == 0 return end if key == KEY_RIGHT @cursor_location += 1 unless @cursor_location == @value.length return end # Ignore control characters if key.is_a?(Fixnum) return end # Adding new characters to the string # Check size of string before adding another character if @value.length >= @size # Ignore input return end # # Get a temporary version of the current value # with the new character added so that we can # test it against the filter. temp_val = value_with(key) unless passes_filter(temp_val) return end # # Actually add the new character if the filter passes # add_character(key) end |
#passes_filter(key) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/ppcurses/form/input_element.rb', line 114 def passes_filter( key ) if @filter.nil? return true end @filter.passes_filter( key ) end |
#set_curs_pos(screen) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/ppcurses/form/input_element.rb', line 123 def set_curs_pos(screen) Curses.curs_set(VISIBLE) x = @value_start_point.x + @cursor_location screen.setpos( @value_start_point.y, x ) end |
#show(screen) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ppcurses/form/input_element.rb', line 56 def show(screen) print_label( screen ) @value_start_point = screen.cur_point print_value( screen ) end |