Fix gridbox segfault (#260)

The problem was about
This commit is contained in:
Nikola Dućak 2021-11-17 10:16:09 +01:00 committed by GitHub
parent 0186f8a463
commit cecd54df42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -20,7 +20,7 @@ class GridBox : public Node {
for (const auto& line : lines_) for (const auto& line : lines_)
x_size = std::max(x_size, (int)line.size()); x_size = std::max(x_size, (int)line.size());
for (auto& line : lines_) { for (auto& line : lines_) {
while (line.size() < (size_t)y_size) { while (line.size() < (size_t)x_size) {
line.push_back(filler()); line.push_back(filler());
} }
} }

View File

@ -569,6 +569,25 @@ TEST(GridboxTest, Horizontal_FlexGrow_NoFlex_FlewShrink) {
} }
} }
// Regression test for https://github.com/ArthurSonzogni/FTXUI/issues/259
TEST(GridboxTest, MissingCells) {
auto root = gridbox({
{cell("1"), cell("2"), cell("3")},
{cell("4"), cell("5")},
});
Screen screen(20, 7);
Render(screen, root);
EXPECT_EQ(screen.ToString(),
"╭─╮╭─╮╭─╮ \r\n"
"│1││2││3│ \r\n"
"╰─╯╰─╯╰─╯ \r\n"
"╭─╮╭─╮ \r\n"
"│4││5│ \r\n"
"╰─╯╰─╯ \r\n"
" ");
}
// Copyright 2020 Arthur Sonzogni. All rights reserved. // Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in // Use of this source code is governed by the MIT license that can be found in
// the LICENSE file. // the LICENSE file.