GUI Get Focused Control

In IFocusableControl, there doesn’t appear to be any kind of way to see if a control has the focus (e.g., an “IsFocused” method).

Nor have I found any other way of getting this info. Is it possible?

Hello,
Are you speaking about the BJS 2D GUI.
I believe it depends what you mean by ‘focused’ method.
If it’s a reference to JS, you want to start an action when you hover something or it could also be just a design/animation event.
Well, in any case, there is a replacement for all that.
But no, the isFocused method is not part of it.
It depends on the control you are using and then again what you want to achieve?
May be you can give some more details? Thanks,

I specifically mentioned IFocusableControl, which exposes a focus() method. I’m not sure what more you are asking for.

As far as I know, this is used only on the inputText control and the accessor is not ‘isFocused’ but ‘onFocusObservable’.

cc @DarraghBurke

FocusableButton does have a private member _isFocused. You could definitely add this to any class which implements IFocusableControl as well by just toggling in onFocus and onBlur. Would that work for you?

The ADT also has a public member focusedControl which you could check for equality with your control. So, isFocused would be equivalent to this.host.focusedControl === this.

1 Like

I’m curious why this exists in the button instead of IFocusableControl.

1 Like

I marked this as solution as it seems the best way to solve the problem at the moment. Certainly seems that the flag should be implemented in the base interface though; I suppose I’ll get into the UI for some of this in the near future. :slight_smile:

2 Likes

Well, the control being focused is really a property of the ADT, not the control itself. Having it as property of the ADT does help prevent bugs where multiple controls could be simultaneously focused. I guess we could have an isFocused() method on the control which performs the check I described, but it doesn’t seem necessary.

1 Like

If it’s actually ADT property, I agree.

1 Like