Forráskód Böngészése

Merge pull request #1058 from floooh/sokol-imgui-bindings

Integrate sokol_imgui.h into zig bindings.
Andre Weissflog 1 éve
szülő
commit
7b5cfa72b3
4 módosított fájl, 32 hozzáadás és 18 törlés
  1. 18 0
      CHANGELOG.md
  2. 1 0
      bindgen/gen_all.py
  3. 3 1
      bindgen/gen_zig.py
  4. 10 17
      util/sokol_imgui.h

+ 18 - 0
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:

+ 1 - 0
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:

+ 3 - 1
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 = [

+ 10 - 17
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
 }