Fixes 2868 too much onconfirm#2872
Merged
Dunbaratu merged 2 commits intoKSP-KOS:developfrom Mar 10, 2021
Merged
Conversation
The problem of the latter buttons not taking focus from the text area stems from Unity IMGUI being weird about what things can and cannot take focus. Because it doesn't support keyboard control of buttons, you can't tab into buttons. So the idea of a button taking control away from a textarea doesn't work right at all. So I had to invent my own focus rules to make it properly take focus away from the text field when a button is clicked. I explicitly tell INGUI to switch which control has focus when the button click happens, since it won't always inherently do it. Secondarily, the multi-ONCONFIRM on earlier buttons is because the IMGUI system is sometimes calling OnGUI during "layout" passes in between the repainting passes. During those in-between calls, the call to GetControlID() returns -1 because it hasn't heard of the current widget yet during the layout pass. It doesn't have control ID's decided until subsequent OnGUI passes, after the layout pass is over. So the textarea incorrectly thought its control ID was -1 for just one OnGUI pass, making it think it just lost focus because the focus'ed control doesn't match the "current" ControlID of -1. Then on the next OnGUI pass it would get the proper ControlID info and realize it never really lost focus, except it *acts* as if it lost focus then regained it because of that one pass where it was -1. To get rid of that problem, I changed it so that when it sees a ControlID that is negative, it doesn't believe it's true. Instead it bypasses the focus check on any pass where the ControlID is negative, knowing it will eventually get a real, meaningful ControlID to work with on a future pass of OnGUI(), and only THEN should it try checking if the focus is in the current textarea widget or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2868 - I hope.
As of this writing there is still testing going on (testing all kinds of GUI interactions is long and can't be automated well). But I'm making the PR anyway so others can try this and report if it fixes it for them in their GUIs.
See the full explanation of the fix in the comment for this commit: 458795a