Skip to content

Scroll lots of lines in a performant way #304

Discussion options

You must be logged in to vote

Hi @matthesoundman

Yes, you can reimplement the menu yourself and draw only a shorter range?

Here, I am rewriting the Render() method from the normal Menu.

For instance:

int selected_line = 0;
std::vector<std::string> lines;
auto menu = Menu(&selected_line, &lines);

auto my_custom_menu = Renderer(menu, [&] {
  int begin = std::max(0, selected_lines - 10);
  int end = std::min(lines.size(), selected_lines + 10)
  Elements elements;
  for(int i = begin; i<end; ++i) {
    Element element = text(lines[i]);
    if (i == selected_line)
      element = element | inverted | selected;
    element.push_back(element);
  }
  return vbox(std::move(elements)) | vscroll_indicator | frame | border;
});

Y…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@matthesoundman
Comment options

@matthesoundman
Comment options

@ArthurSonzogni
Comment options

@matthesoundman
Comment options

Answer selected by ArthurSonzogni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants