Wednesday, July 13, 2011

Keep It In Focus

I rewrote the focus behavior in LWUIT yet again, this is the fifth time so far and I am weary of doing it yet again. We all have these "don't want to touch that" areas of the code, which we avoid like the plague and in LWUIT it was always the focus handling so I gritted my teeth and decided: it can break my compatibility but it will never take the freedom of the code.

I maybe a bit melodramatic here but focus was a nightmare in LWUIT, the main issue is the complex edge cases where a component becomes unreachable via focus. Normally we would say: just call setNextFocusLeft/Right/Up/Down.
However this doesn't work for the HTML component and worse, its not always obvious.
E.g. a specific device with a specific font size/DPI ratio might have a layout that looks different enough for focus to fail on that device and not on another (this actually happened in some of the previous focus implementations).

Eventually after so many focus failures I broke down and wrote the focus vector code where I guarantee every component will receive focus.

So what made me regret that?
The focus is really unintuitive for standard applications and even for HTMLComponent, it jumps around (to satisfy the requirement of visiting everything) and generally doesn't make much sense. However, the thing that triggered a complete rewrite was a benchmark which we failed (more on that in a future post).

Anyway what does this means to you?
You need to test your code with the new LWUIT and make sure your components are reachable, if not you need to use the component methods of setNextFocusUp/Down/Left/Right to define the focus order as you need it.

No comments:

Post a Comment