Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jeremie
Visitor

focus manager like tabIndex for you

Hi,
I give on the forum my script for manage tabindex, it's working well for me

function initTabIndex()
   m._tabIndex = []
end function

function addTabIndex(id,targets)
   m._tabIndex.push({id:id,targets:targets})
end function


function updateTabIndex(key)
   currentIndex = _getFocusIndex()
   currentItem = m._tabIndex[currentIndex]
   if(currentItem = invalid) then return false
   if(currentItem.targets.DoesExist(key)) then
       target = currentItem.targets.Lookup(key)
       m.top.findNode(target).setFocus(true)
       return true
   end if
  return false
end function

function _getFocusIndex()
   for i=0 to m._tabIndex.count()-1
       item = m._tabIndex[i]
       node = m.top.findNode(item.id)
       if(node.focusedChild <> invalid) then
           return i
       end if
   end for
   return invalid
end function


How to use ?
Import the script in your xml
<script type="text/brightscript" uri="pkg:/components/util/UIUtil.brs" />


In your init() you can do something like that : 
initTabIndex()
addTabIndex("keyboard",{down:"btnValidate"})
addTabIndex("btnValidate",{up:"keyboard",right:"btnShowPass"})
addTabIndex("btnShowPass",{left:"btnValidate",up:"keyboard",down:"btnOption"})
addTabIndex("btnOption",{left:"btnValidate",up:"btnShowPass"})


in your onKeyEvent :
function onKeyEvent(key as String, press as Boolean) as Boolean
   if press then return updateTabIndex(key)
end function


in this sample, when you have the focus on btnShowPass, when you press left, you swap the focus to btnValidate

Best regards,
Jeremie.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.