mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Add flex_grow and flex_shrink.
Two new elements: - flex_grow : Expand the element to occupy free space. - flex_shrink: Minimize the element leave away missing space. flex = flex_grow | flex_shrink. Other changes: - hbox and vbox are now non flexible by default. - the vtext element has been added to help writting tests. - Many new tests.
This commit is contained in:

committed by
Arthur Sonzogni

parent
7f7775ba62
commit
08ee49f3e6
@@ -9,70 +9,352 @@
|
||||
using namespace ftxui;
|
||||
using namespace ftxui;
|
||||
|
||||
TEST(VBoxTest, ScreenSmaller1) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 1);
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1", screen.ToString());
|
||||
std::string rotate(std::string str) {
|
||||
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
TEST(VBoxTest, ScreenFit) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 2);
|
||||
Render(screen, root);
|
||||
TEST(VBoxText, NoFlex_NoFlex_NoFlex) {
|
||||
auto root = vbox({
|
||||
vtext(L"012"),
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC"),
|
||||
});
|
||||
|
||||
EXPECT_EQ("text_1\ntext_2", screen.ToString());
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxTest, ScreenBigger1) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 3);
|
||||
Render(screen, root);
|
||||
TEST(VBoxText, FlexGrow_NoFlex_NoFlex) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_grow,
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC"),
|
||||
});
|
||||
|
||||
EXPECT_EQ("text_1\ntext_2\n ", screen.ToString());
|
||||
}
|
||||
TEST(VBoxTest, ScreenBigger2) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 4);
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\ntext_2\n \n ", screen.ToString());
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012 abcABC", //
|
||||
"012 abcABC", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxTest, ScreenSmaller1Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 1);
|
||||
Render(screen, root);
|
||||
TEST(VBoxText, NoFlex_FlexGrow_NoFlex) {
|
||||
auto root = vbox({
|
||||
vtext(L"012"),
|
||||
vtext(L"abc") | flex_grow,
|
||||
vtext(L"ABC"),
|
||||
});
|
||||
|
||||
EXPECT_EQ("text_2", screen.ToString());
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abc ABC", //
|
||||
"012abc ABC", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxTest, ScreenFitFlex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(7, 5);
|
||||
Render(screen, root);
|
||||
TEST(VBoxText, NoFlex_NoFlex_FlexGrow) {
|
||||
auto root = vbox({
|
||||
vtext(L"012"),
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC") | flex_grow,
|
||||
});
|
||||
|
||||
EXPECT_EQ(
|
||||
"text_1 \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
"text_2 ",
|
||||
screen.ToString());
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxTest, ScreenBigger1Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 3);
|
||||
Render(screen, root);
|
||||
TEST(VBoxText, FlexGrow_NoFlex_FlexGrow) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_grow,
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC") | flex_grow,
|
||||
});
|
||||
|
||||
EXPECT_EQ("text_1\n \ntext_2", screen.ToString());
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012 abcABC ", //
|
||||
"012 abcABC ", //
|
||||
"012 abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
TEST(VBoxTest, ScreenBigger2Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 4);
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\n \n \ntext_2", screen.ToString());
|
||||
TEST(VBoxText, FlexGrow_FlexGrow_FlexGrow) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_grow,
|
||||
vtext(L"abc") | flex_grow,
|
||||
vtext(L"ABC") | flex_grow,
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abc ABC ", //
|
||||
"012 abc ABC ", //
|
||||
"012 abc ABC ", //
|
||||
"012 abc ABC ", //
|
||||
"012 abc ABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
// ------
|
||||
|
||||
TEST(VBoxText, FlexShrink_NoFlex_NoFlex) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_shrink,
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC"),
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"a", //
|
||||
"aA", //
|
||||
"abA", //
|
||||
"abAB", //
|
||||
"abcAB", //
|
||||
"abcABC", //
|
||||
"0abcABC", //
|
||||
"01abcABC", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxText, NoFlex_FlexShrink_NoFlex) {
|
||||
auto root = vbox({
|
||||
vtext(L"012"),
|
||||
vtext(L"abc") | flex_shrink,
|
||||
vtext(L"ABC"),
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0A", //
|
||||
"01A", //
|
||||
"01AB", //
|
||||
"012AB", //
|
||||
"012ABC", //
|
||||
"012aABC", //
|
||||
"012abABC", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxText, NoFlex_NoFlex_FlexShrink) {
|
||||
auto root = vbox({
|
||||
vtext(L"012"),
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC") | flex_shrink,
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"01a", //
|
||||
"01ab", //
|
||||
"012ab", //
|
||||
"012abc", //
|
||||
"012abcA", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxText, FlexShrink_NoFlex_FlexShrink) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_shrink,
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC") | flex_shrink,
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"a", //
|
||||
"ab", //
|
||||
"abc", //
|
||||
"0abc", //
|
||||
"0abcA", //
|
||||
"01abcA", //
|
||||
"01abcAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxText, FlexShrink_FlexShrink_FlexShrink) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_shrink,
|
||||
vtext(L"abc") | flex_shrink,
|
||||
vtext(L"ABC") | flex_shrink,
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"0aA", //
|
||||
"01aA", //
|
||||
"01abA", //
|
||||
"01abAB", //
|
||||
"012abAB", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
"012abcABC ", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(VBoxText, FlexGrow_NoFlex_FlewShrink) {
|
||||
auto root = vbox({
|
||||
vtext(L"012") | flex_grow,
|
||||
vtext(L"abc"),
|
||||
vtext(L"ABC") | flex_shrink,
|
||||
});
|
||||
|
||||
std::vector<std::string> expectations = {
|
||||
"", //
|
||||
"0", //
|
||||
"0a", //
|
||||
"01a", //
|
||||
"01ab", //
|
||||
"012ab", //
|
||||
"012abc", //
|
||||
"012abcA", //
|
||||
"012abcAB", //
|
||||
"012abcABC", //
|
||||
"012 abcABC", //
|
||||
"012 abcABC", //
|
||||
"012 abcABC", //
|
||||
};
|
||||
for (int i = 0; i < expectations.size(); ++i) {
|
||||
Screen screen(1, i);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(expectations[i], rotate(screen.ToString()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user