Question: Menu of Input? #249
-
I need to have an undefined number of input bars in my interface. It also would be nice if there was a scroll ability for that. There is a similar thing when you make a Menu:
It has almost everything, even a scroll ability, except input ability.
How can I achieve it? |
Beta Was this translation helpful? Give feedback.
Answered by
ArthurSonzogni
Nov 1, 2021
Replies: 1 comment 1 reply
-
On this example: #include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/elements.hpp"
#include "ftxui/component/component.hpp"
int main(int argc, const char* argv[]) {
using namespace ftxui;
Component input_list = Container::Vertical({});
std::vector<std::string> items(100, "");
for (int i = 0; i < items.size(); ++i) {
input_list->Add(Input(&(items[i]), "placeholder " + std::to_string(i)));
}
auto renderer = Renderer(input_list, [&] {
return input_list->Render() | vscroll_indicator | frame | border |
size(HEIGHT, LESS_THAN, 10);
});
auto screen = ScreenInteractive::TerminalOutput();
screen.Loop(renderer);
}
and by patching FTXUI using: diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp
index c78bf60..c6afe8e 100644
--- a/src/ftxui/component/input.cpp
+++ b/src/ftxui/component/input.cpp
@@ -156,10 +156,9 @@ class WideInputBase : public ComponentBase {
if (!box_.Contain(event.mouse().x, event.mouse().y))
return false;
- TakeFocus();
-
if (event.mouse().button == Mouse::Left &&
event.mouse().motion == Mouse::Pressed) {
+ TakeFocus();
int new_cursor_position =
cursor_position() + event.mouse().x - cursor_box_.x_min;
new_cursor_position =
@@ -168,8 +167,9 @@ class WideInputBase : public ComponentBase {
cursor_position() = new_cursor_position;
option_->on_change();
}
+ return true;
}
- return true;
+ return false;
}
bool Focusable() const final { return true; } test-2021-11-02_00.07.45.mp4I can get this behavior:I need to take a closer look during this week and update FTXUI accordingly. Thanks for opening this! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
TheBjoel2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On this example: