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,48 +732,52 @@ 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'
# Horizontal, start, LTR if is_start:
if is_start and self.ltr: # Horizontal, start, LTR
s.left = (boundary.x - width) + 'px' if self.ltr:
self.start_line_length = selection_size s.left = (boundary.x - width) + 'px'
# Horizontal, start, RTL self.start_line_length = selection_size
else if is_start: # Horizontal, start, RTL
s.left = (boundary.x) + 'px' else:
self.start_line_length = selection_size s.left = (boundary.x) + 'px'
s.transform = 'scaleX(-1)' self.start_line_length = selection_size
# Horizontal, end, LTR s.transform = 'scaleX(-1)'
else if self.ltr:
s.left = boundary.x + 'px'
self.end_line_length = selection_size
s.transform = 'scaleX(-1)'
# Horizontal, end, RTL
else: else:
s.left = (boundary.x - width) + 'px' # Horizontal, end, LTR
self.end_line_length = selection_size if self.ltr:
s.left = boundary.x + 'px'
self.end_line_length = selection_size
s.transform = 'scaleX(-1)'
# Horizontal, end, RTL
else:
s.left = (boundary.x - width) + 'px'
self.end_line_length = selection_size
else: else:
# Vertical, start, RTL if is_start:
if is_start and self.rtl: # Vertical, start, RTL
s.top = boundary.y - height + 'px' if self.rtl:
s.left = boundary.x + 'px' s.top = boundary.y - height + 'px'
self.start_line_length = selection_size s.left = boundary.x + 'px'
s.transform = f'scaleX(-1) scaleY(-1)' self.start_line_length = selection_size
# Vertical, start, LTR s.transform = 'scaleX(-1) scaleY(-1)'
else if is_start: # Vertical, start, LTR
s.top = boundary.y - height + 'px' else:
s.left = boundary.x - width + boundary.width + 'px' s.top = boundary.y - height + 'px'
self.start_line_length = selection_size s.left = boundary.x - width + boundary.width + 'px'
s.transform = f'scaleY(-1)' self.start_line_length = selection_size
# Vertical, end, RTL s.transform = 'scaleY(-1)'
else if self.rtl:
s.top = boundary.y + 'px'
s.left = boundary.x - width + boundary.width + 'px'
self.end_line_length = selection_size
# Vertical, end, LTR
else: else:
s.top = boundary.y + 'px' # Vertical, end, RTL
s.left = boundary.x + 'px' if self.rtl:
self.end_line_length = selection_size s.top = boundary.y + 'px'
s.transform = f'scaleX(-1)' s.left = boundary.x - width + boundary.width + 'px'
self.end_line_length = selection_size
# Vertical, end, LTR
else:
s.top = boundary.y + 'px'
s.left = boundary.x + 'px'
self.end_line_length = selection_size
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: