FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
menu2.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. 全著作権所有。
2// このソースコードの使用は、MITライセンスに従います。
3// LICENSEファイルで確認できます。
4#include <functional> // 関数用
5#include <memory> // アロケーター、__shared_ptr_access用
6#include <string> // string、basic_string、operator+、to_string用
7#include <vector> // vector用
8
9#include "ftxui/component/captured_mouse.hpp" // ftxui用
10#include "ftxui/component/component.hpp" // Menu、Horizontal、Renderer用
11#include "ftxui/component/component_base.hpp" // ComponentBase用
12#include "ftxui/component/component_options.hpp" // MenuOption用
13#include "ftxui/component/screen_interactive.hpp" // Component、ScreenInteractive用
14#include "ftxui/dom/elements.hpp" // text、separator、bold、hcenter、vbox、hbox、gauge、Element、operator|、border用
15
16int main() {
17 using namespace ftxui;
18 auto screen = ScreenInteractive::TerminalOutput();
19
20 std::vector<std::string> left_menu_entries = {
21 "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%",
22 };
23 std::vector<std::string> right_menu_entries = {
24 "0%", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%", "10%",
25 };
26
27 auto menu_option = MenuOption();
28 menu_option.on_enter = screen.ExitLoopClosure();
29
30 int left_menu_selected = 0;
31 int right_menu_selected = 0;
32 Component left_menu_ =
33 Menu(&left_menu_entries, &left_menu_selected, menu_option);
34 Component right_menu_ =
35 Menu(&right_menu_entries, &right_menu_selected, menu_option);
36
37 Component container = Container::Horizontal({
38 left_menu_,
39 right_menu_,
40 });
41
42 auto renderer = Renderer(container, [&] {
43 int sum = left_menu_selected * 10 + right_menu_selected;
44 return vbox({
45 // -------- 上部パネル --------------
46 hbox({
47 // -------- 左メニュー --------------
48 vbox({
49 hcenter(bold(text("Percentage by 10%"))),
50 separator(),
51 left_menu_->Render(),
52 }),
53 separator(),
54 // -------- 右メニュー --------------
55 vbox({
56 hcenter(bold(text("Percentage by 1%"))),
57 separator(),
58 right_menu_->Render(),
59 }),
60 separator(),
61 }),
62 separator(),
63 // -------- 下部パネル --------------
64 vbox({
65 hbox({
66 text(" gauge : "),
67 gauge(sum / 100.0),
68 }),
69 hbox({
70 text(" text : "),
71 text(std::to_string(sum) + " %"),
72 }),
73 }),
74 }) |
75 border;
76 });
77
78 screen.Loop(renderer);
79}
Menuコンポーネントのオプション。
int main()
Definition menu2.cpp:16
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< ComponentBase > Component