Browse Source

pgui: allow keyboard keys to be added as PGButton click buttons

These will respond as clicks not when the mouse cursor is hovering over them, but when they have keyboard focus.

Fixes #600
rdb 6 years ago
parent
commit
54c6eaeb96
1 changed files with 5 additions and 1 deletions
  1. 5 1
      panda/src/pgui/pgButton.cxx

+ 5 - 1
panda/src/pgui/pgButton.cxx

@@ -115,7 +115,11 @@ release(const MouseWatcherParameter &param, bool background) {
   if (has_click_button(param.get_button())) {
     _button_down = false;
     if (get_active()) {
-      if (param.is_outside()) {
+      // Note that a "click" may come from a keyboard button press.  In that
+      // case, instead of checking that the mouse cursor is still over the
+      // button, we check whether the item has keyboard focus.
+      if (param.is_outside() &&
+          (MouseButton::is_mouse_button(param.get_button()) || !get_focus())) {
         set_state(S_ready);
       } else {
         set_state(S_rollover);