imgui 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +273 -0
  4. data/Rakefile +97 -0
  5. data/api/v1.json +53 -0
  6. data/ext/CMakeLists.txt +128 -0
  7. data/ext/Rakefile +31 -0
  8. data/ext/backend_function_bridge.cpp +180 -0
  9. data/ext/backend_function_bridge.h +40 -0
  10. data/ext/build_cimgui.rb +59 -0
  11. data/ext/extconf.rb +25 -0
  12. data/ext/glfw_vulkan_bridge.cpp +14 -0
  13. data/ext/imgui_ruby_build_config.h +17 -0
  14. data/ext/imgui_ruby_glfw.cpp +73 -0
  15. data/ext/imgui_ruby_sdl3.cpp +70 -0
  16. data/ext/imgui_ruby_wgpu.cpp +75 -0
  17. data/ext/install_cimgui.rb +25 -0
  18. data/ext/webgpu_function_bridge.cpp +245 -0
  19. data/generator/api_emitter.rb +164 -0
  20. data/generator/emitter.rb +317 -0
  21. data/generator/generate.rb +47 -0
  22. data/generator/native-dependencies.yml +88 -0
  23. data/generator/native_dependency_lock.rb +78 -0
  24. data/generator/native_dependency_snapshot.rb +159 -0
  25. data/generator/overrides.yml +11 -0
  26. data/generator/type_mapper.rb +112 -0
  27. data/generator/update_vendor.rb +30 -0
  28. data/lib/imgui/api.rb +88 -0
  29. data/lib/imgui/api_generated.rb +1633 -0
  30. data/lib/imgui/api_support.rb +144 -0
  31. data/lib/imgui/backends/glfw.rb +75 -0
  32. data/lib/imgui/backends/opengl3.rb +44 -0
  33. data/lib/imgui/backends/sdl3.rb +133 -0
  34. data/lib/imgui/backends/wgpu.rb +176 -0
  35. data/lib/imgui/backends.rb +60 -0
  36. data/lib/imgui/draw_data.rb +43 -0
  37. data/lib/imgui/dsl.rb +311 -0
  38. data/lib/imgui/dsl_support.rb +107 -0
  39. data/lib/imgui/easy_loop.rb +25 -0
  40. data/lib/imgui/errors.rb +11 -0
  41. data/lib/imgui/fonts.rb +46 -0
  42. data/lib/imgui/io.rb +91 -0
  43. data/lib/imgui/layout.rb +138 -0
  44. data/lib/imgui/memory_pool.rb +18 -0
  45. data/lib/imgui/native/enums.rb +2251 -0
  46. data/lib/imgui/native/functions.rb +1470 -0
  47. data/lib/imgui/native/structs.rb +1926 -0
  48. data/lib/imgui/native/typedefs.rb +93 -0
  49. data/lib/imgui/native.rb +130 -0
  50. data/lib/imgui/plot/api.rb +273 -0
  51. data/lib/imgui/plot/native/enums.rb +593 -0
  52. data/lib/imgui/plot/native/functions.rb +749 -0
  53. data/lib/imgui/plot/native/structs.rb +363 -0
  54. data/lib/imgui/plot/native/typedefs.rb +79 -0
  55. data/lib/imgui/plot.rb +13 -0
  56. data/lib/imgui/struct_value.rb +33 -0
  57. data/lib/imgui/style.rb +44 -0
  58. data/lib/imgui/value.rb +104 -0
  59. data/lib/imgui/version.rb +5 -0
  60. data/lib/imgui/widgets.rb +187 -0
  61. data/lib/imgui.rb +30 -0
  62. data/rakelib/platform_gem.rake +54 -0
  63. data/rakelib/source_gem.rake +75 -0
  64. metadata +129 -0
@@ -0,0 +1,180 @@
1
+ #include "backend_function_bridge.h"
2
+
3
+ #include <mutex>
4
+ #include <string>
5
+ #include <unordered_map>
6
+ #include <vector>
7
+
8
+ #if defined(_WIN32)
9
+ #ifndef WIN32_LEAN_AND_MEAN
10
+ #define WIN32_LEAN_AND_MEAN
11
+ #endif
12
+ #include <windows.h>
13
+ #else
14
+ #include <dlfcn.h>
15
+ #endif
16
+
17
+ namespace
18
+ {
19
+ std::mutex bridge_mutex;
20
+ std::unordered_map<std::string, void*> library_handles;
21
+ std::string bridge_error;
22
+
23
+ const std::vector<const char*>& required_functions(const std::string& backend)
24
+ {
25
+ static const std::vector<const char*> glfw = {
26
+ "glfwCreateStandardCursor", "glfwCreateWindow", "glfwCreateWindowSurface",
27
+ "glfwDestroyCursor", "glfwDestroyWindow", "glfwFocusWindow",
28
+ "glfwGetClipboardString", "glfwGetCursorPos", "glfwGetError",
29
+ "glfwGetFramebufferSize", "glfwGetGamepadState", "glfwGetInputMode",
30
+ "glfwGetJoystickAxes", "glfwGetJoystickButtons", "glfwGetKey", "glfwGetKeyName",
31
+ "glfwGetMonitorContentScale", "glfwGetMonitorPos", "glfwGetMonitorWorkarea",
32
+ "glfwGetMonitors", "glfwGetTime", "glfwGetVideoMode", "glfwGetWindowAttrib",
33
+ "glfwGetWindowPos", "glfwGetWindowSize", "glfwMakeContextCurrent",
34
+ "glfwSetCharCallback", "glfwSetClipboardString", "glfwSetCursor",
35
+ "glfwSetCursorEnterCallback", "glfwSetCursorPos", "glfwSetCursorPosCallback",
36
+ "glfwSetErrorCallback", "glfwSetInputMode", "glfwSetKeyCallback",
37
+ "glfwSetMonitorCallback", "glfwSetMouseButtonCallback", "glfwSetScrollCallback",
38
+ "glfwSetWindowAttrib", "glfwSetWindowCloseCallback", "glfwSetWindowFocusCallback",
39
+ "glfwSetWindowOpacity", "glfwSetWindowPos", "glfwSetWindowPosCallback",
40
+ "glfwSetWindowSize", "glfwSetWindowSizeCallback", "glfwSetWindowTitle",
41
+ "glfwShowWindow", "glfwSwapBuffers", "glfwSwapInterval", "glfwWindowHint",
42
+ #if defined(_WIN32)
43
+ "glfwGetWin32Window",
44
+ #elif defined(__APPLE__)
45
+ "glfwGetCocoaWindow",
46
+ #endif
47
+ };
48
+ static const std::vector<const char*> sdl3 = {
49
+ "SDL_CaptureMouse", "SDL_CloseGamepad", "SDL_CreateSystemCursor", "SDL_CreateWindow",
50
+ "SDL_DestroyCursor", "SDL_DestroyWindow", "SDL_GL_CreateContext", "SDL_GL_DestroyContext",
51
+ "SDL_GL_GetCurrentContext", "SDL_GL_MakeCurrent", "SDL_GL_SetAttribute",
52
+ "SDL_GL_SetSwapInterval", "SDL_GL_SwapWindow", "SDL_GetClipboardText",
53
+ "SDL_GetCurrentVideoDriver", "SDL_GetDisplayBounds", "SDL_GetDisplayContentScale",
54
+ "SDL_GetDisplayUsableBounds", "SDL_GetDisplays", "SDL_GetGamepadAxis",
55
+ "SDL_GetGamepadButton", "SDL_GetGamepads", "SDL_GetGlobalMouseState",
56
+ "SDL_GetKeyboardFocus", "SDL_GetPerformanceCounter", "SDL_GetPerformanceFrequency",
57
+ "SDL_GetPointerProperty", "SDL_GetWindowFlags", "SDL_GetWindowFromID", "SDL_GetWindowID",
58
+ "SDL_GetWindowPosition", "SDL_GetWindowProperties", "SDL_GetWindowRelativeMouseMode",
59
+ "SDL_GetWindowSize", "SDL_GetWindowSizeInPixels", "SDL_HideCursor", "SDL_OpenGamepad",
60
+ "SDL_OpenURL", "SDL_RaiseWindow", "SDL_SetClipboardText", "SDL_SetCursor", "SDL_SetHint",
61
+ "SDL_SetTextInputArea", "SDL_SetWindowOpacity", "SDL_SetWindowParent",
62
+ "SDL_SetWindowPosition", "SDL_SetWindowSize", "SDL_SetWindowTitle", "SDL_ShowCursor",
63
+ "SDL_ShowWindow", "SDL_StartTextInput", "SDL_StopTextInput", "SDL_Vulkan_CreateSurface",
64
+ "SDL_WarpMouseGlobal", "SDL_WarpMouseInWindow", "SDL_free", "SDL_strdup",
65
+ };
66
+ static const std::vector<const char*> empty;
67
+
68
+ if (backend == "GLFW")
69
+ return glfw;
70
+ if (backend == "SDL3")
71
+ return sdl3;
72
+ return empty;
73
+ }
74
+
75
+ void set_error(const std::string& message)
76
+ {
77
+ bridge_error = message;
78
+ }
79
+
80
+ void* open_library(const char* path)
81
+ {
82
+ #if defined(_WIN32)
83
+ HMODULE handle = LoadLibraryA(path);
84
+ if (handle == nullptr)
85
+ set_error("LoadLibrary failed for " + std::string(path) + " (error " + std::to_string(GetLastError()) + ")");
86
+ return reinterpret_cast<void*>(handle);
87
+ #else
88
+ dlerror();
89
+ void* handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
90
+ if (handle == nullptr)
91
+ {
92
+ const char* error = dlerror();
93
+ set_error(error != nullptr ? error : "dlopen failed for " + std::string(path));
94
+ }
95
+ return handle;
96
+ #endif
97
+ }
98
+
99
+ void* find_symbol(void* handle, const char* name)
100
+ {
101
+ #if defined(_WIN32)
102
+ return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(handle), name));
103
+ #else
104
+ dlerror();
105
+ return dlsym(handle, name);
106
+ #endif
107
+ }
108
+ } // namespace
109
+
110
+ extern "C" IMGUI_RUBY_EXPORT bool imgui_ruby_backend_load_library(const char* backend, const char* path)
111
+ {
112
+ if (backend == nullptr || path == nullptr || backend[0] == '\0' || path[0] == '\0')
113
+ return false;
114
+
115
+ std::lock_guard<std::mutex> lock(bridge_mutex);
116
+ if (library_handles.find(backend) != library_handles.end())
117
+ return true;
118
+
119
+ void* handle = open_library(path);
120
+ if (handle == nullptr)
121
+ return false;
122
+
123
+ library_handles.emplace(backend, handle);
124
+ bridge_error.clear();
125
+ return true;
126
+ }
127
+
128
+ extern "C" IMGUI_RUBY_EXPORT bool imgui_ruby_backend_library_ready(const char* backend)
129
+ {
130
+ if (backend == nullptr)
131
+ return false;
132
+
133
+ std::lock_guard<std::mutex> lock(bridge_mutex);
134
+ return library_handles.find(backend) != library_handles.end();
135
+ }
136
+
137
+ extern "C" IMGUI_RUBY_EXPORT bool imgui_ruby_backend_has_function(const char* backend, const char* name)
138
+ {
139
+ return imgui_ruby_backend_resolve_function(backend, name) != nullptr;
140
+ }
141
+
142
+ extern "C" IMGUI_RUBY_EXPORT size_t imgui_ruby_backend_required_function_count(const char* backend)
143
+ {
144
+ return backend != nullptr ? required_functions(backend).size() : 0;
145
+ }
146
+
147
+ extern "C" IMGUI_RUBY_EXPORT const char* imgui_ruby_backend_required_function_name(
148
+ const char* backend,
149
+ size_t index)
150
+ {
151
+ if (backend == nullptr)
152
+ return nullptr;
153
+ const auto& functions = required_functions(backend);
154
+ return index < functions.size() ? functions[index] : nullptr;
155
+ }
156
+
157
+ extern "C" IMGUI_RUBY_EXPORT const char* imgui_ruby_backend_library_error()
158
+ {
159
+ std::lock_guard<std::mutex> lock(bridge_mutex);
160
+ return bridge_error.c_str();
161
+ }
162
+
163
+ void* imgui_ruby_backend_resolve_function(const char* backend, const char* name)
164
+ {
165
+ if (backend == nullptr || name == nullptr)
166
+ return nullptr;
167
+
168
+ std::lock_guard<std::mutex> lock(bridge_mutex);
169
+ auto library = library_handles.find(backend);
170
+ if (library == library_handles.end())
171
+ {
172
+ set_error(std::string(backend) + " runtime library is not loaded");
173
+ return nullptr;
174
+ }
175
+
176
+ void* address = find_symbol(library->second, name);
177
+ if (address == nullptr)
178
+ set_error(std::string(backend) + " runtime library does not export " + name);
179
+ return address;
180
+ }
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <cstdio>
4
+ #include <cstdlib>
5
+
6
+ #if defined(_WIN32)
7
+ #define IMGUI_RUBY_EXPORT __declspec(dllexport)
8
+ #else
9
+ #define IMGUI_RUBY_EXPORT __attribute__((visibility("default")))
10
+ #endif
11
+
12
+ extern "C" {
13
+ IMGUI_RUBY_EXPORT bool imgui_ruby_backend_load_library(const char* backend, const char* path);
14
+ IMGUI_RUBY_EXPORT bool imgui_ruby_backend_library_ready(const char* backend);
15
+ IMGUI_RUBY_EXPORT bool imgui_ruby_backend_has_function(const char* backend, const char* name);
16
+ IMGUI_RUBY_EXPORT size_t imgui_ruby_backend_required_function_count(const char* backend);
17
+ IMGUI_RUBY_EXPORT const char* imgui_ruby_backend_required_function_name(const char* backend, size_t index);
18
+ IMGUI_RUBY_EXPORT const char* imgui_ruby_backend_library_error();
19
+ }
20
+
21
+ void* imgui_ruby_backend_resolve_function(const char* backend, const char* name);
22
+
23
+ template <typename Function>
24
+ Function imgui_ruby_backend_function(const char* backend, const char* name)
25
+ {
26
+ void* address = imgui_ruby_backend_resolve_function(backend, name);
27
+ if (address == nullptr)
28
+ {
29
+ std::fprintf(stderr, "imgui-ruby: unresolved %s function %s\n", backend, name);
30
+ std::abort();
31
+ }
32
+ return reinterpret_cast<Function>(address);
33
+ }
34
+
35
+ #define IMGUI_RUBY_BACKEND_CALL(backend, function_name, ...) \
36
+ ([]() -> decltype(&function_name) { \
37
+ static auto function = imgui_ruby_backend_function<decltype(&function_name)>( \
38
+ backend, #function_name); \
39
+ return function; \
40
+ }())(__VA_ARGS__)
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "open3"
5
+
6
+ module ImGuiRuby
7
+ class NativeBuilder
8
+ def initialize(source_dir:, build_dir:, install_dir:)
9
+ @source_dir = source_dir
10
+ @build_dir = build_dir
11
+ @install_dir = install_dir
12
+ end
13
+
14
+ def build!
15
+ FileUtils.mkdir_p(@build_dir)
16
+ FileUtils.mkdir_p(@install_dir)
17
+ run("cmake", "-S", @source_dir, "-B", @build_dir, *cmake_options)
18
+ run("cmake", "--build", @build_dir, "--config", "Release", "--parallel")
19
+ run("cmake", "--install", @build_dir, "--config", "Release", "--prefix", @install_dir)
20
+ end
21
+
22
+ private
23
+
24
+ def cmake_options
25
+ backends = ENV.fetch("IMGUI_RUBY_BACKENDS", "").split(",").map(&:strip)
26
+ [
27
+ "-DCMAKE_BUILD_TYPE=Release",
28
+ "-DIMGUI_RUBY_WITH_GLFW=#{on_off(backends.include?("glfw"))}",
29
+ "-DIMGUI_RUBY_WITH_OPENGL3=#{on_off(backends.include?("opengl3"))}",
30
+ "-DIMGUI_RUBY_WITH_SDL3=#{on_off(backends.include?("sdl3"))}",
31
+ "-DIMGUI_RUBY_WITH_WGPU=#{on_off(backends.include?("wgpu"))}",
32
+ "-DIMGUI_RUBY_WITH_IMPLOT=#{on_off(!backends.include?("no-implot"))}"
33
+ ]
34
+ end
35
+
36
+ def on_off(value)
37
+ value ? "ON" : "OFF"
38
+ end
39
+
40
+ def run(*command)
41
+ output, status = Open3.capture2e(*command)
42
+ puts output
43
+ return if status.success?
44
+
45
+ raise "command failed (#{status.exitstatus}): #{command.join(" ")}"
46
+ end
47
+ end
48
+ end
49
+
50
+ if $PROGRAM_NAME == __FILE__
51
+ build_dir, install_dir = ARGV
52
+ raise ArgumentError, "build and install directories are required" unless build_dir && install_dir
53
+
54
+ ImGuiRuby::NativeBuilder.new(
55
+ source_dir: __dir__,
56
+ build_dir: File.expand_path(build_dir),
57
+ install_dir: File.expand_path(install_dir)
58
+ ).build!
59
+ end
data/ext/extconf.rb ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+ require "shellwords"
5
+
6
+ ruby = Shellwords.escape(RbConfig.ruby)
7
+ extension_dir = File.expand_path(__dir__)
8
+ build_dir = File.join(extension_dir, "build")
9
+ install_dir = File.join(build_dir, "install")
10
+
11
+ makefile = <<~MAKEFILE
12
+ RUBY = #{ruby}
13
+ sitearchdir = #{Shellwords.escape(RbConfig::CONFIG.fetch("sitearchdir"))}
14
+
15
+ all:
16
+ $(RUBY) #{Shellwords.escape(File.join(extension_dir, "build_cimgui.rb"))} #{Shellwords.escape(build_dir)} #{Shellwords.escape(install_dir)}
17
+
18
+ install:
19
+ $(RUBY) #{Shellwords.escape(File.join(extension_dir, "install_cimgui.rb"))} #{Shellwords.escape(install_dir)} "$(DESTDIR)$(sitearchdir)"
20
+
21
+ clean:
22
+ @true
23
+ MAKEFILE
24
+
25
+ File.write(File.join(extension_dir, "Makefile"), makefile)
@@ -0,0 +1,14 @@
1
+ #include <GLFW/glfw3.h>
2
+
3
+ #include "backend_function_bridge.h"
4
+
5
+ extern "C" int glfwCreateWindowSurface(
6
+ void* instance,
7
+ GLFWwindow* window,
8
+ const void* allocator,
9
+ void* surface)
10
+ {
11
+ using Function = int (*)(void*, GLFWwindow*, const void*, void*);
12
+ static auto function = imgui_ruby_backend_function<Function>("GLFW", "glfwCreateWindowSurface");
13
+ return function(instance, window, allocator, surface);
14
+ }
@@ -0,0 +1,17 @@
1
+ #pragma once
2
+
3
+ // Keep backend declarations compatible with cimgui's exported C ABI on every
4
+ // translation unit, including vendor sources compiled directly by CMake.
5
+ #if !defined(IMGUI_IMPL_API)
6
+ #if defined(_WIN32)
7
+ #define IMGUI_IMPL_API extern "C" __declspec(dllexport)
8
+ #else
9
+ #define IMGUI_IMPL_API extern "C" __attribute__((visibility("default")))
10
+ #endif
11
+ #endif
12
+
13
+ // GLFW includes the system OpenGL header by default, but the bundled backend
14
+ // uses Dear ImGui's own OpenGL loader and does not require that header.
15
+ #if !defined(GLFW_INCLUDE_NONE)
16
+ #define GLFW_INCLUDE_NONE
17
+ #endif
@@ -0,0 +1,73 @@
1
+ #include <GLFW/glfw3.h>
2
+
3
+ #if defined(_WIN32)
4
+ #define GLFW_EXPOSE_NATIVE_WIN32
5
+ #include <GLFW/glfw3native.h>
6
+ #elif defined(__APPLE__)
7
+ #define GLFW_EXPOSE_NATIVE_COCOA
8
+ #include <GLFW/glfw3native.h>
9
+ #endif
10
+
11
+ #include "backend_function_bridge.h"
12
+
13
+ #define IMGUI_RUBY_GLFW(function_name, ...) \
14
+ IMGUI_RUBY_BACKEND_CALL("GLFW", function_name, __VA_ARGS__)
15
+
16
+ #define glfwCreateStandardCursor(...) IMGUI_RUBY_GLFW(glfwCreateStandardCursor, __VA_ARGS__)
17
+ #define glfwCreateWindow(...) IMGUI_RUBY_GLFW(glfwCreateWindow, __VA_ARGS__)
18
+ #define glfwDestroyCursor(...) IMGUI_RUBY_GLFW(glfwDestroyCursor, __VA_ARGS__)
19
+ #define glfwDestroyWindow(...) IMGUI_RUBY_GLFW(glfwDestroyWindow, __VA_ARGS__)
20
+ #define glfwFocusWindow(...) IMGUI_RUBY_GLFW(glfwFocusWindow, __VA_ARGS__)
21
+ #define glfwGetClipboardString(...) IMGUI_RUBY_GLFW(glfwGetClipboardString, __VA_ARGS__)
22
+ #if defined(__APPLE__)
23
+ #define glfwGetCocoaWindow(...) IMGUI_RUBY_GLFW(glfwGetCocoaWindow, __VA_ARGS__)
24
+ #endif
25
+ #define glfwGetCursorPos(...) IMGUI_RUBY_GLFW(glfwGetCursorPos, __VA_ARGS__)
26
+ #define glfwGetError(...) IMGUI_RUBY_GLFW(glfwGetError, __VA_ARGS__)
27
+ #define glfwGetFramebufferSize(...) IMGUI_RUBY_GLFW(glfwGetFramebufferSize, __VA_ARGS__)
28
+ #define glfwGetGamepadState(...) IMGUI_RUBY_GLFW(glfwGetGamepadState, __VA_ARGS__)
29
+ #define glfwGetInputMode(...) IMGUI_RUBY_GLFW(glfwGetInputMode, __VA_ARGS__)
30
+ #define glfwGetJoystickAxes(...) IMGUI_RUBY_GLFW(glfwGetJoystickAxes, __VA_ARGS__)
31
+ #define glfwGetJoystickButtons(...) IMGUI_RUBY_GLFW(glfwGetJoystickButtons, __VA_ARGS__)
32
+ #define glfwGetKey(...) IMGUI_RUBY_GLFW(glfwGetKey, __VA_ARGS__)
33
+ #define glfwGetKeyName(...) IMGUI_RUBY_GLFW(glfwGetKeyName, __VA_ARGS__)
34
+ #define glfwGetMonitorContentScale(...) IMGUI_RUBY_GLFW(glfwGetMonitorContentScale, __VA_ARGS__)
35
+ #define glfwGetMonitorPos(...) IMGUI_RUBY_GLFW(glfwGetMonitorPos, __VA_ARGS__)
36
+ #define glfwGetMonitorWorkarea(...) IMGUI_RUBY_GLFW(glfwGetMonitorWorkarea, __VA_ARGS__)
37
+ #define glfwGetMonitors(...) IMGUI_RUBY_GLFW(glfwGetMonitors, __VA_ARGS__)
38
+ #define glfwGetTime(...) IMGUI_RUBY_GLFW(glfwGetTime, __VA_ARGS__)
39
+ #define glfwGetVideoMode(...) IMGUI_RUBY_GLFW(glfwGetVideoMode, __VA_ARGS__)
40
+ #if defined(_WIN32)
41
+ #define glfwGetWin32Window(...) IMGUI_RUBY_GLFW(glfwGetWin32Window, __VA_ARGS__)
42
+ #endif
43
+ #define glfwGetWindowAttrib(...) IMGUI_RUBY_GLFW(glfwGetWindowAttrib, __VA_ARGS__)
44
+ #define glfwGetWindowPos(...) IMGUI_RUBY_GLFW(glfwGetWindowPos, __VA_ARGS__)
45
+ #define glfwGetWindowSize(...) IMGUI_RUBY_GLFW(glfwGetWindowSize, __VA_ARGS__)
46
+ #define glfwMakeContextCurrent(...) IMGUI_RUBY_GLFW(glfwMakeContextCurrent, __VA_ARGS__)
47
+ #define glfwSetCharCallback(...) IMGUI_RUBY_GLFW(glfwSetCharCallback, __VA_ARGS__)
48
+ #define glfwSetClipboardString(...) IMGUI_RUBY_GLFW(glfwSetClipboardString, __VA_ARGS__)
49
+ #define glfwSetCursor(...) IMGUI_RUBY_GLFW(glfwSetCursor, __VA_ARGS__)
50
+ #define glfwSetCursorEnterCallback(...) IMGUI_RUBY_GLFW(glfwSetCursorEnterCallback, __VA_ARGS__)
51
+ #define glfwSetCursorPos(...) IMGUI_RUBY_GLFW(glfwSetCursorPos, __VA_ARGS__)
52
+ #define glfwSetCursorPosCallback(...) IMGUI_RUBY_GLFW(glfwSetCursorPosCallback, __VA_ARGS__)
53
+ #define glfwSetErrorCallback(...) IMGUI_RUBY_GLFW(glfwSetErrorCallback, __VA_ARGS__)
54
+ #define glfwSetInputMode(...) IMGUI_RUBY_GLFW(glfwSetInputMode, __VA_ARGS__)
55
+ #define glfwSetKeyCallback(...) IMGUI_RUBY_GLFW(glfwSetKeyCallback, __VA_ARGS__)
56
+ #define glfwSetMonitorCallback(...) IMGUI_RUBY_GLFW(glfwSetMonitorCallback, __VA_ARGS__)
57
+ #define glfwSetMouseButtonCallback(...) IMGUI_RUBY_GLFW(glfwSetMouseButtonCallback, __VA_ARGS__)
58
+ #define glfwSetScrollCallback(...) IMGUI_RUBY_GLFW(glfwSetScrollCallback, __VA_ARGS__)
59
+ #define glfwSetWindowAttrib(...) IMGUI_RUBY_GLFW(glfwSetWindowAttrib, __VA_ARGS__)
60
+ #define glfwSetWindowCloseCallback(...) IMGUI_RUBY_GLFW(glfwSetWindowCloseCallback, __VA_ARGS__)
61
+ #define glfwSetWindowFocusCallback(...) IMGUI_RUBY_GLFW(glfwSetWindowFocusCallback, __VA_ARGS__)
62
+ #define glfwSetWindowOpacity(...) IMGUI_RUBY_GLFW(glfwSetWindowOpacity, __VA_ARGS__)
63
+ #define glfwSetWindowPos(...) IMGUI_RUBY_GLFW(glfwSetWindowPos, __VA_ARGS__)
64
+ #define glfwSetWindowPosCallback(...) IMGUI_RUBY_GLFW(glfwSetWindowPosCallback, __VA_ARGS__)
65
+ #define glfwSetWindowSize(...) IMGUI_RUBY_GLFW(glfwSetWindowSize, __VA_ARGS__)
66
+ #define glfwSetWindowSizeCallback(...) IMGUI_RUBY_GLFW(glfwSetWindowSizeCallback, __VA_ARGS__)
67
+ #define glfwSetWindowTitle(...) IMGUI_RUBY_GLFW(glfwSetWindowTitle, __VA_ARGS__)
68
+ #define glfwShowWindow(...) IMGUI_RUBY_GLFW(glfwShowWindow, __VA_ARGS__)
69
+ #define glfwSwapBuffers(...) IMGUI_RUBY_GLFW(glfwSwapBuffers, __VA_ARGS__)
70
+ #define glfwSwapInterval(...) IMGUI_RUBY_GLFW(glfwSwapInterval, __VA_ARGS__)
71
+ #define glfwWindowHint(...) IMGUI_RUBY_GLFW(glfwWindowHint, __VA_ARGS__)
72
+
73
+ #include "imgui_impl_glfw.cpp"
@@ -0,0 +1,70 @@
1
+ #include <SDL3/SDL.h>
2
+ #include <SDL3/SDL_vulkan.h>
3
+
4
+ #include "backend_function_bridge.h"
5
+
6
+ #define IMGUI_RUBY_SDL3(function_name, ...) \
7
+ IMGUI_RUBY_BACKEND_CALL("SDL3", function_name, __VA_ARGS__)
8
+
9
+ #undef SDL_free
10
+ #undef SDL_strdup
11
+
12
+ #define SDL_CaptureMouse(...) IMGUI_RUBY_SDL3(SDL_CaptureMouse, __VA_ARGS__)
13
+ #define SDL_CloseGamepad(...) IMGUI_RUBY_SDL3(SDL_CloseGamepad, __VA_ARGS__)
14
+ #define SDL_CreateSystemCursor(...) IMGUI_RUBY_SDL3(SDL_CreateSystemCursor, __VA_ARGS__)
15
+ #define SDL_CreateWindow(...) IMGUI_RUBY_SDL3(SDL_CreateWindow, __VA_ARGS__)
16
+ #define SDL_DestroyCursor(...) IMGUI_RUBY_SDL3(SDL_DestroyCursor, __VA_ARGS__)
17
+ #define SDL_DestroyWindow(...) IMGUI_RUBY_SDL3(SDL_DestroyWindow, __VA_ARGS__)
18
+ #define SDL_GL_CreateContext(...) IMGUI_RUBY_SDL3(SDL_GL_CreateContext, __VA_ARGS__)
19
+ #define SDL_GL_DestroyContext(...) IMGUI_RUBY_SDL3(SDL_GL_DestroyContext, __VA_ARGS__)
20
+ #define SDL_GL_GetCurrentContext(...) IMGUI_RUBY_SDL3(SDL_GL_GetCurrentContext, __VA_ARGS__)
21
+ #define SDL_GL_MakeCurrent(...) IMGUI_RUBY_SDL3(SDL_GL_MakeCurrent, __VA_ARGS__)
22
+ #define SDL_GL_SetAttribute(...) IMGUI_RUBY_SDL3(SDL_GL_SetAttribute, __VA_ARGS__)
23
+ #define SDL_GL_SetSwapInterval(...) IMGUI_RUBY_SDL3(SDL_GL_SetSwapInterval, __VA_ARGS__)
24
+ #define SDL_GL_SwapWindow(...) IMGUI_RUBY_SDL3(SDL_GL_SwapWindow, __VA_ARGS__)
25
+ #define SDL_GetClipboardText(...) IMGUI_RUBY_SDL3(SDL_GetClipboardText, __VA_ARGS__)
26
+ #define SDL_GetCurrentVideoDriver(...) IMGUI_RUBY_SDL3(SDL_GetCurrentVideoDriver, __VA_ARGS__)
27
+ #define SDL_GetDisplayBounds(...) IMGUI_RUBY_SDL3(SDL_GetDisplayBounds, __VA_ARGS__)
28
+ #define SDL_GetDisplayContentScale(...) IMGUI_RUBY_SDL3(SDL_GetDisplayContentScale, __VA_ARGS__)
29
+ #define SDL_GetDisplayUsableBounds(...) IMGUI_RUBY_SDL3(SDL_GetDisplayUsableBounds, __VA_ARGS__)
30
+ #define SDL_GetDisplays(...) IMGUI_RUBY_SDL3(SDL_GetDisplays, __VA_ARGS__)
31
+ #define SDL_GetGamepadAxis(...) IMGUI_RUBY_SDL3(SDL_GetGamepadAxis, __VA_ARGS__)
32
+ #define SDL_GetGamepadButton(...) IMGUI_RUBY_SDL3(SDL_GetGamepadButton, __VA_ARGS__)
33
+ #define SDL_GetGamepads(...) IMGUI_RUBY_SDL3(SDL_GetGamepads, __VA_ARGS__)
34
+ #define SDL_GetGlobalMouseState(...) IMGUI_RUBY_SDL3(SDL_GetGlobalMouseState, __VA_ARGS__)
35
+ #define SDL_GetKeyboardFocus(...) IMGUI_RUBY_SDL3(SDL_GetKeyboardFocus, __VA_ARGS__)
36
+ #define SDL_GetPerformanceCounter(...) IMGUI_RUBY_SDL3(SDL_GetPerformanceCounter, __VA_ARGS__)
37
+ #define SDL_GetPerformanceFrequency(...) IMGUI_RUBY_SDL3(SDL_GetPerformanceFrequency, __VA_ARGS__)
38
+ #define SDL_GetPointerProperty(...) IMGUI_RUBY_SDL3(SDL_GetPointerProperty, __VA_ARGS__)
39
+ #define SDL_GetWindowFlags(...) IMGUI_RUBY_SDL3(SDL_GetWindowFlags, __VA_ARGS__)
40
+ #define SDL_GetWindowFromID(...) IMGUI_RUBY_SDL3(SDL_GetWindowFromID, __VA_ARGS__)
41
+ #define SDL_GetWindowID(...) IMGUI_RUBY_SDL3(SDL_GetWindowID, __VA_ARGS__)
42
+ #define SDL_GetWindowPosition(...) IMGUI_RUBY_SDL3(SDL_GetWindowPosition, __VA_ARGS__)
43
+ #define SDL_GetWindowProperties(...) IMGUI_RUBY_SDL3(SDL_GetWindowProperties, __VA_ARGS__)
44
+ #define SDL_GetWindowRelativeMouseMode(...) IMGUI_RUBY_SDL3(SDL_GetWindowRelativeMouseMode, __VA_ARGS__)
45
+ #define SDL_GetWindowSize(...) IMGUI_RUBY_SDL3(SDL_GetWindowSize, __VA_ARGS__)
46
+ #define SDL_GetWindowSizeInPixels(...) IMGUI_RUBY_SDL3(SDL_GetWindowSizeInPixels, __VA_ARGS__)
47
+ #define SDL_HideCursor(...) IMGUI_RUBY_SDL3(SDL_HideCursor, __VA_ARGS__)
48
+ #define SDL_OpenGamepad(...) IMGUI_RUBY_SDL3(SDL_OpenGamepad, __VA_ARGS__)
49
+ #define SDL_OpenURL(...) IMGUI_RUBY_SDL3(SDL_OpenURL, __VA_ARGS__)
50
+ #define SDL_RaiseWindow(...) IMGUI_RUBY_SDL3(SDL_RaiseWindow, __VA_ARGS__)
51
+ #define SDL_SetClipboardText(...) IMGUI_RUBY_SDL3(SDL_SetClipboardText, __VA_ARGS__)
52
+ #define SDL_SetCursor(...) IMGUI_RUBY_SDL3(SDL_SetCursor, __VA_ARGS__)
53
+ #define SDL_SetHint(...) IMGUI_RUBY_SDL3(SDL_SetHint, __VA_ARGS__)
54
+ #define SDL_SetTextInputArea(...) IMGUI_RUBY_SDL3(SDL_SetTextInputArea, __VA_ARGS__)
55
+ #define SDL_SetWindowOpacity(...) IMGUI_RUBY_SDL3(SDL_SetWindowOpacity, __VA_ARGS__)
56
+ #define SDL_SetWindowParent(...) IMGUI_RUBY_SDL3(SDL_SetWindowParent, __VA_ARGS__)
57
+ #define SDL_SetWindowPosition(...) IMGUI_RUBY_SDL3(SDL_SetWindowPosition, __VA_ARGS__)
58
+ #define SDL_SetWindowSize(...) IMGUI_RUBY_SDL3(SDL_SetWindowSize, __VA_ARGS__)
59
+ #define SDL_SetWindowTitle(...) IMGUI_RUBY_SDL3(SDL_SetWindowTitle, __VA_ARGS__)
60
+ #define SDL_ShowCursor(...) IMGUI_RUBY_SDL3(SDL_ShowCursor, __VA_ARGS__)
61
+ #define SDL_ShowWindow(...) IMGUI_RUBY_SDL3(SDL_ShowWindow, __VA_ARGS__)
62
+ #define SDL_StartTextInput(...) IMGUI_RUBY_SDL3(SDL_StartTextInput, __VA_ARGS__)
63
+ #define SDL_StopTextInput(...) IMGUI_RUBY_SDL3(SDL_StopTextInput, __VA_ARGS__)
64
+ #define SDL_Vulkan_CreateSurface(...) IMGUI_RUBY_SDL3(SDL_Vulkan_CreateSurface, __VA_ARGS__)
65
+ #define SDL_WarpMouseGlobal(...) IMGUI_RUBY_SDL3(SDL_WarpMouseGlobal, __VA_ARGS__)
66
+ #define SDL_WarpMouseInWindow(...) IMGUI_RUBY_SDL3(SDL_WarpMouseInWindow, __VA_ARGS__)
67
+ #define SDL_free(...) IMGUI_RUBY_SDL3(SDL_free, __VA_ARGS__)
68
+ #define SDL_strdup(...) IMGUI_RUBY_SDL3(SDL_strdup, __VA_ARGS__)
69
+
70
+ #include "imgui_impl_sdl3.cpp"
@@ -0,0 +1,75 @@
1
+ #include "imgui.h"
2
+ #include "backends/imgui_impl_wgpu.h"
3
+
4
+ #include <webgpu/webgpu.h>
5
+
6
+ #if defined(_WIN32)
7
+ #define IMGUI_RUBY_EXPORT __declspec(dllexport)
8
+ #else
9
+ #define IMGUI_RUBY_EXPORT __attribute__((visibility("default")))
10
+ #endif
11
+
12
+ extern "C" {
13
+
14
+ IMGUI_RUBY_EXPORT bool imgui_ruby_wgpu_init(
15
+ void* device,
16
+ int frames_in_flight,
17
+ int render_target_format,
18
+ int depth_format,
19
+ unsigned int sample_count,
20
+ unsigned int sample_mask,
21
+ bool alpha_to_coverage) {
22
+ ImGui_ImplWGPU_InitInfo info = {};
23
+ info.Device = static_cast<WGPUDevice>(device);
24
+ info.NumFramesInFlight = frames_in_flight;
25
+ info.RenderTargetFormat = static_cast<WGPUTextureFormat>(render_target_format);
26
+ info.DepthStencilFormat = static_cast<WGPUTextureFormat>(depth_format);
27
+ info.PipelineMultisampleState.count = sample_count;
28
+ info.PipelineMultisampleState.mask = sample_mask;
29
+ info.PipelineMultisampleState.alphaToCoverageEnabled = alpha_to_coverage;
30
+ return ImGui_ImplWGPU_Init(&info);
31
+ }
32
+
33
+ IMGUI_RUBY_EXPORT void imgui_ruby_wgpu_shutdown() {
34
+ ImGui_ImplWGPU_Shutdown();
35
+ }
36
+
37
+ IMGUI_RUBY_EXPORT void imgui_ruby_wgpu_new_frame() {
38
+ ImGui_ImplWGPU_NewFrame();
39
+ }
40
+
41
+ IMGUI_RUBY_EXPORT void imgui_ruby_wgpu_render_draw_data(
42
+ ImDrawData* draw_data,
43
+ void* render_pass_encoder) {
44
+ ImGui_ImplWGPU_RenderDrawData(
45
+ draw_data,
46
+ static_cast<WGPURenderPassEncoder>(render_pass_encoder));
47
+ }
48
+
49
+ IMGUI_RUBY_EXPORT bool imgui_ruby_wgpu_render_draw_data_to_view(
50
+ ImDrawData* draw_data,
51
+ void* command_encoder,
52
+ void* target_view) {
53
+ WGPURenderPassColorAttachment color_attachment = {};
54
+ color_attachment.view = static_cast<WGPUTextureView>(target_view);
55
+ color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
56
+ color_attachment.loadOp = WGPULoadOp_Load;
57
+ color_attachment.storeOp = WGPUStoreOp_Store;
58
+
59
+ WGPURenderPassDescriptor descriptor = {};
60
+ descriptor.colorAttachmentCount = 1;
61
+ descriptor.colorAttachments = &color_attachment;
62
+ WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(
63
+ static_cast<WGPUCommandEncoder>(command_encoder),
64
+ &descriptor);
65
+ if (!pass) {
66
+ return false;
67
+ }
68
+
69
+ ImGui_ImplWGPU_RenderDrawData(draw_data, pass);
70
+ wgpuRenderPassEncoderEnd(pass);
71
+ wgpuRenderPassEncoderRelease(pass);
72
+ return true;
73
+ }
74
+
75
+ }
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "rbconfig"
5
+
6
+ source_dir, ruby_arch_dir = ARGV
7
+ raise ArgumentError, "source and Ruby architecture directories are required" unless source_dir && ruby_arch_dir
8
+
9
+ library = Dir.glob(File.join(source_dir, "*cimgui_ruby.{so,dylib,dll}")).first
10
+ raise "built cimgui library was not found in #{source_dir}" unless library
11
+
12
+ host_os = RbConfig::CONFIG.fetch("host_os")
13
+ platform_os = if host_os.include?("darwin")
14
+ "darwin"
15
+ elsif host_os.match?(/mswin|mingw/)
16
+ "windows"
17
+ else
18
+ "linux"
19
+ end
20
+ host_cpu = RbConfig::CONFIG.fetch("host_cpu")
21
+ platform_cpu = host_cpu == "arm64" ? "aarch64" : host_cpu
22
+ destination = File.join(ruby_arch_dir, "imgui", "vendor", "#{platform_cpu}-#{platform_os}")
23
+
24
+ FileUtils.mkdir_p(destination)
25
+ FileUtils.cp(library, destination)