basic cursor

3-keyboard-control
Felix Pankratz 5 months ago
parent 7cf7923b63
commit f01fae27d7

@ -2,6 +2,7 @@ from textual.reactive import reactive
from textual.widget import Widget
from textual.app import ComposeResult
from textual.message import Message
from textual import events
from datetime import datetime
import random
@ -75,6 +76,20 @@ class BingoBoard(Widget):
fields = self.query(BingoField)
fields[self.fieldnum_from_cursor()].set_highlighted(False)
def on_key(self, event: events.Key) -> None:
fields = self.query(BingoField)
fields[self.fieldnum_from_cursor()].set_highlighted(False)
match event.key:
case 'up':
self.cursor_y -= 1 if self.cursor_y > 0 else 0
case 'down':
self.cursor_y += 1 if self.cursor_y < 4 else 0
case 'left':
self.cursor_x -= 1 if self.cursor_x > 0 else 0
case 'right':
self.cursor_x += 1 if self.cursor_x < 4 else 0
fields[self.fieldnum_from_cursor()].set_highlighted(True)
async def on_bingo_field_selected(self, message: BingoField.Selected) -> None:
self.fieldstate[message.num] = message.selected

Loading…
Cancel
Save