mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
ui/curses: implement game view widget focusing
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import contextlib
|
||||
import typing as T
|
||||
|
||||
from pqcli.ui.curses.event_handler import EventHandler
|
||||
|
||||
|
||||
class Focusable:
|
||||
def __init__(self, *args: T.Any, **kwargs: T.Any) -> None:
|
||||
self._focused = False
|
||||
self._on_focus_change = EventHandler()
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def focused(self) -> bool:
|
||||
return self._focused
|
||||
|
||||
@focused.setter
|
||||
def focused(self, focused: bool) -> None:
|
||||
self._focused = focused
|
||||
self._on_focus_change()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _focus_standout(self, win: T.Any) -> T.Generator:
|
||||
if self._focused:
|
||||
self._win.standout()
|
||||
yield
|
||||
if self._focused:
|
||||
self._win.standend()
|
||||
Reference in New Issue
Block a user