Wednesday, August 14, 2013

Widgets come and go.

Hmm ... allow me to use one post as a documentation-to-self for a feature of the GuiEngine that I haven't used a lot, yet: the ability to dynamically control widgets showing up on screen.

  • one static widgets list per window
  • nbWidgets may tune how far you can go in that list
  • wstart indicates where you start reading from.
  • add(x,y,Widget) populate the list, normally in the Window's CTOR.
  • setmark() inserts a terminator in the list.
  • setmark(HOP_TO_ZERO) inserts a "goto" item that forces the list to be read from the start. This is allowed only when wstart>nbWidgets, which implies that you must reset nbWidget to the position returned by the earlier setmark(). I'm not happy with this constraint.
When one wants a (set of) widget(s) to be optional, the prefered approach is to place it after a terminator and followed by a HOP_TO_ZERO to further process the "permanent" widgets. That also gives those "tabbed/pop-up" widget precedence over permanent widgets.


if (wstart==nbox) {
    wstart=0; box->hide();
    ge.release();
} else {
    wstart=nbox; box->render();
    ge.focus(box);
}
Note that visibility of the 'pop-up' widget needs to be manually adjusted with render()/hide() and that we need to force the Gui Engine to lose widget focus to make it work. In setup, the current location of the optional widget (here box) needs to be captured (in nbox):

add(64,0,(box=new BoxWidget(...))->attach(...));
setmark(HOP_TO_ZERO);
nbox=nbWidgets--;
If you want the 'pop-up widget' to be hidden when you'll enter that window again, you'll have to complete your Window::release() method with a conditional test:


if (wstart==nbox) {
      box->hide();
      wstart=0; 
}

No comments: