FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
examples/component/selection.cpp
// 版权所有 2020 Arthur Sonzogni。保留所有权利。
// 本源代码受 MIT 许可证的约束,您可以在 LICENSE 文件中找到该许可证。
#include <string> // for char_traits, operator+, string, basic_string
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
#include "ftxui/util/ref.hpp" // for Ref
using namespace ftxui;
return vbox({
text("FTXUI:一个用于构建用户界面的强大库。"),
text("享受丰富的组件集和声明式风格。"),
text("以最小的努力创建美观且响应迅速的 UI。"),
text("加入社区,体验 FTXUI 的强大功能。"),
});
}
int main() {
auto screen = ScreenInteractive::TerminalOutput();
auto quit =
Button("退出", screen.ExitLoopClosure(), ButtonOption::Animated());
int selection_change_counter = 0;
std::string selection_content = "";
screen.SelectionChange([&] {
selection_change_counter++;
selection_content = screen.GetSelection();
});
// 组件:
auto renderer = Renderer(quit, [&] {
return vbox({
text("选择已更改:" + std::to_string(selection_change_counter) +
" 次"),
text("当前选中:"),
paragraph(selection_content) | vscroll_indicator | frame | border |
size(HEIGHT, EQUAL, 10),
window(text("水平分割"), hbox({
separator(),
separator(),
})),
window(text("垂直分割"), vbox({
separator(),
separator(),
})),
window(text("具有不同样式的网格分割"),
vbox({
hbox({
separator(),
| selectionBackgroundColor(Color::Yellow) //
| selectionColor(Color::Black) //
| selectionStyleReset,
separator(),
LoremIpsum() | selectionColor(Color::Blue),
}),
separator(),
hbox({
LoremIpsum() | selectionColor(Color::Red),
separator(),
LoremIpsum() | selectionStyle([](Pixel& pixel) {
pixel.underlined_double = true;
}),
separator(),
}),
})),
quit->Render(),
});
});
screen.Loop(renderer);
}
Element window(Element title, Element content, BorderStyle border)
绘制带有标题和边框的窗口。
bool underlined_double
一个 Unicode 字符及其相关样式。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element