ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.76k stars 406 forks source link

container is passed to renderer as a lambda return value, causing rendering to fail #837

Open dty2 opened 5 months ago

dty2 commented 5 months ago

first of all for

ArthurSonzogni commented 5 months ago

Hello, I do not understand you. Could you please try again?

dty2 commented 5 months ago

I did have some questions to ask, but I made a mistake and published them without editing them. Then something happened, and I went to a meeting, and I didn't continue to edit. I am not a native English speaker, I want to express my sincerest apologies, but I can't speak English, I can only use translation software to translate, and I am a college student, not very good at technology, so the following questions, perhaps in your opinion will be relatively simple. Finally, I sincerely apologize. Next, I get to the point. There is a question with a urge to ask. The prompt is related to the display of ASCLL art characters. This has to do with issue#336. You said you were going to enhance paragraph, but I don't seem to have found that paragraph resolves the line break "\n". But fortunately, I found that you gave a more suitable solution. I adopted it, and it worked fine. But I hope you can improve the functionality of paragraph. As for the problem, it is as follows. here is my codes, there are two version, and version 1 can work successful, version 2 not.

// version1
void Module::start()
{
  auto screen = ScreenInteractive::Fullscreen();

  // Start
  Option selected = Log;
  auto menu = Container::Horizontal({
    Button("Log",[&]{ selected = Log; },ButtonOption::Ascii()),
    Button("Sign",[&]{ selected = Sign; },ButtonOption::Ascii()),
    Button("Help",[&]{ selected = Help; },ButtonOption::Ascii()),
    Button("Exit",[&]{ selected = Exit; },ButtonOption::Ascii()),
  });

  //auto start_container = vbox({
  //    hcenter(nonWrappingParagraph(LOGO)),
  //    hcenter(menu->Render()) | bold
  //  }) | center | border | color(Color::Blue);

  auto start_render = Renderer(menu, [&](){
//    return start_container;
    return vbox({
      hcenter(nonWrappingParagraph(LOGO)),
      hcenter(menu->Render()) | bold
    }) | center | border | color(Color::Blue);
  });
// version 2
void Module::start()
{
  auto screen = ScreenInteractive::Fullscreen();

  // Start
  Option selected = Log;
  auto menu = Container::Horizontal({
    Button("Log",[&]{ selected = Log; },ButtonOption::Ascii()),
    Button("Sign",[&]{ selected = Sign; },ButtonOption::Ascii()),
    Button("Help",[&]{ selected = Help; },ButtonOption::Ascii()),
    Button("Exit",[&]{ selected = Exit; },ButtonOption::Ascii()),
  });

  auto start_container = vbox({
      hcenter(nonWrappingParagraph(LOGO)),
      hcenter(menu->Render()) | bold
    }) | center | border | color(Color::Blue);

  auto start_render = Renderer(menu, [&](){
    return start_container;
    //return vbox({
    //  hcenter(nonWrappingParagraph(LOGO)),
    //  hcenter(menu->Render()) | bold
    //}) | center | border | color(Color::Blue);
  });

you can see that , I just use a auto start_render to receive vbox() . in lambda, it works, in outside it doesn't . the result of version 2, it can't choose the button by key h or l. but in version 1,it can choose the button by key h or l(that was what I want to get) so what happened ? why version 2 can't work ? I had read some source code , due to I'm a rookie.I can't get any useful things for me .

In my country, it is very late now, so I need to go to bed, but in your country, it should be daytime now, so I may reply you after several hours, please forgive me, thank you

dty2 commented 5 months ago

well, by the way, the ftxui is so awesome! so I want to use it to develop a communication software , and use the operation like vi/vim(I like vim too, and I use arch), and I want to know that ,Is it really popular? if I done, Will full keyboard streamers like it?

ArthurSonzogni commented 5 months ago

Thanks!

I am not a native English speaker, I want to express my sincerest apologies, but I can't speak English.

Don't worry. Me too ;-)


So what happened ? why version 2 can't work ?

In v2, the same element is reused to draw multiple frames. Even if it might work, this is not supported. You should create a new one for every frames.

dty2 commented 5 months ago

Oh, I see what you mean. That said, it was possible for my version 1 to write vbox in lambda because lambda returns a different value each time it is rendered. Thus, it will show different effects, which is why it is necessary to write vbox in lambda. If it is not written in lambda, then no matter how many times it is rendered, the return value will not change, and it is always the outside start_container, so if it is written outside, it is theoretically OK, but it will cause the interface to render the same content many times, and it looks like there is no change. 非常感谢您的回复与耐心,Merci pour votre;-)