Skip to content

Commit

Permalink
keep focus on alphamenu while it's active + voice searches of 1 lette…
Browse files Browse the repository at this point in the history
…r will move the alphamenu focus to the corresponding letter
  • Loading branch information
cewert committed Nov 28, 2023
1 parent 33fe6bb commit f0a814b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/ItemGrid/Alpha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Poster id="alphaMic" height="22" width="15" uri="pkg:/images/icons/mic_icon.png" translation="[60, 150]" visible="false" />
<LabelList
id="alphaMenu"
translation="[52, 186]"
translation="[52, 206]"
vertFocusAnimationStyle="floatingFocus"
font="font:SmallestSystemFont"
focusedFont="font:SmallestSystemFont"
Expand Down
34 changes: 26 additions & 8 deletions components/ItemGrid/ItemGrid.bs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sub init()
m.spinner.visible = true

m.alpha = m.top.findNode("alpha")
m.alphaSelected = m.top.findNode("alphaSelected")
m.alphaMenu = m.alpha.findNode("alphaMenu")

'Get reset folder setting
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]
Expand Down Expand Up @@ -455,7 +455,6 @@ end sub
'
'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
m.top.alphaActive = false
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []
Expand Down Expand Up @@ -489,10 +488,13 @@ sub ItemDataLoaded(msg)
end for

' keep focus on alpha menu when loading new data
if not m.alpha.isinFocusChain()
if m.top.alphaActive
m.alphaMenu.setFocus(true)
else
m.itemGrid.opacity = "1"
m.genreList.opacity = "0"

m.alphaMenu.setFocus(false)
m.itemGrid.setFocus(true)
m.genreList.setFocus(false)
end if
Expand Down Expand Up @@ -619,6 +621,24 @@ sub onvoiceFilter()
m.loadItemsTask.searchTerm = m.voiceBox.text
m.loadItemsTask.recursive = true
m.spinner.visible = true
if m.voiceBox.text.len() = 1
' move focus to the letter spoken
alphaMenu = m.top.findNode("alphaMenu")
intConversion = m.voiceBox.text.ToInt() ' non numeric input returns as 0

if m.voiceBox.text = "0" or (isValid(intConversion) and intConversion <> 0)
alphaMenu.jumpToItem = 0
else
' loop through each option until we find a match
for i = 1 to alphaMenu.numRows - 1
alphaMenuOption = alphaMenu.content.getChild(i)
if Lcase(alphaMenuOption.TITLE) = Lcase(m.voiceBox.text)
alphaMenu.jumpToItem = i
exit for
end if
end for
end if
end if
loadInitialItems()
end if
end sub
Expand Down Expand Up @@ -761,7 +781,7 @@ function getItemFocused()
return m.itemGrid.content.getChild(m.itemGrid.itemFocused)
else if m.genreList.isinFocusChain() and isValid(m.genreList.rowItemFocused)
return m.genreList.content.getChild(m.genreList.rowItemFocused[0]).getChild(m.genreList.rowItemFocused[1])
else if m.scheduleGrid.isinFocusChain() and isValid(m.scheduleGrid.itemFocused)
else if isValid(m.scheduleGrid) and m.scheduleGrid.isinFocusChain() and isValid(m.scheduleGrid.itemFocused)
return m.scheduleGrid.content.getChild(m.scheduleGrid.itemFocused)
end if
return invalid
Expand Down Expand Up @@ -835,13 +855,11 @@ function onKeyEvent(key as string, press as boolean) as boolean
else if key = "left" and topGrp.isinFocusChain()
m.top.alphaActive = true
topGrp.setFocus(false)
alpha = m.alpha.getChild(0).findNode("alphaMenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true

else if key = "right" and m.alpha.isinFocusChain()
m.top.alphaActive = false
m.alpha.setFocus(false)
m.alphaMenu.setFocus(false)
topGrp.setFocus(true)
return true
else if key = "replay" and topGrp.isinFocusChain()
Expand Down
38 changes: 29 additions & 9 deletions components/ItemGrid/MovieLibraryView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub setupNodes()
m.swapAnimation = m.top.findNode("backroundSwapAnimation")
m.spinner = m.top.findNode("spinner")
m.alpha = m.top.findNode("alpha")
m.alphaSelected = m.top.findNode("alphaSelected")
m.alphaMenu = m.alpha.findNode("alphaMenu")
m.communityRatingGroup = m.top.findNode("communityRatingGroup")
m.criticRatingIcon = m.top.findNode("criticRatingIcon")
m.criticRatingGroup = m.top.findNode("criticRatingGroup")
Expand Down Expand Up @@ -407,7 +407,6 @@ end sub
'
'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
m.top.alphaActive = false
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []
Expand Down Expand Up @@ -440,11 +439,14 @@ sub ItemDataLoaded(msg)
return
end if

' keep focus on alpha menu when loading new data
if not m.alpha.isinFocusChain()
' keep focus on alpha menu if it's active
if m.top.alphaActive
m.alphaMenu.setFocus(true)
else
m.itemGrid.opacity = "1"
m.genreList.opacity = "0"

m.alphaMenu.setFocus(false)
m.itemGrid.setFocus(true)
m.genreList.setFocus(false)
end if
Expand Down Expand Up @@ -750,6 +752,26 @@ sub onvoiceFilter()
m.loadItemsTask.searchTerm = m.voiceBox.text
m.loadItemsTask.recursive = true
m.spinner.visible = true

if m.voiceBox.text.len() = 1
' move focus to the letter spoken
alphaMenu = m.top.findNode("alphaMenu")
intConversion = m.voiceBox.text.ToInt() ' non numeric input returns as 0

if m.voiceBox.text = "0" or (isValid(intConversion) and intConversion <> 0)
alphaMenu.jumpToItem = 0
else
' loop through each option until we find a match
for i = 1 to alphaMenu.numRows - 1
alphaMenuOption = alphaMenu.content.getChild(i)
if Lcase(alphaMenuOption.TITLE) = Lcase(m.voiceBox.text)
alphaMenu.jumpToItem = i
exit for
end if
end for
end if
end if

loadInitialItems()
end if
end sub
Expand Down Expand Up @@ -884,20 +906,18 @@ function onKeyEvent(key as string, press as boolean) as boolean
if m.itemGrid.isinFocusChain()
m.top.alphaActive = true
m.itemGrid.setFocus(false)
alpha = m.alpha.getChild(0).findNode("alphaMenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true
else if m.genreList.isinFocusChain()
m.top.alphaActive = true
m.genreList.setFocus(false)
alpha = m.alpha.getChild(0).findNode("alphaMenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true
end if

else if key = "right" and m.alpha.isinFocusChain()
m.top.alphaActive = false
m.alpha.setFocus(false)
m.alphaMenu.setFocus(false)

m.itemGrid.setFocus(m.itemGrid.opacity = 1)
m.genreList.setFocus(m.genreList.opacity = 1)
Expand Down
43 changes: 33 additions & 10 deletions components/ItemGrid/MusicLibraryView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub setupNodes()
m.swapAnimation = m.top.findNode("backroundSwapAnimation")
m.spinner = m.top.findNode("spinner")
m.alpha = m.top.findNode("alpha")
m.alphaSelected = m.top.findNode("alphaSelected")
m.alphaMenu = m.alpha.findNode("alphaMenu")
m.overhang = m.top.getScene().findNode("overhang")
m.genreList = m.top.findNode("genrelist")
end sub
Expand Down Expand Up @@ -322,11 +322,11 @@ end sub
'
'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
m.top.alphaActive = false
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []

print "itemData=", itemData
if itemData = invalid
m.Loading = false
return
Expand All @@ -351,11 +351,14 @@ sub ItemDataLoaded(msg)
return
end if

' keep focus on alpha menu when loading new data
if not m.alpha.isinFocusChain()
' keep focus on alpha menu if it's active
if m.top.alphaActive
m.alphaMenu.setFocus(true)
else
m.itemGrid.opacity = "1"
m.genreList.opacity = "0"

m.alphaMenu.setFocus(false)
m.itemGrid.setFocus(true)
m.genreList.setFocus(false)
end if
Expand Down Expand Up @@ -626,7 +629,30 @@ sub onvoiceFilter()
m.loadItemsTask.searchTerm = m.voiceBox.text
m.loadItemsTask.recursive = true
m.spinner.visible = true

if m.voiceBox.text.len() = 1
' move focus to the letter spoken
intConversion = m.voiceBox.text.ToInt() ' non numeric input returns as 0

if m.voiceBox.text = "0" or (isValid(intConversion) and intConversion <> 0)
m.alphaMenu.jumpToItem = 0
else
' loop through each option until we find a match
for i = 1 to m.alphaMenu.numRows - 1
alphaMenuOption = m.alphaMenu.content.getChild(i)
if Lcase(alphaMenuOption.TITLE) = Lcase(m.voiceBox.text)
m.alphaMenu.jumpToItem = i
exit for
end if
end for
end if
end if

loadInitialItems()

if m.top.alphaActive
m.alphaMenu.setFocus(true)
end if
end if
end sub

Expand Down Expand Up @@ -744,20 +770,17 @@ function onKeyEvent(key as string, press as boolean) as boolean
if m.itemGrid.isinFocusChain()
m.top.alphaActive = true
m.itemGrid.setFocus(false)
alpha = m.alpha.getChild(0).findNode("alphaMenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true
else if m.genreList.isinFocusChain()
m.top.alphaActive = true
m.genreList.setFocus(false)
alpha = m.alpha.getChild(0).findNode("alphaMenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true
end if
else if key = "right" and m.alpha.isinFocusChain()
m.top.alphaActive = false
m.alpha.setFocus(false)
m.alpha.visible = true
m.alphaMenu.setFocus(false)

m.itemGrid.setFocus(m.itemGrid.opacity = 1)
m.genreList.setFocus(m.genreList.opacity = 1)
Expand Down

0 comments on commit f0a814b

Please sign in to comment.