Class: WindowBlessing::Widgets::Slider
- Inherits:
-
WindowBlessing::Window
- Object
- WindowBlessing::Window
- WindowBlessing::Widgets::Slider
- Includes:
- Evented
- Defined in:
- lib/window_blessing/widgets/slider.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#evented_value ⇒ Object
readonly
Returns the value of attribute evented_value.
-
#key_press_step ⇒ Object
Returns the value of attribute key_press_step.
Attributes inherited from WindowBlessing::Window
Attributes included from WindowBlessing::Window::Drawing
Attributes included from WindowBlessing::Window::ParentsAndChildren
Attributes included from WindowBlessing::Window::Geometry
Attributes included from WindowBlessing::Window::KeyboardFocus
Instance Method Summary collapse
- #draw_background ⇒ Object
- #draw_handle ⇒ Object
- #handle_area ⇒ Object
- #handle_x ⇒ Object
-
#initialize(rect, evented_value, options = {}) ⇒ Slider
constructor
options :key_press_step => 0.1.
- #screen_value_range ⇒ Object
- #value ⇒ Object
- #value=(v) ⇒ Object
Methods included from Evented
#event_manager, #handle_event, #on
Methods inherited from WindowBlessing::Window
attr_accessor_with_redraw, #inspect, #route_pointer_event
Methods included from WindowBlessing::Window::Drawing
#add_redraw_area, #clear_redraw_areas, #draw, #draw_internal, #redraw, #redraw_requested?, #request_redraw, #request_redraw_internal
Methods included from WindowBlessing::Window::ParentsAndChildren
#add_child, #each_child, #each_child_with_index, #parent_path, #path, #remove_child
Methods included from WindowBlessing::Window::Geometry
#internal_area, #loc, #loc=, #move_onscreen, #pointer_inside?, #size, #size=
Methods included from WindowBlessing::Window::KeyboardFocus
#blur, #blurred?, #focus, #focused?, #route_keyboard_event
Methods included from Tools
#buffer, #clone_value, #color, #fill_line, #gen_array2d, #gray_screen_color, #log, #overlapping_span, #overlay2d, #overlay_span, #range_length, #resize2d, #rgb_screen_color, #subarray2d, #window
Constructor Details
#initialize(rect, evented_value, options = {}) ⇒ Slider
options
:key_press_step => 0.1
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 |
# File 'lib/window_blessing/widgets/slider.rb', line 10 def initialize(rect, evented_value, ={}) rect.size.y = 1 super rect @evented_value = evented_value = case evented_value when EventedVariable then evented_value when Float then EventedVariable.new(evented_value) else raise ArgumentError.new "invalid text type #{evented_value.inspect}(#{evented_value.class})" end self.bg = gray_screen_color(0.25) @key_press_step = [:key_press_step] || 0.1 on :pointer do |event| x = event[:loc].x evented_value.set bound(0.0, x / screen_value_range, 1.0) end evented_value.on :refresh do |event| request_redraw_internal end on :key_press do |event| case event[:key] when :home then self.value = 0 when :end then self.value = 1 when :left then self.value = max(0.0, self.value - @key_press_step) if @key_press_step when :right then self.value = min(1.0, self.value + @key_press_step) if @key_press_step end end end |
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute background.
5 6 7 |
# File 'lib/window_blessing/widgets/slider.rb', line 5 def background @background end |
#evented_value ⇒ Object (readonly)
Returns the value of attribute evented_value.
5 6 7 |
# File 'lib/window_blessing/widgets/slider.rb', line 5 def evented_value @evented_value end |
#key_press_step ⇒ Object
Returns the value of attribute key_press_step.
6 7 8 |
# File 'lib/window_blessing/widgets/slider.rb', line 6 def key_press_step @key_press_step end |
Instance Method Details
#draw_background ⇒ Object
50 51 52 53 |
# File 'lib/window_blessing/widgets/slider.rb', line 50 def draw_background super draw_handle end |
#draw_handle ⇒ Object
46 47 48 |
# File 'lib/window_blessing/widgets/slider.rb', line 46 def draw_handle buffer.fill :area => handle_area, :string => "+" end |
#handle_area ⇒ Object
42 43 44 |
# File 'lib/window_blessing/widgets/slider.rb', line 42 def handle_area rect(point(handle_x,0),point(1,1)) end |
#handle_x ⇒ Object
55 |
# File 'lib/window_blessing/widgets/slider.rb', line 55 def handle_x; (value * screen_value_range).to_i end |
#screen_value_range ⇒ Object
56 |
# File 'lib/window_blessing/widgets/slider.rb', line 56 def screen_value_range; size.x - 1.0 end |
#value ⇒ Object
57 |
# File 'lib/window_blessing/widgets/slider.rb', line 57 def value; evented_value.get end |
#value=(v) ⇒ Object
58 |
# File 'lib/window_blessing/widgets/slider.rb', line 58 def value=(v) evented_value.set(v) end |