Skip to content

Commit

Permalink
Inputs: Extra Keys / AddKeyEvent(): bidirectional mapping, basic CI, …
Browse files Browse the repository at this point in the history
…simplify backends, asserts on misuses, tested backward compat. (#2625, #4858, #2787)

(edit: simplified backends merged into previous commits to make history clearer)
  • Loading branch information
ocornut committed Jan 10, 2022
1 parent 3b66929 commit bf08c13
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 153 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -301,6 +301,18 @@ jobs:
EOF
g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_OBSOLETE_KEYIO)
run: |
cat > example_single_file.cpp <<'EOF'
#define IMGUI_DISABLE_OBSOLETE_KEYIO
#define IMGUI_IMPLEMENTATION
#include "misc/single_file/imgui_single_file.h"
#include "examples/example_null/main.cpp"
EOF
g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp
- name: Build example_null (with IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_METRICS_WINDOW)
run: |
cat > example_single_file.cpp <<'EOF'
Expand Down
29 changes: 29 additions & 0 deletions docs/CHANGELOG.txt
Expand Up @@ -37,6 +37,34 @@ HOW TO UPDATE?

Breaking Changes:

- Reworked IO keyboard input system. (#2625, #3724) [@thedmd, @ocornut]
- Added io.AddKeyEvent() function, obsoleting writing directly to io.KeyMap[], io.KeysDown[] arrays.
- Added io.AddKeyModEvent() function, obsoleting writing directly to io.KeyCtrl, io.KeyShift etc.
- Added io.SetKeyEventNativeData() function (optional) to pass native and old legacy indices.
- Added full range of key enums in ImGuiKey (e.g. ImGuiKey_F1).
- Added GetKeyName() helper function.
- Obsoleted GetKeyIndex(): it is now unnecessary and will now return the same value.
- All keyboard related functions taking 'int user_key_index' now take 'ImGuiKey key':
- IsKeyDown(), IsKeyPressed(), IsKeyReleased(), GetKeyPressedAmount().
- All backends were updated to use io.AddKeyEvent().
- Backward compatibility:
- Old backends populating those arrays will still work! (for a while)
- Calling e.g. IsKeyPressed(MY_NATIVE_KEY_XXX) will still work! (for a while)
- Those legacy arrays will only be disabled if '#define IMGUI_DISABLE_OBSOLETE_KEYIO' is set in your imconfig.
In a few versions, IMGUI_DISABLE_OBSOLETE_FUNCTIONS will automatically enable IMGUI_DISABLE_OBSOLETE_KEYIO,
so this will be moved into the regular obsolescence path.
- Transition guide:
- IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX)
- IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
- Backend writing to io.KeyMap[],KeysDown[] -> backend should call io.AddKeyEvent(), if legacy indexing is desired, call io.SetKeyEventNativeData()
- Basically the trick we took advantage of is that we previously only supported native keycode from 0 to 511,
so ImGuiKey values can still express a legacy native keycode, and new named keys are all >= 512.
- This will enable a few things in the future:
- Access to portable keys allows for backed-agnostic keyboard input code. Until now it was difficult to
share code using keyboard accross project because of this gap. (#2625, #3724)
- Access to full key ranges will allow us to develop a proper keyboard shortcut system. (#456)
- io.AddKeyEvent() will later be turned into a trickling IO queue (for all inputs) to handle very low framerate better. (#2525, #2787, #3383)
- io.SetKeyEventNativeData() include native keycode/scancode which will later be exposed. (#3141, #2959)
- Renamed ImGuiKey_KeyPadEnter to ImGuiKey_KeypadEnter to align with new symbols. Kept redirection enum. (#2625)
- Commented out redirecting functions/enums names that were marked obsolete in 1.69, 1.70, 1.71, 1.72 (March-July 2019)
- ImGui::SetNextTreeNodeOpen() -> use ImGui::SetNextItemOpen()
Expand Down Expand Up @@ -68,6 +96,7 @@ Other Changes:
- Backends: GLFW: fix CTRL+A, CTRL+Z, CTRL+Y shortcuts to match user keyboard layout. We are now converting GLFW
untranslated keycodes back to translated keycodes in order to match the behavior of every other backend, and
facilitate the use of GLFW with lettered-shortcuts API. (#456, #2625)
- Backends: Allegro5, GLFW, GLUT, SDL, OSX, Win32, Android: Updated to use io.AddKeyEvent() with full key range. (#2625) [@thedmd]
- Backends: OpenGL3: Fixed a buffer overflow in imgui_impl_opengl3_loader.h init (added in 1.86). (#4468, #4830) [@dymk]
It would generally not have noticeable side-effect at runtime but would be detected by runtime checkers.
- Backends: Metal: Added Apple Metal C++ API support. (#4824, #4746) [@luigifcruz]
Expand Down
2 changes: 1 addition & 1 deletion imconfig.h
Expand Up @@ -28,7 +28,7 @@

//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.86: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.

//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
Expand Down

0 comments on commit bf08c13

Please sign in to comment.