Skip to content

Commit

Permalink
Ensure that wgpu is compatible both with imgui 1.6.0 and older (#649)
Browse files Browse the repository at this point in the history
* Ensure that wgpu is compatible both with imgui 1.6.0 and older

* Use try execpt. Release pin
  • Loading branch information
hmaarrfk authored Dec 2, 2024
1 parent b813719 commit c5108ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = ["cffi>=1.15.0", "rubicon-objc>=0.4.1; sys_platform == 'darwin'"]
# For users
jupyter = ["jupyter_rfb>=0.4.2"]
glfw = ["glfw>=1.9"]
imgui = ["imgui-bundle>=1.6.0"]
imgui = ["imgui-bundle>=1.2.1"]
# For devs / ci
build = ["build", "hatchling", "requests", "twine"]
codegen = ["pytest", "numpy", "ruff"]
Expand Down
26 changes: 20 additions & 6 deletions wgpu/utils/imgui/imgui_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,26 @@ class ImguiRenderer:
"Tab": imgui.Key.tab,
}

KEY_MAP_MOD = {
"Shift": imgui.Key.mod_shift,
"Control": imgui.Key.mod_ctrl,
"Alt": imgui.Key.mod_alt,
"Meta": imgui.Key.mod_super,
}
# imgui changed its API between 1.5.2 and 1.6.0
# But as of Dec 1, 2024, it is too early for us to force
# users to use one specific version.
# So we will support both versions for now with this small shim
try:
# Version 1.6.0 and above
KEY_MAP_MOD = {
"Shift": imgui.Key.mod_shift,
"Control": imgui.Key.mod_ctrl,
"Alt": imgui.Key.mod_alt,
"Meta": imgui.Key.mod_super,
}
except AttributeError:
# Version 1.2.1 to 1.5.2
KEY_MAP_MOD = {
"Shift": imgui.Key.im_gui_mod_shift,
"Control": imgui.Key.im_gui_mod_ctrl,
"Alt": imgui.Key.im_gui_mod_alt,
"Meta": imgui.Key.im_gui_mod_super,
}

def __init__(
self, device, canvas: wgpu.gui.WgpuCanvasBase, render_target_format=None
Expand Down

0 comments on commit c5108ac

Please sign in to comment.