Closed sla-te closed 3 years ago
The "columns" function has a really ugly API. I didn't think of a better one - do you have some ideas?
def columns(elems, identifier=None, vert_borders=True, hor_borders=True, widths=None) -> Widget:
"""
Table, using the imgui columns API.
:param List[List[Widget]] elems: 2D array of widgets. A list containing another list for
each row. len() of the first row defines the amount of columns, that will be rendered.
:param identifier: TODO
:param bool hor_borders: Toggle horizontal borders on/off.
:param List[Union[int,float]] widths: is an optional vector of column widths in pixels. May
contain None values.
:param bool vert_borders: Toggle horizontal borders on/off.
:return: orr() wrapping the column widget.
:rtype: WidgetWrapper
"""
# TODO Move import to top of script
from concur.core import nothing
n_columns = len(elems[0])
if widths is None:
widths = []
if hor_borders:
sep = [separator(), *[nothing() for _ in range(n_columns - 1)]]
n, i = 1, 1
while i < len(elems):
elems.insert(i, sep)
i += (n + 1)
accum = [lift(imgui.columns, n_columns, identifier, vert_borders)]
for i, w in enumerate(widths):
if w is not None:
accum.append(lift(imgui.set_column_width, i, w))
for row in elems:
assert len(row) == n_columns
for widget in row:
accum.append(widget)
accum.append(lift(imgui.next_column))
accum.append(lift(imgui.columns, 1))
return orr(accum)
https://github.com/potocpav/python-concur/blob/5cc92d2ffc57ed896d2aced048be54a53c42199e/concur/widgets.py#L570
drops
If we comment out the assertion it works fine.
EDIT: In fact it doesn't work fine if we do that, the rows will be out of order. How do we properly add horizontal separators? EDIT2: Ah, we can do
[c.separator(), c.nothing(), c.nothing(), c.nothing()]
would add that to the docs