How to manage focus for a small set of simple widgets

Posted by Christoph on Programmers See other posts from Programmers or by Christoph
Published on 2014-02-20T00:01:50Z Indexed on 2014/06/04 21:41 UTC
Read the original article Hit count: 320

Filed under:
|
|

I'm developing a set of simple widgets for a small (128x128) display.

For example I'd like to have a main screen with an overlay menu which I can use to toggle visibilty of main screen elements. Each option would be an icon with a box around it while it is selected. Button (left, up, right, down, enter) events should be given to the widget that has "focus".

Focus is a simple thing to understand when using a GUI, but I'm having trouble implementing this. Can you suggest a simple concept for managing focus and input events? I have these simple ideas:

  • Only one widget can have focus, so I need a single pointer to that widget.
  • When this widget gets some kind of "cycle" input (as in "highlight the next item in this list"), the focus is given to a different widget.
  • a widget must have a way of telling the application which widget the focus is given to next.
  • if a widget cannot give a "next focus" hint, the application must be able to figure out where the focus should go.

Widgets are currently structured like this:

  • A widget can have a parent, which is passed to the constructor. Widgets are created statically, as I want to avoid dynamic memory allocation (I only have 16kB of RAM and I'd like to have control over that).
  • widgets have siblings, implemented as an intrusive linked list (they have a next member). A parent has a pointer to the head of its list of children.

Input events are arguments to the widgets buttonEvent methods which can accept or ignore that event. If it ignores the event, it can pass the event to its parent.

My Questions:

  1. How can I manage focus for these widgets?
  2. Am I making this too complicated?

© Programmers or respective owner

Related posts about c++

Related posts about gui