mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
Simplify the Render(screen, document) function.
This commit is contained in:
parent
957387adaa
commit
e34f051f7a
@ -39,6 +39,6 @@ int main(int argc, const char* argv[]) {
|
||||
filler(),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L"overlay") | border | center,
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -23,7 +23,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L" " + data_downloaded),
|
||||
});
|
||||
auto screen = Screen(100, 1);
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
|
@ -64,7 +64,7 @@ int main(int argc, const char* argv[]) {
|
||||
border | size(HEIGHT, GREATER_THAN, 40);
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
|
||||
reset_position = screen.ResetPosition();
|
||||
|
@ -43,7 +43,7 @@ int main(int argc, const char* argv[]) {
|
||||
style;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
|
||||
return 0;
|
||||
|
@ -45,7 +45,7 @@ int main(int argc, const char* argv[]) {
|
||||
border;
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full());
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
|
||||
reset_position = screen.ResetPosition();
|
||||
|
@ -125,7 +125,7 @@ int main(int argc, const char* argv[]) {
|
||||
// Draw.
|
||||
auto document = render();
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
|
@ -29,7 +29,7 @@ int main(int argc, const char* argv[]) {
|
||||
});
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Full());
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString();
|
||||
getchar();
|
||||
|
||||
|
@ -22,7 +22,7 @@ int main(int argc, const char* argv[]) {
|
||||
}) |
|
||||
border;
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
|
||||
|
@ -22,7 +22,7 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
auto document = hbox(std::move(content));
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
|
||||
return 0;
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, const char* argv[]) {
|
||||
filler(),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << reset_position << screen.ToString() << std::flush;
|
||||
reset_position = screen.ResetPosition();
|
||||
|
||||
|
@ -16,7 +16,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -16,7 +16,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -55,7 +55,7 @@ int main(int argc, const char* argv[]) {
|
||||
// clang-format on
|
||||
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -16,7 +16,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -23,7 +23,7 @@ int main(int argc, const char* argv[]) {
|
||||
});
|
||||
// clang-format on
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -15,7 +15,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -16,7 +16,7 @@ int main(int argc, const char* argv[]) {
|
||||
text(L". Do you like it?"),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
|
||||
|
@ -30,7 +30,7 @@ int main(int argc, const char* argv[]) {
|
||||
}),
|
||||
});
|
||||
auto screen = Screen::Create(Dimension::Full());
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
|
||||
std::cout << screen.ToString();
|
||||
getchar();
|
||||
|
@ -65,7 +65,7 @@
|
||||
filler()
|
||||
);
|
||||
auto screen = Screen::Create(Dimension::Fit(document));
|
||||
Render(screen, document.get());
|
||||
Render(screen, document);
|
||||
std::cout << screen.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ class Node {
|
||||
Box box_;
|
||||
};
|
||||
|
||||
void Render(Screen& screen, const Element& node);
|
||||
void Render(Screen& screen, Node* node);
|
||||
|
||||
} // namespace ftxui
|
||||
|
@ -321,7 +321,7 @@ void ScreenInteractive::Draw(Component* component) {
|
||||
cursor_.y = dimy_ - 1;
|
||||
}
|
||||
|
||||
Render(*this, document.get());
|
||||
Render(*this, document);
|
||||
|
||||
// Set cursor position for user using tools to insert CJK characters.
|
||||
set_cursor_position = "";
|
||||
|
@ -12,7 +12,7 @@ using namespace ftxui;
|
||||
TEST(GaugeTest, zero) {
|
||||
auto root = gauge(0);
|
||||
Screen screen(11, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ(" ", screen.ToString());
|
||||
}
|
||||
@ -20,7 +20,7 @@ TEST(GaugeTest, zero) {
|
||||
TEST(GaugeTest, half) {
|
||||
auto root = gauge(0.5);
|
||||
Screen screen(11, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("█████▍ ", screen.ToString());
|
||||
//" ▏▎▍▌▊▉█";
|
||||
@ -29,7 +29,7 @@ TEST(GaugeTest, half) {
|
||||
TEST(GaugeTest, one) {
|
||||
auto root = gauge(1.0);
|
||||
Screen screen(11, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("███████████", screen.ToString());
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using namespace ftxui;
|
||||
TEST(HBoxTest, ScreenSmaller1) {
|
||||
auto root = hbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(11, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text_", screen.ToString());
|
||||
}
|
||||
@ -20,7 +20,7 @@ TEST(HBoxTest, ScreenSmaller1) {
|
||||
TEST(HBoxTest, ScreenSmaller2) {
|
||||
auto root = hbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(10, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text", screen.ToString());
|
||||
}
|
||||
@ -28,7 +28,7 @@ TEST(HBoxTest, ScreenSmaller2) {
|
||||
TEST(HBoxTest, ScreenFit) {
|
||||
auto root = hbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(12, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text_2", screen.ToString());
|
||||
}
|
||||
@ -36,14 +36,14 @@ TEST(HBoxTest, ScreenFit) {
|
||||
TEST(HBoxTest, ScreenBigger1) {
|
||||
auto root = hbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(13, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text_2 ", screen.ToString());
|
||||
}
|
||||
TEST(HBoxTest, ScreenBigger2) {
|
||||
auto root = hbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(14, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text_2 ", screen.ToString());
|
||||
}
|
||||
@ -51,7 +51,7 @@ TEST(HBoxTest, ScreenBigger2) {
|
||||
TEST(HBoxTest, ScreenSmaller1Flex) {
|
||||
auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(11, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_text_2", screen.ToString());
|
||||
}
|
||||
@ -59,7 +59,7 @@ TEST(HBoxTest, ScreenSmaller1Flex) {
|
||||
TEST(HBoxTest, ScreenSmaller2Flex) {
|
||||
auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(10, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("texttext_2", screen.ToString());
|
||||
}
|
||||
@ -67,7 +67,7 @@ TEST(HBoxTest, ScreenSmaller2Flex) {
|
||||
TEST(HBoxTest, ScreenFitFlex) {
|
||||
auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(12, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1text_2", screen.ToString());
|
||||
}
|
||||
@ -75,7 +75,7 @@ TEST(HBoxTest, ScreenFitFlex) {
|
||||
TEST(HBoxTest, ScreenBigger1Flex) {
|
||||
auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(13, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1 text_2", screen.ToString());
|
||||
}
|
||||
@ -83,7 +83,7 @@ TEST(HBoxTest, ScreenBigger1Flex) {
|
||||
TEST(HBoxTest, ScreenBigger2Flex) {
|
||||
auto root = hbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(14, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1 text_2", screen.ToString());
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ void Node::Render(Screen& screen) {
|
||||
child->Render(screen);
|
||||
}
|
||||
|
||||
void Render(Screen& screen, const Element& element) {
|
||||
Render(screen, element);
|
||||
}
|
||||
|
||||
void Render(Screen& screen, Node* node) {
|
||||
// Step 1: Find what dimension this elements wants to be.
|
||||
node->ComputeRequirement();
|
||||
|
@ -12,7 +12,7 @@ using namespace ftxui;
|
||||
TEST(TextTest, ScreenHeightSmaller) {
|
||||
auto element = text(L"test");
|
||||
Screen screen(2, 0);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
|
||||
EXPECT_EQ("", screen.ToString());
|
||||
}
|
||||
@ -20,7 +20,7 @@ TEST(TextTest, ScreenHeightSmaller) {
|
||||
TEST(TextTest, ScreenSmaller) {
|
||||
auto element = text(L"test");
|
||||
Screen screen(2, 1);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
|
||||
EXPECT_EQ("te", screen.ToString());
|
||||
}
|
||||
@ -28,7 +28,7 @@ TEST(TextTest, ScreenSmaller) {
|
||||
TEST(TextTest, ScreenFit) {
|
||||
auto element = text(L"test");
|
||||
Screen screen(4, 1);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
|
||||
EXPECT_EQ("test", screen.ToString());
|
||||
}
|
||||
@ -36,7 +36,7 @@ TEST(TextTest, ScreenFit) {
|
||||
TEST(TextTest, ScreenBigger) {
|
||||
auto element = text(L"test");
|
||||
Screen screen(6, 1);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
|
||||
EXPECT_EQ("test ", screen.ToString());
|
||||
}
|
||||
@ -44,7 +44,7 @@ TEST(TextTest, ScreenBigger) {
|
||||
TEST(TextTest, ScreenBigger2) {
|
||||
auto element = text(L"test");
|
||||
Screen screen(6, 2);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
|
||||
EXPECT_EQ("test \n ", screen.ToString());
|
||||
}
|
||||
@ -53,7 +53,7 @@ TEST(TextTest, ScreenBigger2) {
|
||||
TEST(TextTest, CJK) {
|
||||
auto element = text(L"测试") | border;
|
||||
Screen screen(6, 3);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(
|
||||
"┌────┐\n"
|
||||
"│测试│\n"
|
||||
@ -65,7 +65,7 @@ TEST(TextTest, CJK) {
|
||||
TEST(TextTest, CJK_2) {
|
||||
auto element = text(L"测试") | border;
|
||||
Screen screen(5, 3);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(
|
||||
"┌───┐\n"
|
||||
"│测试\n"
|
||||
@ -77,7 +77,7 @@ TEST(TextTest, CJK_2) {
|
||||
TEST(TextTest, CJK_3) {
|
||||
auto element = text(L"测试") | border;
|
||||
Screen screen(4, 3);
|
||||
Render(screen, element.get());
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(
|
||||
"┌──┐\n"
|
||||
"│测│\n"
|
||||
|
@ -12,7 +12,7 @@ using namespace ftxui;
|
||||
TEST(VBoxTest, ScreenSmaller1) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1", screen.ToString());
|
||||
}
|
||||
@ -20,7 +20,7 @@ TEST(VBoxTest, ScreenSmaller1) {
|
||||
TEST(VBoxTest, ScreenFit) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 2);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\ntext_2", screen.ToString());
|
||||
}
|
||||
@ -28,14 +28,14 @@ TEST(VBoxTest, ScreenFit) {
|
||||
TEST(VBoxTest, ScreenBigger1) {
|
||||
auto root = vbox(text(L"text_1"), text(L"text_2"));
|
||||
Screen screen(6, 3);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
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.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\ntext_2\n \n ", screen.ToString());
|
||||
}
|
||||
@ -43,7 +43,7 @@ TEST(VBoxTest, ScreenBigger2) {
|
||||
TEST(VBoxTest, ScreenSmaller1Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 1);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_2", screen.ToString());
|
||||
}
|
||||
@ -51,7 +51,7 @@ TEST(VBoxTest, ScreenSmaller1Flex) {
|
||||
TEST(VBoxTest, ScreenFitFlex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(7, 5);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ(
|
||||
"text_1 \n"
|
||||
@ -65,14 +65,14 @@ TEST(VBoxTest, ScreenFitFlex) {
|
||||
TEST(VBoxTest, ScreenBigger1Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 3);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\n \ntext_2", screen.ToString());
|
||||
}
|
||||
TEST(VBoxTest, ScreenBigger2Flex) {
|
||||
auto root = vbox(text(L"text_1"), filler(), text(L"text_2"));
|
||||
Screen screen(6, 4);
|
||||
Render(screen, root.get());
|
||||
Render(screen, root);
|
||||
|
||||
EXPECT_EQ("text_1\n \n \ntext_2", screen.ToString());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user