From 9d10ca4f39f30cb10ada1bc24cd928af0f2cc843 Mon Sep 17 00:00:00 2001 From: Scyfris Talivinsky Date: Sun, 15 Oct 2017 13:36:08 -0700 Subject: [PATCH] Fix an issue with adding an empty column to an EvTable There seems to be an issue with adding an empty column (i.e. a column with empty data) to an EvTable that has already been set up. It seems that the column with empty data is added with one extra row than the rest of the table, and when a new call to add_rows() is made to EvTable, the data in the column that was added previously is offset by 1. This change fixes that by calculating the size of the new column to take into account the headers BEFORE making the calculation on whether to expand the column to match the table's size or not. --- evennia/utils/evtable.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/evennia/utils/evtable.py b/evennia/utils/evtable.py index 70abe2439c..31218189ab 100644 --- a/evennia/utils/evtable.py +++ b/evennia/utils/evtable.py @@ -1421,8 +1421,21 @@ class EvTable(object): column = EvColumn(*args, **options) wtable = self.ncols htable = self.nrows - excess = len(column) - htable + header = kwargs.get("header", None) + if header: + column.add_rows(unicode(header), ypos=0, **options) + self.header = True + elif self.header: + # we have a header already. Offset + column.add_rows("", ypos=0, **options) + + # Calculate whether the new column needs to expand to the + # current table size, or if the table needs to expand to + # the column size. + # This needs to happen after the header rows have already been + # added to the column in order for the size calculations to match. + excess = len(column) - htable if excess > 0: # we need to add new rows to table for col in self.table: @@ -1435,13 +1448,6 @@ class EvTable(object): column.add_rows(*empty_rows, **options) self.nrows -= excess - header = kwargs.get("header", None) - if header: - column.add_rows(unicode(header), ypos=0, **options) - self.header = True - elif self.header: - # we have a header already. Offset - column.add_rows("", ypos=0, **options) if xpos is None or xpos > wtable - 1: # add to the end self.table.append(column)