60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
#include "Core/IoContext.h"
|
|
#include "Core/Singleton.h"
|
|
#include "NngClient.h"
|
|
#include <ftxui/component/component.hpp>
|
|
#include <ftxui/component/screen_interactive.hpp>
|
|
|
|
int main() {
|
|
using namespace Core;
|
|
auto ioContext = Singleton<IoContext>::construct(std::thread::hardware_concurrency());
|
|
auto nng = Singleton<NngClient>::construct(*ioContext->ioContext());
|
|
nng->start("127.0.0.1", 8000);
|
|
|
|
auto zeroCheckButton =
|
|
ftxui::Button("零点校正", [&]() { nng->requestZeroCheck(); }, ftxui::ButtonOption::Animated());
|
|
|
|
auto zoomButtons = ftxui::Container::Horizontal({
|
|
ftxui::Button(
|
|
"+", [&]() { nng->requestZoom(false); }, ftxui::ButtonOption::Animated()),
|
|
ftxui::Button(
|
|
"-", [&]() { nng->requestZoom(true); }, ftxui::ButtonOption::Animated()),
|
|
});
|
|
auto zoomItem = ftxui::Renderer(zoomButtons, [&]() {
|
|
return ftxui::hbox({
|
|
ftxui::text("zoom:") | ftxui::vcenter,
|
|
zoomButtons->Render(),
|
|
});
|
|
});
|
|
|
|
auto focusButtons = ftxui::Container::Horizontal({
|
|
ftxui::Button(
|
|
"+", [&]() { nng->requestFocus(true); }, ftxui::ButtonOption::Animated()),
|
|
ftxui::Button(
|
|
"-", [&]() { nng->requestFocus(false); }, ftxui::ButtonOption::Animated()),
|
|
});
|
|
auto focusItem = ftxui::Renderer(focusButtons, [&]() {
|
|
return ftxui::hbox({
|
|
ftxui::text("focus:") | ftxui::vcenter,
|
|
focusButtons->Render(),
|
|
});
|
|
});
|
|
|
|
auto controls = ftxui::Container::Vertical({
|
|
zeroCheckButton,
|
|
zoomItem,
|
|
focusItem,
|
|
});
|
|
|
|
// Modify the way to render them on screen:
|
|
auto component = ftxui::Renderer(controls, [&] {
|
|
return ftxui::vbox({
|
|
ftxui::text("Nng 控制端"),
|
|
controls->Render(),
|
|
});
|
|
});
|
|
|
|
ioContext->run(false);
|
|
auto screen = ftxui::ScreenInteractive::FitComponent();
|
|
screen.Loop(component);
|
|
return 0;
|
|
} |