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

Scroll a Vertical Container #130

Closed
matthesoundman opened this issue Jun 26, 2021 · 3 comments
Closed

Scroll a Vertical Container #130

matthesoundman opened this issue Jun 26, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@matthesoundman
Copy link

I want to be able to scroll through a Vertical container during runtime. I have ideas to populate the container with messages and other various strings. With the strings being dynamically added during runtime I can't seem to figure out how to scroll the container's history after it has filled passed the screen height.

auto message_container {ftxui::Container::Vertical({})};
auto message_view_renderer {Renderer(layout, [&] {
  return vbox({
    text(L"Basic Message Viewer") | center,
      vbox({ message_container->Render() | yflex }) | border | flex
  });
})};

I would then have another process running in another thread adding new lines as they arrive.

message_container->Add(ftxui::Renderer([] {}));

Is it possible to scroll the contents of the container?

@ArthurSonzogni
Copy link
Owner

It is because ftxui::Renderer do not use focus or select when focused/selected.

You can add:

// A simple text highlighted when focused.
class Focusable : public ComponentBase {
 public:
  Focusable(const std::wstring& title) : title_(title) {}
  Element Render() final {
    if (Focused())
      return text(title_) | inverted | focus;
    else
      return text(title_);
  }

 private:
  std::wstring title_;
};

And then:

message_container->Add(Make<Focusable>(L"Text"))

It might worth it adding a builtin component like Focusable in the library.

@ArthurSonzogni
Copy link
Owner

BTW, at this point, you could simply use the builtin Menu()

@matthesoundman
Copy link
Author

Cool. Let me give Menu() a try. BTW really am liking this library.

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

No branches or pull requests

2 participants