Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an input window, and outputting entered text after hitting enter or special key. #862

Closed
dr-mrsthemonarch opened this issue May 12, 2024 · 3 comments

Comments

@dr-mrsthemonarch
Copy link

Hello!
I'm a weekish old new user of FTXUI, which is simply amazing, All of your examples are pretty helpful to understand the library. and I'm really excited to use this for many of my future projects. But I'm seriously having problems achieving a simple task of adding a command line window/input to the program, to explain:

I'm trying to design a server to do testing with devices over a network. It will have 3 main windows, one with some buttons for commands, one for input, to send a more advanced command to, that may require too many clicks or menus, what-have-you, and an output window that will display what the server is doing at a timed interval, who may have connected to it, and some response to the sent command within the input window.

Through your examples i'm slowly hacking it all together, but I can't seem to get the syntax correct for how I catch an event like '\n' take that input typed, clear the input window, and have the output window react to it, or in my trivial testing case, simply paste the text entered, unfortunately, I can't find a single example, that does this, except for a mix between pressed_key and input, but they render live the event/text captured.

I'm also unsure how to really implement things like .on_enter, .push_back, which I feel are probably the methods I'm missing to complete the code. How would I go about doing this? Below is a snippet of what I'm doing wrong, I can post the full code if needed.

Thank you for the time and help if you can!

    auto textarea_1 = Input(&content_1);
    
    textarea_1 |= CatchEvent([&](Event event) {
        if (event == Event::Character('\n')) {
            //can't figure out what to do here
            return true;
        }
        return false;
    });
 
    auto create_right_window_elements = [&] {
      Elements elements;
      for (const auto& line : content_1) {
        elements.push_back(text(std::to_string(line)));
      }
      return elements;
    };
    
    auto right = Renderer([&] { return text(content_1); }); // Here this clearly just renders what is typed
@ArthurSonzogni
Copy link
Owner

Hello

I am not entirely sure I understood every questions. Feel free to ask more, or share the full code.

About catching the return key

I recently added:

/// @brief Return a string representation of the event.
std::string Event::DebugString() const;

This shows you have to use the key Event::Return instead of Event::Character('\n').

About creating a modal window

You can check the demo code
documentation

@dr-mrsthemonarch
Copy link
Author

I've managed to solve this problem with a push_back().

    input_option.on_enter = [&] {
        input_entries.push_back(input_add_content);
        input_add_content = "";
    };
image

@dr-mrsthemonarch
Copy link
Author

thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants