Forum Discussion

renojim's avatar
renojim
Community Streaming Expert
7 years ago

ButtonGroup never hasFocus

I'm still trying to wrap my head around this roSG stuff. I noticed that if I have a CheckList and a ButtonGroup within a scene I can use setFocus() to switch between them, but calling hasFocus() on the ButtonGroup always returns false (even when a button has the focus). This seems wrong to me. Calling hasFocus() on the CheckList works as expected. It isn't keeping me from doing anything; it just bugs me. Am I missing something fundamental about scenes and components?

-JT
  • Yeah it is confusing.  Apparently only one node can have focus at a time, and according to the button group doc, "When the ButtonGroup node has focus, it sets the key focus on a single one of its child Button nodes."
    https://sdkdocs.roku.com/display/sdkdoc/ButtonGroup

    So once that child button node has focus, the group no longer does.  In this case you can use isInFocusChain() to determine whether the group has focus.
    https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeFocus#ifSGNodeFocus-isInFocusChain()asBoolean
  • renojim's avatar
    renojim
    Community Streaming Expert
    Thanks! I really need to read the docs more, but I'd rather slog through and just get my channels converted. Maybe I'll read later. Smiley LOL It just seems to me that a node should hasFocus() if any of its children does, but I guess there may be something to be said for only one node being able to have focus at a time.

    -JT
  • well I learned this stuff the hard way and just reference the docs to back up what I think I know 🙂
    But I agree, took me a while to understand that only one node can have focus and this sort of immediate off-loading of focus to a subcomponent means the parent never has focus even if you assign it directly.