Change EvTable vertical rebalance algorithm to simply add empty rows at end. Produces more consistent visual result than old algorithm which could sometimes look like a bug.

This commit is contained in:
Griatch 2021-09-17 00:49:37 +02:00
parent 28fae7af09
commit b19b77f549
3 changed files with 109 additions and 26 deletions

View file

@ -86,8 +86,10 @@ Up requirements to Django 3.2+
but `Cmd_nAmE` -> `Cmd.nAmE`). This helps e.g Mudlet's legacy `Client_GUI` implementation)
- Prototypes now allow setting `prototype_parent` directly to a prototype-dict.
This makes it easier when dynamically building in-module prototypes.
- RPSystem contrib was expanded to support case, so /tall becomes 'tall man'
- `RPSystem contrib` was expanded to support case, so /tall becomes 'tall man'
while /Tall becomes 'Tall man'. One can turn this off if wanting the old style.
- Change `EvTable` fixed-height rebalance algorithm to fill with empty lines at end of
column instead of inserting rows based on cell-size (could be mistaken for a bug).
### Evennia 0.9.5 (2019-2020)

View file

@ -1478,31 +1478,13 @@ class EvTable(object):
% (self.height, chmin + locked_height)
)
# now we add all the extra height up to the desired table-height.
# We do this so that the tallest cells gets expanded first (and
# thus avoid getting cropped)
even = self.height % 2 == 0
correction = 0
while correction < excess:
# expand the cells with the most rows first
if 0 <= correction < nrowmax and nrowmax > 1:
# avoid adding to header first round (looks bad on very small tables)
ci = cheights[1:].index(max(cheights[1:])) + 1
else:
ci = cheights.index(max(cheights))
if ci in locked_cols:
# locked row, make sure it's not picked again
cheights[ci] -= 9999
cheights_min[ci] = locked_cols[ci]
else:
cheights_min[ci] += 1
# change balance
if ci == 0 and self.header:
# it doesn't look very good if header expands too fast
cheights[ci] -= 2 if even else 3
cheights[ci] -= 2 if even else 1
correction += 1
# Add all the excess at the end of the table
# Note: Older solutions tried to balance individual
# rows' vsize. This could lead to empty rows that
# looked like a bug. This solution instead
# adds empty rows at the end which is less sophisticated
# but much more visually consistent.
cheights_min[-1] += excess
cheights = cheights_min
# we must tell cells to crop instead of expanding

View file

@ -165,3 +165,102 @@ Durian
""".lstrip()
result = self._simple_form(form)
self.assertEqual(expected, result)
# test of issue #2308
_SHEET = """
.----------------------------------------------.
| Sheet |
| xxxxxxxxxxxxxxxxxxxxxxxxxx1xxxxxxxxxxxx |
>----------------------------------------------<
| Ability scores | Skills |
| ccccccccccccccc | ccccccccccccccccccc |
| cccccc2cccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| ccccccccccccccc | ccccccccccccccccccc |
| | ccccccccc3ccccccccc |
| | ccccccccccccccccccc |
| | ccccccccccccccccccc |
| | ccccccccccccccccccc |
| | |
+----------------------------------------------+
"""
_EXPECTED = """
.----------------------------------------------.
| Sheet |
| Test text |
>----------------------------------------------<
| Ability scores | Skills |
| +------+------+ | +--------+--------+ |
| |Ab |Sc | | |Skill |Level | |
| +~~~~~~+~~~~~~+ | +~~~~~~~~+~~~~~~~~+ |
| |STR |10 | | |Acro |10 | |
| |CON |10 | | |Anim |10 | |
| |DEX |10 | | |Arca |10 | |
| | | | | |Ath |10 | |
| | | | | |Dec |10 | |
| +------+------+ | |His |10 | |
| | | | | |
| | | | | |
| | | | | |
| | +--------+--------+ |
| | |
+----------------------------------------------+
"""
class TestEvFormParallelTables(TestCase):
"""
Test of issue #2308
https://github.com/evennia/evennia/issues/2308
where parallel tables cause strange overlaps
in output
"""
def setUp(self):
self.text1 = "Test text"
self.table2 = evtable.EvTable(
"Ab", "Sc",
table=[
["|ySTR", "|yCON", "|yDEX"],
[10, 10, 10]
]
)
self.table3 = evtable.EvTable(
"|RSkill", "|RLevel",
table=[
["|yAcro", "|yAnim", "|yArca", "|yAth", "|yDec", "|yHis"],
[10, 10, 10, 10, 10, 10]
]
)
self.formdict = {
"FORM": _SHEET,
"FORMCHAR": 'x',
"TABLECHAR": 'c'
}
def test_parallel_tables(self):
"""
Build form to check for error.
"""
form = evform.EvForm(form=self.formdict)
form.map(
cells={
'1': self.text1,
},
tables={
'2': self.table2,
'3': self.table3
}
)
self.assertEqual(
ansi.strip_ansi(str(form).strip()),
_EXPECTED.strip()
)