mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-20 10:38:09 +08:00
Implement a lot of new features.
This commit deserve to be cut into at least 8 sub commit. Sorry, I acknowledge this is bad... Here are the new features: * dom decorator: bold, dim, underlined, inverted. * component mechanism * components * menu * toogle
This commit is contained in:
4
examples/print_key_press/CMakeLists.txt
Normal file
4
examples/print_key_press/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
add_executable(print_key_press
|
||||
main.cpp
|
||||
)
|
||||
target_link_libraries(print_key_press PRIVATE ftxui)
|
44
examples/print_key_press/main.cpp
Normal file
44
examples/print_key_press/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "ftxui/screen_interactive.hpp"
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/util/string.hpp"
|
||||
|
||||
class DrawKey : public ftxui::component::Component {
|
||||
public:
|
||||
DrawKey(ftxui::component::Delegate* delegate)
|
||||
: ftxui::component::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) {
|
||||
try {
|
||||
std::string line = std::to_string(i) + " -> " + std::to_string(keys[i]) +
|
||||
" (" + char(keys[i]) + ")";
|
||||
children.push_back(text(to_wstring(line)));
|
||||
} catch (...) {
|
||||
std::string line = std::to_string(i) + " -> " + std::to_string(keys[i]) +
|
||||
" (undefined)";
|
||||
children.push_back(text(to_wstring(line)));
|
||||
}
|
||||
}
|
||||
return vbox(std::move(children));
|
||||
}
|
||||
|
||||
bool Event(int key) override {
|
||||
keys.push_back(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<int> keys;
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
ftxui::ScreenInteractive screen(80,10);
|
||||
DrawKey draw_key(screen.delegate());
|
||||
screen.Loop();
|
||||
}
|
Reference in New Issue
Block a user