Logs component #400
-
Hello. I'm tempted to use FTXUI for a small program. My program receives messages over the network. I want to display them in a scrollable window. I can't figure out how to do this with FTXUI. Do you have any thoughts on this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
There are many ways. std::vector<std::string> log; You can display them inside the int log_index = 0;
auto log_menu = Menu(&log, &log_index) To make the menu displayed inside a scrollable area, you can use the element decorator: auto log_menu_decorated = log_menu | vscroll_indicator | frame; Alternativelyauto log_menu_decorated = Renderer(log_menu, [log_menu] {
return log_menu->Render() | vscroll_indicator | frame;
}); That's it. One final thing to note. When calling For instance you can post from a thread: screen_interactive.PostEvent(Event::Custom); this will force a new frame to be drawn. If the thread waiting for network and the one running FTXUI aren't the same, you can also use ScreenInteractive::Post to post task from one thread to the other: void AddLogFromNetworkThread(std::string line) {
// Currently on the "network" thread.
screen_.PostTask([line]() {
// Currently on the "UI" thread.
log.push_back(line);
screen_.PostEvent(Event::Custom); // Cause a new frame to be drawn.
});
} |
Beta Was this translation helpful? Give feedback.
There are many ways.
Let's say you are going to store the data into:
You can display them inside the
Menu
component:To make the menu displayed inside a scrollable area, you can use the element decorator:
frame
. You can also add a scroll indicator using:vscroll_indicator
decorator:auto log_menu_decorated = log_menu | vscroll_indicator | frame;
Alternatively
That's it.
If you don't want to use
Menu
, you should be able to build any kind of component rendering the log the way you want…