table: unable to display table with more than 64 columns
Hi there, in refer to https://github.com/OpenDiablo2/HellSpawner/issues/335#issuecomment-893227410 I'd like to show the situation, we can notice the behavior: when I create a large table, e.g.:
rowItems := make([]giu.Widget, numCols)
for i := range rowItems {
rowItems[i] = giu.Label(strconv.Itoa(i))
}
row := giu.TableRow(rowItems...)
full code
package main
import (
"strconv"
"github.com/AllenDang/giu"
)
func loop() {
const numCols = 65
rowItems := make([]giu.Widget, numCols)
for i := range rowItems {
rowItems[i] = giu.Label(strconv.Itoa(i))
}
row := giu.TableRow(rowItems...)
giu.SingleWindow().Layout(
giu.Table().Rows(row),
)
}
func main() {
wnd := giu.NewMasterWindow("table", 640, 480, 0)
wnd.Run(loop)
}
i'm getting the following panic:
table: imgui_tables.cpp:323: bool ImGui::BeginTableEx(const char*, ImGuiID, int, ImGuiTableFlags, const ImVec2&, float): Assertion `columns_count > 0 && columns_count <= 64 && "Only 1..64 columns allowed!"' failed.
SIGABRT: abort
PC=0x7f7e2133d9e5 m=0 sigcode=18446744073709551610
signal arrived during cgo execution
This is due to a limitation of imgui not of giu.
From imgui_tables.cpp
// Sanity checks
IM_ASSERT(columns_count > 0 && columns_count <= IMGUI_TABLE_MAX_COLUMNS && "Only 1..64 columns allowed!");
So imgui asserts and you get a SIGABRT: abort
you're right. I see an issue in imgui repo: https://github.com/ocornut/imgui/issues/3572 maybe the suggested workaround, would work?
from https://github.com/ocornut/imgui imgui_demog.cpp:
if (ImGui::BeginTable("table_scrolly", 3, flags, outer_size))
{
ImGui::TableSetupScrollFreeze(0, 1); // Make top row always visible
ImGui::TableSetupColumn("One", ImGuiTableColumnFlags_None);
ImGui::TableSetupColumn("Two", ImGuiTableColumnFlags_None);
ImGui::TableSetupColumn("Three", ImGuiTableColumnFlags_None);
ImGui::TableHeadersRow();
// Demonstrate using clipper for large vertical lists
ImGuiListClipper clipper;
clipper.Begin(1000);
while (clipper.Step())
{
for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++)
{
ImGui::TableNextRow();
for (int column = 0; column < 3; column++)
{
ImGui::TableSetColumnIndex(column);
ImGui::Text("Hello %d,%d", column, row);
}
}
}
ImGui::EndTable();
ImGuiListClipper work on the vertical axis which is were the count can grow the most. Both TableSetColumnIndex() and TableNextColumn() return a bool reporting the column visibility so you can skip rendering your contents.
as an alternative, we can update the internal imgui tables mechanism like suggested in https://github.com/ocornut/imgui/issues/3572#issuecomment-885744366
so, to sum up: there are 2 possible workarounds
- externally affect imgui table to display only the visible rows and bypass 64 columns limit
- modify the tables mechanism to remove columns limit
@AllenDang should we focus on working around this issue or just wait until the upstream issue gets solved?
@gucio321 IMO, let's wait upstream issue gets solved. I've been suffered much to apply custom patches, for now the power-saving patch. I have to do line-by-line diff and merge each time upgrading imgui.
@AllenDang upstream issue is solved now IMO, we should wait for cimgui-go migration with that anyway.
@AllenDang upstream issue has been closed. I think it may be fixed after cimgui migration
@gucio321 Yes, after migration this should be fixed.
I still get the error with more than 64 columns, using @latest 0.7.0 and master is not compiling
@gucio321
This works on matter, if it doesn't compile it a separated issue
good to know!
can you point me at a working commit?
this issue was related to old imgui. master uses cimgui-go so relatively new imgui where 64 column tables works. THats why I said master works. (but may not compile, however it does for me)
Thank you