Forum Discussion

jedashford's avatar
jedashford
Channel Surfer
10 years ago

How is focus handled with multiple components?

There must be a way to handle this since the keyboard widget has no 'ok', 'done', or 'continue' button. How would I handle focus when there are multiple components on the page?

For the below example, I give focus to the keyboard, but can never access the button group below it.




Here is the XML:

<LayoutGroup
id = "buttonLayoutGroup"
horizAlignment = "center"
vertAlignment = "center"
layoutDirection = "vert"
translation="[640,360]">
<Keyboard id = "exampleKeyboard" />
<ButtonGroup
id="buttonGroup"
translation="[200,500]" >
<Button
text="Change Email Address"
focusedTextColor="0xFFFFFF"
focusBitmapUri="pkg:/images/va_button.9.png"
iconUri="pkg:/images/empty_small.png"
focusedIconUri="pkg:/images/empty_small.png"
showFocusFootprint="true"
/>

<Button
text="Back"
focusedTextColor="0xFFFFFF"
focusBitmapUri="pkg:/images/va_button.9.png"
iconUri="pkg:/images/empty_small.png"
focusedIconUri="pkg:/images/empty_small.png"
showFocusFootprint="true"
/>
</ButtonGroup>
</LayoutGroup>

4 Replies

  • If a keypress isn't handled natively by the component, it'll be surfaced to the onKeyEvent function. In your example, you should get a "down" keypress if you press down on the bottom row of the keyboard, at which point you can change the focus to your button group. The same works in reverse when you press up when the top most button is highlighted.
  • This would work except for one point, the ButtonGroup is passign every keypress up the chain, so within the focus of the ButtonGroup the onKeyEvent is getting fired on every keypress. The keyboard widget handles key presses correctly (doesn't send up, but is contained in the component). Unfortunately, without some counters for button clicks and one off code, this wont work, unless someone has an idea for how to suppress key events while navigating a ButtonGroup, but still fire on an up/down while on the first/last buttons.
  • "jedashford" wrote:
    This would work except for one point, the ButtonGroup is passign every keypress up the chain, so within the focus of the ButtonGroup the onKeyEvent is getting fired on every keypress. The keyboard widget handles key presses correctly (doesn't send up, but is contained in the component). Unfortunately, without some counters for button clicks and one off code, this wont work, unless someone has an idea for how to suppress key events while navigating a ButtonGroup, but still fire on an up/down while on the first/last buttons.

    Can you not check the buttonFocused index, and if it's 0 and the key is "up" then change focus?
  • Actually, found that if I check for 'press' on the onKeyEvent then it returns false while navigating around inside the component. I'm hoping this isn't changed in a future revision of the API:

    function onKeyEvent(key as String, press as Boolean) as Boolean
    if press then 'returns false during navigation inside of ButtonGroup'