From f94188a64dd0aadde866861a0cab6d2661048895 Mon Sep 17 00:00:00 2001 From: Nameless Date: Fri, 24 Jul 2020 10:12:42 +0800 Subject: [PATCH] Fix invalid width count when resizing and terminal width is uneven (#164) --- tg/controllers.py | 6 ++++-- tg/views.py | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tg/controllers.py b/tg/controllers.py index 48d39c7..1cd5eec 100644 --- a/tg/controllers.py +++ b/tg/controllers.py @@ -747,8 +747,10 @@ class Controller: self.view.stdscr.erase() self.view.stdscr.noutrefresh() - self.view.chats.resize(rows, cols, self.chat_size) - self.view.msgs.resize(rows, cols, 1 - self.chat_size) + chat_width = round(cols * self.chat_size) + msg_width = cols - chat_width + self.view.chats.resize(rows, cols, chat_width) + self.view.msgs.resize(rows, cols, msg_width) self.view.status.resize(rows, cols) self.render() diff --git a/tg/views.py b/tg/views.py index 9e871e2..31d765b 100644 --- a/tg/views.py +++ b/tg/views.py @@ -137,9 +137,9 @@ class ChatView: self._refresh = self.win.refresh self.model = model - def resize(self, rows: int, cols: int, p: float = 0.25) -> None: + def resize(self, rows: int, cols: int, width: int) -> None: self.h = rows - 1 - self.w = round(cols * p) + self.w = width self.win.resize(self.h, self.w) def _msg_color(self, is_selected: bool = False) -> int: @@ -278,9 +278,9 @@ class MsgView: "messageSendingStatePending": "pending", } - def resize(self, rows: int, cols: int, p: float = 0.5) -> None: + def resize(self, rows: int, cols: int, width: int) -> None: self.h = rows - 1 - self.w = round(cols * p) + self.w = width self.x = cols - self.w self.win.resize(self.h, self.w) self.win.mvwin(0, self.x)