FTXUI/examples/component/button.cpp

41 lines
1.3 KiB
C++
Raw Normal View History

#include <memory> // for __shared_ptr_access, shared_ptr
#include <string> // for operator+, to_wstring
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
#include "ftxui/dom/elements.hpp" // for separator, Element, gauge, text, operator|, vbox, border
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;
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("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({
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.