Skip to content

Commit

Permalink
resolve #348
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 18, 2019
1 parent 2637b75 commit e93afa2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions uiautomator2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,19 +752,27 @@ def click(self, timeout=None, offset=None):
if delay:
time.sleep(delay)

def center(self, offset=None):
def bounds(self):
"""
Returns:
left_top_x, left_top_y, right_bottom_x, right_bottom_y
"""
info = self.info
bounds = info.get('visibleBounds') or info.get("bounds")
lx, ly, rx, ry = bounds['left'], bounds['top'], bounds['right'], bounds['bottom']
return (lx, ly, rx, ry)

def center(self, offset=(0.5, 0.5)):
"""
Args:
offset: optional, (x_off, y_off)
(0, 0) means center, (0.5, 0.5) means right-bottom
(0, 0) means left-top, (0.5, 0.5) means middle(Default)
Return:
center point (x, y)
"""
info = self.info
bounds = info.get('visibleBounds') or info.get("bounds")
lx, ly, rx, ry = bounds['left'], bounds['top'], bounds['right'], bounds['bottom']
if not offset:
offset = (0.5, 0.5)
lx, ly, rx, ry = self.bounds()
if offset is None:
offset = (0.5, 0.5) # default center
xoff, yoff = offset
width, height = rx - lx, ry - ly
x = lx + width * xoff
Expand Down

0 comments on commit e93afa2

Please sign in to comment.