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

@ -9,8 +9,6 @@ class MenuDisplay(Display):
super().__init__(screen)
self.values = menu.values
self.menu = menu
self.width = self.cols
self.height = self.rows
self.trueheight = len(menu.values)
self.truewidth = max(len(item.value) for item in menu.values)
self.topleftx = topleftx
@ -18,33 +16,40 @@ class MenuDisplay(Display):
# Menu values are printed in pad
self.pad = self.newpad(self.trueheight, self.truewidth + 1)
for i in range(self.trueheight):
self.pad.addstr(i, 0, " " + self.values[i].value)
# Menu box
self.menubox = self.newpad(self.height, self.width)
def update_pad(self, position: int) -> None:
self.menubox.addstr(0, 0, "" + "" * (self.width - 2) + "")
for i in range(1, self.height - 2):
self.menubox.addstr(i, 0, "" + " " * (self.width - 2) + "")
self.menubox.addstr(self.height - 2, 0,
"" + "" * (self.width - 2) + "")
def update_pad(self, position: int) -> None:
for i in range(self.trueheight):
self.pad.addstr(i, 0, " " + self.values[i].value)
for i in range(self.trueheight):
self.pad.addstr(i, 0, " ")
# set a marker in front of the selected line
self.pad.addstr(position, 0, ">")
def refresh(self) -> None:
with open("/tmp/log", "a") as f:
f.write(f"{self.width}x{self.height}\n")
self.ensure_resized(self.menubox, self.pad)
if self.height - 2 >= self.menu.position - 1:
cornery = 0
elif self.height - 2 >= self.trueheight - self.menu.position:
cornery = self.trueheight - self.height + 2
self.update_pad(self.menu.position)
self.menubox.refresh(0, 0, self.toplefty, self.topleftx,
self.height + self.toplefty,
self.width + self.topleftx)
self.update_pad(self.menu.position)
self.pad.refresh(cornery, 0, self.toplefty + 1, self.topleftx + 1,
self.height - 2 + self.toplefty,
self.height - 3 + self.toplefty,
self.width - 2 + self.topleftx)