Class: Puppeteer::TouchScreen

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/touch_screen.rb

Overview

rbs_inline: enabled

Instance Method Summary collapse

Constructor Details

#initialize(client, keyboard) ⇒ TouchScreen

Returns a new instance of TouchScreen.



9
10
11
12
13
14
# File 'lib/puppeteer/touch_screen.rb', line 9

def initialize(client, keyboard)
  @client = client
  @keyboard = keyboard
  @touch_id_counter = 0
  @touches = []
end

Instance Method Details

#tap(x, y) ⇒ Object



19
20
21
22
# File 'lib/puppeteer/touch_screen.rb', line 19

def tap(x, y)
  touch = touch_start(x, y)
  touch.end
end

#touch_endObject



60
61
62
63
64
65
# File 'lib/puppeteer/touch_screen.rb', line 60

def touch_end
  touch = @touches.shift
  raise Puppeteer::TouchError.new('Must start a new Touch first') unless touch

  touch.end
end

#touch_move(x, y) ⇒ Object



50
51
52
53
54
55
# File 'lib/puppeteer/touch_screen.rb', line 50

def touch_move(x, y)
  touch = @touches.first
  raise Puppeteer::TouchError.new('Must start a new Touch first') unless touch

  touch.move(x, y)
end

#touch_start(x, y) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppeteer/touch_screen.rb', line 29

def touch_start(x, y)
  @touch_id_counter += 1
  touch_point = {
    x: x.round,
    y: y.round,
    radiusX: 0.5,
    radiusY: 0.5,
    force: 0.5,
    id: @touch_id_counter,
  }
  touch = Puppeteer::TouchHandle.new(self, touch_point)
  touch.start
  @touches << touch
  touch
end