Coding style

- Use match statement where possible.
This commit is contained in:
Andrew Hamilton 2022-05-31 16:41:09 +10:00
parent 0ab831e48b
commit f0159eb6ff
2 changed files with 25 additions and 22 deletions

View file

@ -616,10 +616,11 @@ class Help:
def on_mouse_input(self, term_code): def on_mouse_input(self, term_code):
event = terminal.decode_mouse_input(term_code) event = terminal.decode_mouse_input(term_code)
if event[1] == terminal.MOUSE_WHEEL_UP: match event[1]:
case terminal.MOUSE_WHEEL_UP:
self.view.portal.scroll_up() self.view.portal.scroll_up()
fill3.APPEARANCE_CHANGED_EVENT.set() fill3.APPEARANCE_CHANGED_EVENT.set()
elif event[1] == terminal.MOUSE_WHEEL_DOWN: case terminal.MOUSE_WHEEL_DOWN:
self.view.portal.scroll_down() self.view.portal.scroll_down()
fill3.APPEARANCE_CHANGED_EVENT.set() fill3.APPEARANCE_CHANGED_EVENT.set()

View file

@ -236,26 +236,28 @@ class Portal:
widget_width, widget_height = appearance_dimensions widget_width, widget_height = appearance_dimensions
x, y = self.position x, y = self.position
if widget_width <= portal_width: if widget_width <= portal_width:
if self.x_alignment == Alignment.left: match self.x_alignment:
case Alignment.left:
x = 0 x = 0
elif self.x_alignment == Alignment.center: case Alignment.center:
x = (widget_width - portal_width) // 2 x = (widget_width - portal_width) // 2
elif self.x_alignment == Alignment.right: case Alignment.right:
x = widget_width - portal_width x = widget_width - portal_width
else: case _:
raise NotImplementedError raise NotImplementedError
elif x < 0: elif x < 0:
x = 0 x = 0
elif x > (widget_width - portal_width): elif x > (widget_width - portal_width):
x = widget_width - portal_width x = widget_width - portal_width
if widget_height <= portal_height: if widget_height <= portal_height:
if self.y_alignment == Alignment.top: match self.y_alignment:
case Alignment.top:
y = 0 y = 0
elif self.y_alignment == Alignment.center: case Alignment.center:
y = (widget_height - portal_height) // 2 y = (widget_height - portal_height) // 2
elif self.y_alignment == Alignment.bottom: case Alignment.bottom:
y = widget_height - portal_height y = widget_height - portal_height
else: case _:
raise NotImplementedError raise NotImplementedError
elif y < 0: elif y < 0:
y = 0 y = 0