Coding style
- Use match statement where possible.
This commit is contained in:
parent
0ab831e48b
commit
f0159eb6ff
2 changed files with 25 additions and 22 deletions
|
|
@ -616,12 +616,13 @@ class Help:
|
|||
|
||||
def on_mouse_input(self, term_code):
|
||||
event = terminal.decode_mouse_input(term_code)
|
||||
if event[1] == terminal.MOUSE_WHEEL_UP:
|
||||
self.view.portal.scroll_up()
|
||||
fill3.APPEARANCE_CHANGED_EVENT.set()
|
||||
elif event[1] == terminal.MOUSE_WHEEL_DOWN:
|
||||
self.view.portal.scroll_down()
|
||||
fill3.APPEARANCE_CHANGED_EVENT.set()
|
||||
match event[1]:
|
||||
case terminal.MOUSE_WHEEL_UP:
|
||||
self.view.portal.scroll_up()
|
||||
fill3.APPEARANCE_CHANGED_EVENT.set()
|
||||
case terminal.MOUSE_WHEEL_DOWN:
|
||||
self.view.portal.scroll_down()
|
||||
fill3.APPEARANCE_CHANGED_EVENT.set()
|
||||
|
||||
def on_keyboard_input(self, term_code):
|
||||
action = self.key_map.get(term_code) or self.key_map.get(term_code.lower())
|
||||
|
|
|
|||
|
|
@ -236,27 +236,29 @@ class Portal:
|
|||
widget_width, widget_height = appearance_dimensions
|
||||
x, y = self.position
|
||||
if widget_width <= portal_width:
|
||||
if self.x_alignment == Alignment.left:
|
||||
x = 0
|
||||
elif self.x_alignment == Alignment.center:
|
||||
x = (widget_width - portal_width) // 2
|
||||
elif self.x_alignment == Alignment.right:
|
||||
x = widget_width - portal_width
|
||||
else:
|
||||
raise NotImplementedError
|
||||
match self.x_alignment:
|
||||
case Alignment.left:
|
||||
x = 0
|
||||
case Alignment.center:
|
||||
x = (widget_width - portal_width) // 2
|
||||
case Alignment.right:
|
||||
x = widget_width - portal_width
|
||||
case _:
|
||||
raise NotImplementedError
|
||||
elif x < 0:
|
||||
x = 0
|
||||
elif x > (widget_width - portal_width):
|
||||
x = widget_width - portal_width
|
||||
if widget_height <= portal_height:
|
||||
if self.y_alignment == Alignment.top:
|
||||
y = 0
|
||||
elif self.y_alignment == Alignment.center:
|
||||
y = (widget_height - portal_height) // 2
|
||||
elif self.y_alignment == Alignment.bottom:
|
||||
y = widget_height - portal_height
|
||||
else:
|
||||
raise NotImplementedError
|
||||
match self.y_alignment:
|
||||
case Alignment.top:
|
||||
y = 0
|
||||
case Alignment.center:
|
||||
y = (widget_height - portal_height) // 2
|
||||
case Alignment.bottom:
|
||||
y = widget_height - portal_height
|
||||
case _:
|
||||
raise NotImplementedError
|
||||
elif y < 0:
|
||||
y = 0
|
||||
elif y > (widget_height - portal_height):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue