Skip to content

Fixes 2868 too much onconfirm#2872

Merged
Dunbaratu merged 2 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2868_too_much_onconfirm
Mar 10, 2021
Merged

Fixes 2868 too much onconfirm#2872
Dunbaratu merged 2 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2868_too_much_onconfirm

Conversation

@Dunbaratu
Copy link
Member

@Dunbaratu Dunbaratu commented Feb 6, 2021

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

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.
@Dunbaratu Dunbaratu added the bug Weird outcome is probably not what the mod programmer expected. label Feb 6, 2021
@Dunbaratu Dunbaratu merged commit d7e35a9 into KSP-KOS:develop Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Weird outcome is probably not what the mod programmer expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

problem with :ONCONFIRM call back for fields [BUG]

1 participant