diff options
| author | Andre Weissflog <floooh@gmail.com> | 2024-06-01 16:03:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-01 16:03:11 +0200 |
| commit | 7b5cfa72b3188b239c23ec0f0eb7a810ec128dd4 (patch) | |
| tree | 69f6921fbb8a16a2a7657170ff5619889d1d7b5b | |
| parent | cb641c900bbe478f07f8b2b22a4ea1c2f7d1d121 (diff) | |
| parent | ff0dc3f8d3d04e67f04a4c5e4e2f4fe6d5751391 (diff) | |
Merge pull request #1058 from floooh/sokol-imgui-bindings
Integrate sokol_imgui.h into zig bindings.
| -rw-r--r-- | CHANGELOG.md | 18 | ||||
| -rw-r--r-- | bindgen/gen_all.py | 1 | ||||
| -rw-r--r-- | bindgen/gen_zig.py | 4 | ||||
| -rw-r--r-- | util/sokol_imgui.h | 27 |
4 files changed, 32 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 28fc9bbd..c16f4437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ ## Updates +### 01-Jun-2024 + +sokol_imgui.h is now officially supported in the [sokol-zig bindings](https://github.com/floooh/sokol-zig). + +This caused a very minor breaking change in the sokol_imgui.h function +`simgui_add_key_event()`: previously this took a callback function pointer +which mapped the incoming key code to a Dear ImGui compatible keycode, +this is now expected to be performed by the caller before calling +`simgui_add_key_event()`. + +Other than the minor API change there's an equally minor internal code cleanup: +The ImGuiIO method `SetKeyEventNativeData()` is no longer called. This change shouldn't +have any side effects. + +For more details about the Zig sokol_imgui.h also see this example project: + +https://github.com/floooh/sokol-zig-imgui-sample + ### 14-May-2024 sokol_fetch.h: A minor breaking change in which hopefully doesn't affect anybody: diff --git a/bindgen/gen_all.py b/bindgen/gen_all.py index 4ddd339f..3b29383d 100644 --- a/bindgen/gen_all.py +++ b/bindgen/gen_all.py @@ -28,6 +28,7 @@ for task in tasks: zig_tasks = [ *tasks, [ '../sokol_fetch.h', 'sfetch_', [] ], + [ '../util/sokol_imgui.h', 'simgui_', ['sg_', 'sapp_'] ], ] gen_zig.prepare() for task in zig_tasks: diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py index 57e2f860..4b63eebe 100644 --- a/bindgen/gen_zig.py +++ b/bindgen/gen_zig.py @@ -22,6 +22,7 @@ module_names = { 'sshape_': 'shape', 'sglue_': 'glue', 'sfetch_': 'fetch', + 'simgui_': 'imgui', } c_source_paths = { @@ -34,7 +35,8 @@ c_source_paths = { 'sdtx_': 'sokol-zig/src/sokol/c/sokol_debugtext.c', 'sshape_': 'sokol-zig/src/sokol/c/sokol_shape.c', 'sglue_': 'sokol-zig/src/sokol/c/sokol_glue.c', - 'sfetch_': 'sokol-zig/src/sokol/c/sokol_fetch.c' + 'sfetch_': 'sokol-zig/src/sokol/c/sokol_fetch.c', + 'simgui_': 'sokol-zig/src/sokol/c/sokol_imgui.c', } ignores = [ diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h index 810890c0..0362a9a9 100644 --- a/util/sokol_imgui.h +++ b/util/sokol_imgui.h @@ -351,12 +351,10 @@ simgui_add_mouse_pos_event(100, 200); - Key events require a mapping function to convert your platform's key values to ImGuiKey's: + For adding key events, you're responsible to map your own key codes to ImGuiKey + values and pass those as int: - int map_keycode(int keycode) { - // Your mapping logic here... - } - simgui_add_key_event(map_keycode, keycode, true); + simgui_add_key_event(imgui_key, true); Take note that modifiers (shift, ctrl, etc.) must be updated manually. @@ -533,13 +531,13 @@ SOKOL_IMGUI_API_DECL simgui_image_t simgui_make_image(const simgui_image_desc_t* SOKOL_IMGUI_API_DECL void simgui_destroy_image(simgui_image_t img); SOKOL_IMGUI_API_DECL simgui_image_desc_t simgui_query_image_desc(simgui_image_t img); SOKOL_IMGUI_API_DECL void* simgui_imtextureid(simgui_image_t img); -SOKOL_IMGUI_API_DECL simgui_image_t simgui_image_from_imtextureid(void* imtextureid); +SOKOL_IMGUI_API_DECL simgui_image_t simgui_image_from_imtextureid(void* im_texture_id); SOKOL_IMGUI_API_DECL void simgui_add_focus_event(bool focus); SOKOL_IMGUI_API_DECL void simgui_add_mouse_pos_event(float x, float y); SOKOL_IMGUI_API_DECL void simgui_add_touch_pos_event(float x, float y); SOKOL_IMGUI_API_DECL void simgui_add_mouse_button_event(int mouse_button, bool down); SOKOL_IMGUI_API_DECL void simgui_add_mouse_wheel_event(float wheel_x, float wheel_y); -SOKOL_IMGUI_API_DECL void simgui_add_key_event(int (*map_keycode)(int), int keycode, bool down); +SOKOL_IMGUI_API_DECL void simgui_add_key_event(int imgui_key, bool down); SOKOL_IMGUI_API_DECL void simgui_add_input_character(uint32_t c); SOKOL_IMGUI_API_DECL void simgui_add_input_characters_utf8(const char* c); SOKOL_IMGUI_API_DECL void simgui_add_touch_button_event(int mouse_button, bool down); @@ -2508,9 +2506,9 @@ SOKOL_API_IMPL void* simgui_imtextureid(simgui_image_t img) { return (void*)(uintptr_t)img.id; } -SOKOL_API_IMPL simgui_image_t simgui_image_from_imtextureid(void* imtextureid) { +SOKOL_API_IMPL simgui_image_t simgui_image_from_imtextureid(void* im_texture_id) { SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); - simgui_image_t img = { (uint32_t)(uintptr_t) imtextureid }; + simgui_image_t img = { (uint32_t)(uintptr_t) im_texture_id }; return img; } @@ -2840,17 +2838,14 @@ SOKOL_API_IMPL void simgui_add_mouse_wheel_event(float wheel_x, float wheel_y) { #endif } -SOKOL_API_IMPL void simgui_add_key_event(int (*map_keycode)(int), int keycode, bool down) { +SOKOL_API_IMPL void simgui_add_key_event(int imgui_key, bool down) { SOKOL_ASSERT(_SIMGUI_INIT_COOKIE == _simgui.init_cookie); - const ImGuiKey imgui_key = (ImGuiKey)map_keycode(keycode); #if defined(__cplusplus) ImGuiIO* io = &ImGui::GetIO(); - io->AddKeyEvent(imgui_key, down); - io->SetKeyEventNativeData(imgui_key, keycode, 0, -1); + io->AddKeyEvent((ImGuiKey)imgui_key, down); #else ImGuiIO* io = igGetIO(); - ImGuiIO_AddKeyEvent(io, imgui_key, down); - ImGuiIO_SetKeyEventNativeData(io, imgui_key, keycode, 0, -1); + ImGuiIO_AddKeyEvent(io, (ImGuiKey)imgui_key, down); #endif } @@ -3000,10 +2995,8 @@ _SOKOL_PRIVATE void _simgui_add_sapp_key_event(ImGuiIO* io, sapp_keycode sapp_ke const ImGuiKey imgui_key = _simgui_map_keycode(sapp_key); #if defined(__cplusplus) io->AddKeyEvent(imgui_key, down); - io->SetKeyEventNativeData(imgui_key, (int)sapp_key, 0, -1); #else ImGuiIO_AddKeyEvent(io, imgui_key, down); - ImGuiIO_SetKeyEventNativeData(io, imgui_key, (int)sapp_key, 0, -1); #endif } |