FTXUI/examples/component/button.cpp

41 lines
1.3 KiB
C++
Raw Normal View History

2021-07-10 19:20:43 +08:00
#include <memory> // for shared_ptr, __shared_ptr_access
2022-03-14 01:51:46 +08:00
#include <string> // for operator+, to_string
2020-08-26 22:26:09 +08:00
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
2021-05-02 02:40:35 +08:00
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
2022-03-14 01:51:46 +08:00
#include "ftxui/dom/elements.hpp" // for separator, gauge, text, Element, operator|, vbox, border
2020-08-26 22:26:09 +08:00
using namespace ftxui;
int main() {
2021-05-13 17:44:47 +08:00
int value = 50;
2020-08-26 22:26:09 +08:00
2021-05-13 17:44:47 +08:00
// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
2022-03-14 01:51:46 +08:00
Button("Decrease", [&] { value--; }),
Button("Increase", [&] { value++; }),
2021-05-13 17:44:47 +08:00
});
2020-08-26 22:26:09 +08:00
2021-05-13 17:44:47 +08:00
// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
2021-05-10 02:32:27 +08:00
return vbox({
text("value = " + std::to_string(value)),
2021-05-10 02:32:27 +08:00
separator(),
2021-05-13 17:44:47 +08:00
gauge(value * 0.01f),
2021-05-10 02:32:27 +08:00
separator(),
2021-05-13 17:44:47 +08:00
buttons->Render(),
2021-05-10 02:32:27 +08:00
}) |
border;
2021-05-13 17:44:47 +08:00
});
2020-08-26 22:26:09 +08:00
2021-05-10 02:32:27 +08:00
auto screen = ScreenInteractive::FitComponent();
2021-05-13 17:44:47 +08:00
screen.Loop(component);
2020-08-26 22:26:09 +08:00
return 0;
}
2020-09-06 19:46:56 +08:00
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.