Add title to boxes to have pretty boxes, fixes #28

This commit is contained in:
Yohann D'ANELLO
2020-12-12 17:15:08 +01:00
parent 158338637a
commit 73e1fac89a
5 changed files with 116 additions and 84 deletions

View File

@ -222,6 +222,10 @@ class HorizontalSplit(Display):
class Box(Display):
title: str = ""
def update_title(self, title: str) -> None:
self.title = title
def __init__(self, *args, fg_border_color: Optional[int] = None, **kwargs):
super().__init__(*args, **kwargs)
@ -236,5 +240,11 @@ class Box(Display):
self.addstr(self.pad, i, self.width - 1, "", self.fg_border_color)
self.addstr(self.pad, self.height - 1, 0,
"" + "" * (self.width - 2) + "", self.fg_border_color)
if self.title:
self.addstr(self.pad, 0, (self.width - len(self.title) - 8) // 2,
f" == {self.title} == ", curses.COLOR_GREEN,
italic=True, bold=True)
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
self.y + self.height - 1, self.x + self.width - 1)