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

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

Open
dty2 opened this issue Apr 3, 2024 · 5 comments

Comments

@dty2
Copy link

dty2 commented Apr 3, 2024

first of all for

@dty2 dty2 changed the title return container in function as the value pass to renderer that render default 失败 38/5000 container is passed to renderer as a lambda return value, causing rendering to fail Apr 3, 2024
@dty2 dty2 changed the title 失败 38/5000 container is passed to renderer as a lambda return value, causing rendering to fail container is passed to renderer as a lambda return value, causing rendering to fail Apr 3, 2024
@ArthurSonzogni
Copy link
Owner

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

@dty2
Copy link
Author

dty2 commented Apr 3, 2024

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
Copy link
Author

dty2 commented Apr 3, 2024

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
Copy link
Owner

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
Copy link
Author

dty2 commented Apr 4, 2024

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;-)

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