linux4sam / egt

Ensemble Graphics Toolkit - Modern C++ GUI Toolkit for AT91/SAMA5 Microprocessors
https://ensemble.graphics
Apache License 2.0
63 stars 25 forks source link

Possibly app.event().step() triggered with window.show() #28

Closed SaschaKoch closed 7 months ago

SaschaKoch commented 9 months ago

Hi,

I have recently changed from EGT 1.7 to EGT 1.8 and observed a different behavior during startup of my program. The program consists of several windows and loads of different Widgets and Images on them which makes the loading of the program rather slow (roughly 2-3s). To avoid having a 2-3s black screen on my target device after Linux finished booting and before the program started up properly and reached the app.run() at the very end of my main() function we introduced a "loading" screen: at the beginning of the main() function a TopWindow is created, a text label-Widget is added "..." and then the whole thing is displayed with app.event().step(). (The TextBox Widget is only there to fix a bug which leads to the event().step() sometimes not working and sometimes working. With that TextBox things seem to work fine)

int main(int argc, const char ** argv)
{
  Application app;

  TopWindow mainWin;
  mainWin.name("Topwindow");
  mainWin.show();

  auto text_patch = std::make_shared<TextBox>("e");
  text_patch->hide();
  mainWin.add(text_patch);

  auto main_loading_lbl = std::make_shared<Label>("...",
      Rect(0, 0, screen_size_x, screen_size_y), AlignFlag::center);
  main_loading_lbl->font(
      Font("Montserrat SemiBold", 92, Font::Weight::normal));
  main_loading_lbl->color(Palette::ColorId::label_text,
      Color(0xae0f21ff));

  mainWin.add(main_loading_lbl);
  main_loading_lbl->show();
  app.event().step();

...

//Loads of code

...
  main_loading_lbl->hide();
  return app.run();
}

In that way the user sees the loading screen after Linux finished booting (white screen with the "..." in red color in the middle) and is not presented with an awkward black screen for a couple of seconds. The app.event().step() leads to everything being created and displayed up to this point. the app.run() at the end has a similar effect but keeps the whole program indefinitely going (until the user or something ends it).

In EGT 1.7 this worked fine, in EGT1.8 this works as well but I encountered that the snippet

TopWindow window;
mainWin.add(window)
...
// Widgets added to window
...
window.show()  

which is placed in the above code somewhere in the //Loads of code section seem to have a similar effect than app.event().step() leading to a display update half way through the first run of my main() where only half the stuff is done yet. Only after some time when the program reaches the final return app.run() is the display updated again and everything is created as it should be. However now the user is again left with an even more awkward half build screen due to my window.show(). I hot fixed it by putting the window.show at the very end just before the return app.run() but it seems like just a hot fix. For example some code parts are not finished executing leading to a change in an image which is actually coded before the window.show()

Is this change in behavior intended or a bug?

Thanks already Sascha

ldesroches commented 9 months ago

Hi,

Instead of using app.event().step(), you should use app.event().draw() which is what you really want to do. Moreover, it's prevents the workaround of the TextBox. The TextBox, because of it's cursor, triggers an event that causes step() to call draw().

Concerning the issue related to the call to show(), that is not a bug. There is a patch that changes the behavior of the show and hide methods for overlays. Showing or hiding them is now done instantly. So either you take care when the show method is called or you set the window hint to software in order to wait for an event to draw it.

Regards, Ludovic