Added a box element

This commit is contained in:
Nicolas Margulies 2020-11-20 18:06:43 +01:00
parent 7e63607836
commit 9ca6561bc3

View File

@ -33,7 +33,7 @@ class Display:
self.width = width
self.height = height
if hasattr(self, "pad") and resize_pad:
self.pad.resize(self.height, self.width)
self.pad.resize(self.height + 1, self.width + 1)
def refresh(self, *args, resize_pad: bool = True) -> None:
if len(args) == 4:
@ -69,7 +69,7 @@ class VerticalSplit(Display):
def display(self) -> None:
for i in range(self.height):
self.pad.addstr(i, 0, "")
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height, self.x)
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x)
class HorizontalSplit(Display):
@ -89,4 +89,19 @@ class HorizontalSplit(Display):
def display(self) -> None:
for i in range(self.width):
self.pad.addstr(0, i, "")
self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width)
self.pad.refresh(0, 0, self.y, self.x, self.y, self.x + self.width - 1)
class Box(Display):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.pad = self.newpad(self.rows, self.cols)
def display(self) -> None:
self.pad.addstr(0, 0, "" + "" * (self.width - 2) + "")
for i in range(1, self.height - 1):
self.pad.addstr(i, 0, "")
self.pad.addstr(i, self.width - 1, "")
self.pad.addstr(self.height - 1, 0,
"" + "" * (self.width - 2) + "")
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height - 1, self.x + self.width - 1)