mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Refactor directory structure.
The goal is to increase the separation in between: * ftxui::screen * ftxui::dom * ftxui::component
This commit is contained in:
@@ -2,26 +2,28 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
class DrawKey : public ftxui::component::Component {
|
||||
using namespace ftxui::component;
|
||||
|
||||
class DrawKey : public Component {
|
||||
public:
|
||||
DrawKey(ftxui::component::Delegate* delegate)
|
||||
: ftxui::component::Component(delegate) {}
|
||||
DrawKey(Delegate* delegate)
|
||||
: Component(delegate) {}
|
||||
|
||||
ftxui::dom::Element Render() override {
|
||||
using namespace ftxui::dom;
|
||||
Children children;
|
||||
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
|
||||
std::string code = "";
|
||||
for(size_t j = 0; j<5; ++j)
|
||||
std::string code = "";
|
||||
for (size_t j = 0; j < 5; ++j)
|
||||
code += " " + std::to_string(keys[i].values[j]);
|
||||
|
||||
try {
|
||||
std::string line = code + " -> " + std::to_string(keys[i].values[0]) + " (" +
|
||||
char(keys[i].values[0]) + ")";
|
||||
std::string line = code + " -> " + std::to_string(keys[i].values[0]) +
|
||||
" (" + char(keys[i].values[0]) + ")";
|
||||
children.push_back(text(to_wstring(line)));
|
||||
} catch (...) {
|
||||
std::string line =
|
||||
@@ -32,17 +34,17 @@ class DrawKey : public ftxui::component::Component {
|
||||
return vbox(std::move(children));
|
||||
}
|
||||
|
||||
bool OnEvent(ftxui::Event event) override {
|
||||
bool OnEvent(Event event) override {
|
||||
keys.push_back(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<ftxui::Event> keys;
|
||||
std::vector<Event> keys;
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
auto screen = ftxui::ScreenInteractive::FixedSize(80,10);
|
||||
auto screen = ScreenInteractive::FixedSize(80, 10);
|
||||
DrawKey draw_key(screen.delegate());
|
||||
screen.Loop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user