Add support for nxxm.

[nxxm](https://nxxm.github.io)
This commit is contained in:
ArthurSonzogni
2019-02-02 01:59:48 +01:00
parent 2eddd0fa17
commit ef0de8d873
72 changed files with 309 additions and 165 deletions

View File

@@ -0,0 +1,42 @@
#include "ftxui/component/toggle.hpp"
namespace ftxui {
Element Toggle::Render() {
bool is_focused = Focused();
Elements children;
for(size_t i = 0; i<entries.size(); ++i) {
// Separator.
if (i != 0)
children.push_back(separator());
// Entry.
auto style = (selected != int(i))
? normal_style
: is_focused ? focused_style : selected_style;
auto focused = (selected != int(i)) ? nothing : is_focused ? focus : select;
children.push_back(text(entries[i]) | style | focused);
}
return hbox(std::move(children));
}
bool Toggle::OnEvent(Event event) {
if (selected > 0 &&
(event == Event::ArrowLeft || event == Event::Character('h'))) {
selected--;
on_change();
return true;
}
if (selected < int(entries.size()) - 1 &&
(event == Event::ArrowRight || event == Event::Character('l'))) {
selected++;
on_change();
return true;
}
return false;
}
} // namespace ftxui