More cleanups

This commit is contained in:
Kovid Goyal 2020-08-31 17:22:01 +05:30
parent 8c00352dce
commit 24e1fa90d1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -32,9 +32,11 @@ def map_boundaries(cs, vertical, rtl):
margins = get_margins() margins = get_margins()
def map_boundary(b): def map_boundary(b):
x_offset = 0 x_offset = y_offset = 0
y_offset = 0 if vertical:
if not vertical: if b.selected_prev:
y_offset = b.height
else:
if rtl: if rtl:
# Horizontal RTL # Horizontal RTL
if not b.selected_prev: if not b.selected_prev:
@ -43,10 +45,6 @@ def map_boundaries(cs, vertical, rtl):
# Horizontal LTR # Horizontal LTR
if b.selected_prev: if b.selected_prev:
x_offset = b.width x_offset = b.width
else:
# Vertical:
if b.selected_prev:
y_offset = b.height
return {'x': (b.x or 0) + x_offset + margins.left, 'y': (b.y or 0) + y_offset + margins.top, 'height': b.height or 0, 'width': b.width or 0, 'onscreen': b.onscreen} return {'x': (b.x or 0) + x_offset + margins.left, 'y': (b.y or 0) + y_offset + margins.top, 'height': b.height or 0, 'width': b.width or 0, 'onscreen': b.onscreen}
@ -718,7 +716,7 @@ class SelectionBar:
s.display = 'block' if boundary.onscreen else 'none' s.display = 'block' if boundary.onscreen else 'none'
# Cap this to prevent very large handles when selecting images. # Cap this to prevent very large handles when selecting images.
selection_size = min(60, selection_size) selection_size = max(10, min(selection_size, 60))
if self.vertical: if self.vertical:
width = selection_size * 2 width = selection_size * 2
@ -734,17 +732,19 @@ class SelectionBar:
bottom = boundary.y + boundary.height bottom = boundary.y + boundary.height
top = bottom - height top = bottom - height
s.top = f'{top}px' s.top = f'{top}px'
if is_start:
# Horizontal, start, LTR # Horizontal, start, LTR
if is_start and self.ltr: if self.ltr:
s.left = (boundary.x - width) + 'px' s.left = (boundary.x - width) + 'px'
self.start_line_length = selection_size self.start_line_length = selection_size
# Horizontal, start, RTL # Horizontal, start, RTL
else if is_start: else:
s.left = (boundary.x) + 'px' s.left = (boundary.x) + 'px'
self.start_line_length = selection_size self.start_line_length = selection_size
s.transform = 'scaleX(-1)' s.transform = 'scaleX(-1)'
else:
# Horizontal, end, LTR # Horizontal, end, LTR
else if self.ltr: if self.ltr:
s.left = boundary.x + 'px' s.left = boundary.x + 'px'
self.end_line_length = selection_size self.end_line_length = selection_size
s.transform = 'scaleX(-1)' s.transform = 'scaleX(-1)'
@ -753,20 +753,22 @@ class SelectionBar:
s.left = (boundary.x - width) + 'px' s.left = (boundary.x - width) + 'px'
self.end_line_length = selection_size self.end_line_length = selection_size
else: else:
if is_start:
# Vertical, start, RTL # Vertical, start, RTL
if is_start and self.rtl: if self.rtl:
s.top = boundary.y - height + 'px' s.top = boundary.y - height + 'px'
s.left = boundary.x + 'px' s.left = boundary.x + 'px'
self.start_line_length = selection_size self.start_line_length = selection_size
s.transform = f'scaleX(-1) scaleY(-1)' s.transform = 'scaleX(-1) scaleY(-1)'
# Vertical, start, LTR # Vertical, start, LTR
else if is_start: else:
s.top = boundary.y - height + 'px' s.top = boundary.y - height + 'px'
s.left = boundary.x - width + boundary.width + 'px' s.left = boundary.x - width + boundary.width + 'px'
self.start_line_length = selection_size self.start_line_length = selection_size
s.transform = f'scaleY(-1)' s.transform = 'scaleY(-1)'
else:
# Vertical, end, RTL # Vertical, end, RTL
else if self.rtl: if self.rtl:
s.top = boundary.y + 'px' s.top = boundary.y + 'px'
s.left = boundary.x - width + boundary.width + 'px' s.left = boundary.x - width + boundary.width + 'px'
self.end_line_length = selection_size self.end_line_length = selection_size
@ -775,7 +777,7 @@ class SelectionBar:
s.top = boundary.y + 'px' s.top = boundary.y + 'px'
s.left = boundary.x + 'px' s.left = boundary.x + 'px'
self.end_line_length = selection_size self.end_line_length = selection_size
s.transform = f'scaleX(-1)' s.transform = 'scaleX(-1)'
def position_handles(self, start_handle, end_handle, start, end): def position_handles(self, start_handle, end_handle, start, end):
if self.vertical: if self.vertical: