FTXUI/examples/component/button.cpp

47 lines
1.4 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/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Button, Make
#include "ftxui/component/component_base.hpp" // for ComponentBase
2021-05-02 02:40:35 +08:00
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
2021-05-10 02:32:27 +08:00
#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-10 02:32:27 +08:00
class MyComponent : public ComponentBase {
2020-08-26 22:26:09 +08:00
private:
2021-05-10 02:32:27 +08:00
std::wstring label_add = L"Increase";
std::wstring label_rm = L"Decrease";
int value_ = 50;
2020-08-26 22:26:09 +08:00
public:
MyComponent() {
2021-05-10 02:32:27 +08:00
Add(Container::Horizontal({
Button(&label_rm, [&] { value_--; }),
Button(&label_add, [&] { value_++; }),
}));
}
2020-08-26 22:26:09 +08:00
2021-05-10 02:32:27 +08:00
Element Render() override {
return vbox({
text(L"Value = " + std::to_wstring(value_)),
separator(),
gauge(value_ * 0.01f),
separator(),
ComponentBase::Render(),
}) |
border;
2020-08-26 22:26:09 +08:00
}
};
int main(int argc, const char* argv[]) {
2021-05-10 02:32:27 +08:00
auto screen = ScreenInteractive::FitComponent();
screen.Loop(Make<MyComponent>());
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.