Your Digital Media Has Never Looked So Good

 
jaxim
Topic Author
Posts: 57
Joined: Mon Sep 26, 2016 6:25 am

Button to Listen to Focus Event?

Fri Aug 03, 2018 2:59 pm

I've created a custom component that extends the button class. I would like to listen to a Focus event within the custom component so I can tell the UI nodes to display differently when the component is in focus. I've tried to listen to the focusPercent field within component's interface like below but the eventhandler is never called.

<field id="focusPercent" type="float" onChange="itemFocusChanged"/>


How do I get this custom component/button to listen to the focus event so I can have it react to getting into and out of focus?


p.s. This is how I am setting the button into focus: button.setFocus(true)
 
joetesta
Posts: 762
Joined: Wed Apr 20, 2011 11:48 am

Re: Button to Listen to Focus Event?

Fri Aug 03, 2018 6:30 pm

button and Group (which button is extended from) don't have a focusPercent field, afaik.
You could do this; In your .brs script, add an observer to the button's focusedChild:

...
  m.button.observeField("focusedChild", "focusChanged")
...

sub focusChanged()
  if m.button.hasFocus()
    ' the button has focus, decorate accordingly'
  else
    ' the button lost focus, undecorate accordingly'
  end if
end sub

Actually you probably need to use "m.top" instead of "m.button" assuming this script is in the actual button brs.
aspiring
 
jaxim
Topic Author
Posts: 57
Joined: Mon Sep 26, 2016 6:25 am

Re: Button to Listen to Focus Event?

Mon Aug 06, 2018 8:47 am

That worked! This seems like a bug. It seems like an oversight not to officially support a buttons onFocus event instead of having to use a workaround like this.
Thanks!

m.top.observeField("focusedChild", "onFocusChanged")

Who is online

Users browsing this forum: No registered users and 10 guests