FTXUI/examples/component/button.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

2021-05-10 02:32:27 +08:00
#include <string> // for operator+, to_wstring, allocator, wstring
2020-08-26 22:26:09 +08:00
2021-05-10 02:32:27 +08:00
#include "ftxui/component/component.hpp" // for Button, Make
2021-05-02 02:40:35 +08:00
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
2020-08-26 22:26:09 +08:00
using namespace ftxui;
2021-05-13 17:44:47 +08:00
int main(int argc, const char* argv[]) {
int value = 50;
std::wstring label_dec = L"decrease";
std::wstring label_inc = L"increase";
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({
Button(&label_dec, [&] { value--; }),
Button(&label_inc, [&] { value++; }),
});
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({
2021-05-13 17:44:47 +08:00
text(L"value = " + std::to_wstring(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.