Module: Briar::Control::Slider
- Defined in:
- lib/briar/control/slider.rb
Instance Method Summary collapse
- #briar_args_for_slider_set_value(options) ⇒ Object
- #briar_slider_set_value(slider_id, value, options = {:animate => true, :notify_targets => true}) ⇒ Object
-
#change_slider_value_to(slider_id, value) ⇒ Object
WARNING: requires a tap gesture recognizer on the slider you have been warned.
Instance Method Details
#briar_args_for_slider_set_value(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/briar/control/slider.rb', line 7 def () args = [] if .has_key?(:notify_targets) args << [:notify_targets] ? 1 : 0 else args << 1 end if .has_key?(:animate) args << [:animate] ? 1 : 0 else args << 1 end args end |
#briar_slider_set_value(slider_id, value, options = {:animate => true, :notify_targets => true}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/briar/control/slider.rb', line 23 def (, value, = {:animate => true, :notify_targets => true}) value_str = value.to_f.to_s args = () query_str = "slider marked:'#{}'" views_touched = map(query_str, :changeSlider, value_str, *args) msg = "could not slider marked '#{}' to '#{value}' using query '#{query_str}' with options '#{}'" assert_map_results(views_touched, msg) end |
#change_slider_value_to(slider_id, value) ⇒ Object
WARNING: requires a tap gesture recognizer on the slider you have been warned
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 |
# File 'lib/briar/control/slider.rb', line 36 def (, value) target = value.to_f if target < 0 pending "value '#{value}' must be >= 0" end min_val = query("slider marked:'#{}'", :minimumValue).first # will not work for min_val != 0 if min_val != 0 pending "sliders with non-zero minimum values are not supported - slider '#{}' has minimum value of '#{min_val}'" end max_val = query("slider marked:'#{}'", :maximumValue).first if target > max_val screenshot_and_raise "cannot change slider '#{}' to '#{value}' because the maximum allowed value is '#{max_val}'" end # the x offset is from the middle of the slider. # ex. slider from 0 to 5 # to touch 3, x must be 0 # to touch 0, x must be -2.5 # to touch 5, x must be 2.5 half_val = (max_val/2) width = query("slider marked:'#{}'", :frame).first["Width"] x = ((width/2) * ((target - half_val)/half_val)).ceil touch("slider marked:'#{}'", {:offset => {:x => x, :y => 0}}) #current = query("slider marked:'#{slider_id}'", :value).first #puts "current => at '#{current}' with x => '#{x}'" end |