From: Arvin Schnell Date: Mon, 21 Oct 2024 07:10:04 +0000 (+0200) Subject: - fixed visibility handling for trailing columns X-Git-Tag: v0.12.0~21^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F947%2Fhead;p=thirdparty%2Fsnapper.git - fixed visibility handling for trailing columns --- diff --git a/client/utils/Table.cc b/client/utils/Table.cc index 7eb8e56e..d406a6b0 100644 --- a/client/utils/Table.cc +++ b/client/utils/Table.cc @@ -53,6 +53,8 @@ namespace snapper size_t trim = -1; }; + size_t last_visible_idx = 0; + vector column_vars; }; @@ -92,6 +94,12 @@ namespace snapper calculate_widths(table, row, false, 0); calculate_abbriviated_widths(table); + + // calculate last visible idx + + for (size_t idx = 0; idx < column_vars.size(); ++idx) + if (!column_vars[idx].hidden) + last_visible_idx = idx; } @@ -272,7 +280,7 @@ namespace snapper column = output_info.trimmed(column, column_params[idx].align, output_info.column_vars[idx].trim); bool first = idx == 0; - bool last = idx == output_info.column_vars.size() - 1; + bool last = idx == output_info.last_visible_idx; size_t extra = (idx == tree_idx) ? 2 * lasts.size() : 0; @@ -353,7 +361,7 @@ namespace snapper for (size_t j = 0; j < output_info.column_vars[idx].width; ++j) s << glyph(1); - if (idx == output_info.column_vars.size() - 1) + if (idx == output_info.last_visible_idx) break; s << glyph(1) << glyph(2) << glyph(1); diff --git a/testsuite/table.cc b/testsuite/table.cc index 0efb6706..ca36db51 100644 --- a/testsuite/table.cc +++ b/testsuite/table.cc @@ -205,3 +205,23 @@ BOOST_AUTO_TEST_CASE(test7) check(table, output); } + + +BOOST_AUTO_TEST_CASE(test8) +{ + Table table({ "A", "B", Cell("Number", Id::NUMBER, Align::RIGHT) }); + + table.set_style(Style::LIGHT); + table.set_visibility(Id::NUMBER, Visibility::AUTO); + + Table::Row row1(table, { "a", "b", "" }); + table.add(row1); + + vector output = { + "A │ B", + "──┼──", + "a │ b" + }; + + check(table, output); +}