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. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <functional> // for function
5#include <memory> // for allocator, __shared_ptr_access
6#include <string> // for string, basic_string, operator+, to_string
7#include <vector> // for vector
8
9#include "ftxui/component/captured_mouse.hpp" // for ftxui
10#include "ftxui/component/component.hpp" // for Menu, Horizontal, Renderer
11#include "ftxui/component/component_base.hpp" // for ComponentBase
12#include "ftxui/component/component_options.hpp" // for MenuOption
13#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
14#include "ftxui/dom/elements.hpp" // for text, separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border
15
16 int 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 // -------- Top panel --------------
46 hbox({
47 // -------- Left Menu --------------
48 vbox({
49 hcenter(bold(text("Percentage by 10%"))),
50 separator(),
51 left_menu_->Render(),
52 }),
53 separator(),
54 // -------- Right Menu --------------
55 vbox({
56 hcenter(bold(text("Percentage by 1%"))),
57 separator(),
58 right_menu_->Render(),
59 }),
60 separator(),
61 }),
62 separator(),
63 // -------- Bottom panel --------------
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}
captured_mouse.hpp
component.hpp
component_base.hpp
component_options.hpp
elements.hpp
ftxui::MenuOption
Option for the Menu component.
Definition component_options.hpp:86
main
int main()
Definition menu2.cpp:16
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
screen_interactive.hpp