How to properly detect focus change from a context? #899
Replies: 1 comment
-
|
Yeah, I see you already found |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
EDIT: Just realised that a TextInputHandler is what I need instead, so none of the below is relevant. Apologies!
In my RmlUi integration (I'm using version 6.1), the game engine I'm using passes all key presses up as raw key events unless it is put into "text input mode", in which case it will pass key press data up as characters instead. I need to use the text input mode in order to feed the characters to RmlUi through
ProcessTextInput(), but in order to do this I need to know when to enable and disable text input mode.As far as I understand, I should probably be able to get away with enabling text input mode when an
<input />or<textarea />is given focus, and disabling text input mode when anything else gains focus. To detect focus, I'm currently callingAddEventListener("focus", listener)on my context in C++, and checking the events that come through. However, I can't find a reliable way to detect what is actually left focused.If I pass
in_capture_phaseasfalse, I never get any focus events at all. If I pass it astruethen I do get events, but I get multiple events per focus change and they do not appear to be in a helpful order:GetCurrentElement()is always#root, not the input that I clicked on.GetTargetElement()appears to be any element in the parent-child chain to the input that I clicked on, and across all the events that I receive for a change in focus, the order doesn't seem to make sense. For example, one sequence of events will belabel, div, input, form, and then restarting my application and trying the exact same thing again, the sequence will beinput, label, form, div. This means I can't work out which of these target elements to actually treat as the focused element.context->GetFocusElement()is always the previously focused element, so I can't use that either.Is there a nice way to get the element that RmlUi eventually does assign focus to? I don't really want to have to register individual event listeners on every input element that happens to be on my page.
Beta Was this translation helpful? Give feedback.
All reactions