Width and height are managed dynamically: we can almost freely resize the window

This commit is contained in:
Yohann D'ANELLO
2020-11-09 00:44:08 +01:00
parent 0ab0e6a00c
commit e9c8640159
6 changed files with 48 additions and 16 deletions

View File

@ -7,11 +7,37 @@ from dungeonbattle.tests.screen import FakePad
class Display:
def __init__(self, screen: Any):
self.screen = screen
self.rows = curses.LINES if screen else 42
self.cols = curses.COLS * 4 // 5 if screen else 42
def refresh(self) -> None:
raise NotImplementedError
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
return curses.newpad(height, width) if self.screen else FakePad()
def ensure_resized(self, *pads) -> bool:
"""
If the window got resized, ensure that the pads are also resized.
"""
y, x = self.screen.getmaxyx() if self.screen else (0, 0)
for pad in pads:
pad.resize(y, x)
if self.screen and curses.is_term_resized(self.rows, self.cols):
curses.resizeterm(y, x)
return True
return False
@property
def rows(self) -> int:
return curses.LINES if self.screen else 42
@property
def height(self) -> int:
return self.rows
@property
def cols(self) -> int:
return curses.COLS if self.screen else 42
@property
def width(self) -> int:
return self.cols