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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5db61cd5cd40e3d068a5c8144fe6edcaa2f5a2be978aa621b479af946e83f1b3
4
+ data.tar.gz: fc7ed9985b2a2c5b3fcc4cb61e78b7d0d133de5ccc44be361216e8f96701f9d6
5
+ SHA512:
6
+ metadata.gz: a5bb6a0cdb519cdf4c7090dea048b8b51be6b290411da1dd54c37c0fd36a300ac235c69709fe9bb2bdf715b48ca53a1d4761da7e09340ffb5335d65f9e66c76b
7
+ data.tar.gz: 99dc01926644a20bdc35894e60b7cc05001476d7f3f393bf56e71d558606465d761964bd8aa23c461e926cc459898d9de9de9fb6201c7ef7410e25c0e372900e
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Yudai Takada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,273 @@
1
+ # imgui-ruby
2
+
3
+ Ruby bindings for [Dear ImGui](https://github.com/ocornut/imgui) through
4
+ [cimgui](https://github.com/cimgui/cimgui) and FFI. The binding targets Dear
5
+ ImGui 1.91.9 from the docking branch and is generated from cimgui metadata.
6
+ Version 1 freezes the idiomatic Ruby, DSL, backend, and ImPlot method
7
+ signatures in [`api/v1.json`](api/v1.json).
8
+
9
+ The API has three layers:
10
+
11
+ ```ruby
12
+ ImGui::Native.igButton("OK", ImGui::Native::ImVec2.new) # generated C API
13
+ ImGui.button("OK") # idiomatic Ruby API
14
+ ImGui.window("Debug") { ImGui.text("hello") } # exception-safe DSL
15
+ ```
16
+
17
+ ## Installation
18
+
19
+ Add the gem to your bundle:
20
+
21
+ ```bash
22
+ bundle add imgui-ruby
23
+ ```
24
+
25
+ The source gem needs CMake and a C++17 compiler. Platform gems for x86_64 and
26
+ Arm64 Linux, Intel and Arm64 macOS, and x64 Windows contain a prebuilt
27
+ `libcimgui_ruby` and do not compile during installation. The only required
28
+ runtime dependency is `ffi`; `glfw-ruby`, `sdl3`, and `wgpu` are optional and
29
+ needed only by their respective backends.
30
+
31
+ To use a custom native build, set its full path before requiring the gem:
32
+
33
+ ```bash
34
+ IMGUI_RUBY_LIB=/opt/imgui/libcimgui_ruby.so ruby app.rb
35
+ ```
36
+
37
+ ## Basic OpenGL/GLFW loop
38
+
39
+ ```ruby
40
+ require "imgui"
41
+ require "glfw"
42
+
43
+ context = ImGui.create_context
44
+ io = ImGui.io
45
+ io.config_flags |= ImGui::ConfigFlags::DockingEnable
46
+ io.fonts.add_font_jp("assets/NotoSansJP-Regular.ttf", size: 18)
47
+
48
+ ImGui::Backends::Glfw.init_for_opengl(window.handle, install_callbacks: true)
49
+ ImGui::Backends::OpenGL3.init("#version 330")
50
+
51
+ until window.should_close?
52
+ GLFW.poll_events
53
+ ImGui::Backends::OpenGL3.new_frame
54
+ ImGui::Backends::Glfw.new_frame
55
+ ImGui.new_frame
56
+
57
+ ImGui.window("Stats") do
58
+ ImGui.text("fps: %.1f", io.framerate)
59
+ ImGui.separator
60
+ ImGui.button("Reset")
61
+ end
62
+
63
+ ImGui.render
64
+ ImGui::Backends::OpenGL3.render_draw_data(ImGui.draw_data)
65
+ window.swap_buffers
66
+ end
67
+
68
+ ImGui::Backends::OpenGL3.shutdown
69
+ ImGui::Backends::Glfw.shutdown
70
+ ImGui.destroy_context(context)
71
+ ```
72
+
73
+ `ImGui.frame` performs the three `new_frame` calls, yields the UI block, then
74
+ renders DrawData. `ImGui.easy_loop` additionally owns the window loop and swaps
75
+ buffers when the window object supports it.
76
+
77
+ ## Values and output arguments
78
+
79
+ Passing a Ruby value returns `[changed, value]`:
80
+
81
+ ```ruby
82
+ changed, speed = ImGui.slider_float("Speed", speed, 0.0, 10.0)
83
+ changed, tint = ImGui.color_edit3("Tint", tint)
84
+ ```
85
+
86
+ `ImGui::Value` owns stable native memory and is updated in place:
87
+
88
+ ```ruby
89
+ speed = ImGui::Value.float(1.0)
90
+ open = ImGui::Value.bool(true)
91
+ name = ImGui::Value.text("Player", capacity: 256)
92
+
93
+ ImGui.slider_float("Speed", speed, 0.0, 10.0)
94
+ ImGui.checkbox("Open", open)
95
+ ImGui.input_text("Name", name)
96
+ ```
97
+
98
+ The available types are `bool`, `int`, `float`, `vec2`, `vec3`, `vec4`, and
99
+ `text`.
100
+
101
+ ## Block DSL
102
+
103
+ Begin/End pairs have different native contracts. The DSL calls the matching
104
+ End or Pop under the correct condition and uses `ensure`, so Ruby exceptions do
105
+ not corrupt the ImGui stack.
106
+
107
+ ```ruby
108
+ ImGui.window("Inspector") do
109
+ ImGui.menu_bar do
110
+ ImGui.menu("File") { ImGui.menu_item("Close") }
111
+ end
112
+
113
+ ImGui.tree_node("Renderer") do
114
+ ImGui.style_color(ImGui::Col::Text, [1, 0.4, 0.2, 1]) do
115
+ ImGui.text("draw calls: %d", draw_calls)
116
+ end
117
+ end
118
+ end
119
+ ```
120
+
121
+ Blockless calls return the native Begin result for manual control. Close them
122
+ with the matching method, such as `end_window`, `end_table`, `tree_pop`, or the
123
+ generic `close_scope`. A mismatched close raises `ImGui::StackError`.
124
+
125
+ ## Fonts and retained strings
126
+
127
+ `io.fonts.add_font_jp` uses Dear ImGui's Japanese glyph range. Pass
128
+ `merge: true` to merge an icon font. Dear ImGui retains `IniFilename` and
129
+ `LogFilename` pointers, so assign them through `ImGui.ini_filename=` or the IO
130
+ wrapper; imgui-ruby retains the backing memory for the context lifetime.
131
+
132
+ ```ruby
133
+ ImGui.ini_filename = "settings/imgui.ini"
134
+ ImGui.io.log_filename = nil
135
+ ```
136
+
137
+ ## Thread safety
138
+
139
+ Contexts are owned by the thread that first uses or creates them. Layer 2 and
140
+ the DSL raise `ImGui::ThreadError` when a context is used from another thread.
141
+ `ImGui.unsafe_allow_threads!` disables this guard for applications that provide
142
+ their own synchronization; `ImGui.enforce_thread_safety!` restores it.
143
+
144
+ ## Backends
145
+
146
+ The native build can include GLFW, OpenGL3, and SDL3 wrappers. Select source
147
+ build backends with a comma-separated environment variable:
148
+
149
+ ```bash
150
+ IMGUI_RUBY_BACKENDS=glfw,opengl3 bundle exec rake native:build
151
+ ```
152
+
153
+ Backend symbols are resolved on first use, so a core-only library remains
154
+ usable for headless operation. Calling a backend omitted from the native
155
+ library raises `ImGui::BackendUnavailableError`. GLFW and SDL3 calls use a
156
+ validated runtime loader on every supported OS, so the native gem does not
157
+ link either optional library. WebGPU uses an explicit function table and does
158
+ not link against a particular wgpu-native release.
159
+
160
+ ### SDL3
161
+
162
+ The SDL3 adapter supports OpenGL, Vulkan, D3D, Metal, SDL_Renderer, SDL_GPU,
163
+ and renderer-independent initialization. Forward each polled event before the
164
+ frame begins:
165
+
166
+ ```ruby
167
+ require "sdl3"
168
+ require "imgui"
169
+
170
+ SDL3.init(SDL3::INIT_VIDEO | SDL3::INIT_GAMEPAD)
171
+ window = SDL3::Window.new("ImGui", 1280, 720)
172
+ context = ImGui.create_context
173
+
174
+ ImGui::Backends::SDL3.init_for_other(window.ptr)
175
+ ImGui::Backends::SDL3.set_gamepad_mode(:auto_first)
176
+
177
+ # SDL3 event loop:
178
+ # ImGui::Backends::SDL3.process_event(event.raw)
179
+ ImGui::Backends::SDL3.new_frame
180
+ ImGui.new_frame
181
+ ImGui.window("SDL3") { ImGui.text("ready") }
182
+ ImGui.render
183
+
184
+ ImGui::Backends::SDL3.shutdown
185
+ ImGui.destroy_context(context)
186
+ window.destroy
187
+ SDL3.quit
188
+ ```
189
+
190
+ ### WGPU and stagecraft-style renderers
191
+
192
+ `WGPU.init` accepts objects exposing `#handle`/`#to_ptr` and discovers the
193
+ wgpu-native function table from the device, or accepts `function_table:` or
194
+ `library_path:` explicitly. Passing an encoder and target view creates an
195
+ overlay render pass; passing an existing render pass records directly into it.
196
+
197
+ ```ruby
198
+ ImGui::Backends::WGPU.init(
199
+ device: renderer.device,
200
+ queue: renderer.queue,
201
+ render_target_format: renderer.surface_format,
202
+ depth_format: nil,
203
+ frames_in_flight: 3
204
+ )
205
+
206
+ renderer.on_after_render do |encoder, target_view|
207
+ ImGui::Backends::WGPU.render_draw_data(ImGui.draw_data, encoder, target_view)
208
+ end
209
+ ```
210
+
211
+ ## ImPlot
212
+
213
+ ImPlot is opt-in at the Ruby level and shares the bundled native library:
214
+
215
+ ```ruby
216
+ require "imgui/plot"
217
+
218
+ plot_context = ImPlot.create_context
219
+ ImPlot.plot("Frame time") do
220
+ ImPlot.setup_axes("frame", "ms")
221
+ ImPlot.plot_line("CPU", [4.1, 3.8, 5.0, 4.4])
222
+ ImPlot.plot_scatter("samples", [4.1, 3.8], xs: [1.0, 2.0])
223
+ end
224
+ ImPlot.destroy_context(plot_context)
225
+ ```
226
+
227
+ Line, scatter, stairs, bars, and histogram helpers accept Ruby numeric arrays.
228
+
229
+ ## Development
230
+
231
+ Native dependency sources are not stored in Git. Their revisions and SHA-256
232
+ checksums are pinned in `generator/native-dependencies.yml`; the first native
233
+ build or generation downloads a minimal snapshot into the ignored `tmp/vendor`
234
+ cache. Install dependencies, fetch the cache, then run the suites:
235
+
236
+ ```bash
237
+ bundle install
238
+ bundle exec rake vendor:fetch
239
+ bundle exec rake vendor:verify
240
+ bundle exec rake
241
+ bundle exec rake native:spec
242
+ bundle exec rake native:audit
243
+ ```
244
+
245
+ Regenerate all committed Native files and the snake_case Layer 2 surface with:
246
+
247
+ ```bash
248
+ bundle exec rake generate
249
+ ```
250
+
251
+ `vendor:fetch` uses a valid cache without network access and otherwise downloads
252
+ the pinned revisions. `vendor:verify` performs an offline file and checksum
253
+ audit, while `vendor:update` advances the configured upstream branches and
254
+ updates their checksums.
255
+
256
+ `native:spec` builds cimgui and executes two real headless frames.
257
+ `native:audit` builds every supported backend and attaches all generated
258
+ symbols. `native:integration` runs GLFW/OpenGL3, SDL3, and WGPU integration
259
+ frames when the optional gems and system libraries are installed. To build the
260
+ source gem use `bundle exec rake build`; `bundle exec rake gem:platform`
261
+ builds a gem containing the native library for the current platform. Source gem
262
+ packaging stages only the native files needed for an offline extension build;
263
+ platform gems contain no native source snapshots.
264
+
265
+ The weekly update workflow refreshes the dependency cache and lock data, regenerates the
266
+ bindings, and opens a pull request only after the compatibility and native
267
+ suites pass. Tagged releases build all platform gems and use RubyGems trusted
268
+ publishing; repository maintainers must register `release.yml` and the
269
+ `release` environment as a trusted publisher before the first release.
270
+
271
+ ## License
272
+
273
+ imgui-ruby, Dear ImGui, and cimgui are available under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rbconfig"
6
+
7
+ desc "Generate FFI declarations from cimgui metadata"
8
+ task generate: "vendor:fetch" do
9
+ ruby File.expand_path("generator/generate.rb", __dir__)
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task default: :spec
15
+
16
+ namespace :vendor do
17
+ desc "Fetch the pinned native dependencies when the cache is missing"
18
+ task :fetch do
19
+ ruby File.expand_path("generator/update_vendor.rb", __dir__)
20
+ end
21
+
22
+ desc "Verify the cached native dependency snapshots"
23
+ task :verify do
24
+ ruby File.expand_path("generator/update_vendor.rb", __dir__), "--verify"
25
+ end
26
+
27
+ desc "Update cached native dependencies from their configured branches"
28
+ task :update do
29
+ ruby File.expand_path("generator/update_vendor.rb", __dir__), "--latest"
30
+ end
31
+ end
32
+
33
+ namespace :native do
34
+ build_root = File.expand_path("tmp/native-build", __dir__)
35
+ install_root = File.expand_path("tmp/native-install", __dir__)
36
+
37
+ desc "Build the cached cimgui library"
38
+ task build: "vendor:fetch" do
39
+ require_relative "ext/build_cimgui"
40
+
41
+ ImGuiRuby::NativeBuilder.new(
42
+ source_dir: File.expand_path("ext", __dir__),
43
+ build_dir: build_root,
44
+ install_dir: install_root
45
+ ).build!
46
+ end
47
+
48
+ desc "Build cimgui and run a real headless ImGui frame"
49
+ task spec: :build do
50
+ library = Dir.glob(File.join(install_root, "*cimgui_ruby.{so,dylib,dll}")).first
51
+ raise "built cimgui library was not found" unless library
52
+
53
+ previous_library = ENV["IMGUI_RUBY_LIB"]
54
+ ENV["IMGUI_RUBY_LIB"] = library
55
+ ruby "-Ilib", "spec/native_smoke.rb"
56
+ ensure
57
+ ENV["IMGUI_RUBY_LIB"] = previous_library
58
+ end
59
+
60
+
61
+ desc "Build all supported backends and attach every generated native function"
62
+ task :audit do
63
+ previous_backends = ENV["IMGUI_RUBY_BACKENDS"]
64
+ ENV["IMGUI_RUBY_BACKENDS"] = "glfw,opengl3,sdl3,wgpu"
65
+ Rake::Task["native:build"].invoke
66
+ library = Dir.glob(File.join(install_root, "*cimgui_ruby.{so,dylib,dll}")).first
67
+ raise "built cimgui library was not found" unless library
68
+
69
+ previous_library = ENV["IMGUI_RUBY_LIB"]
70
+ ENV["IMGUI_RUBY_LIB"] = library
71
+ ruby "-Ilib", "spec/native_symbol_audit.rb"
72
+ ensure
73
+ ENV["IMGUI_RUBY_BACKENDS"] = previous_backends
74
+ ENV["IMGUI_RUBY_LIB"] = previous_library
75
+ end
76
+
77
+ desc "Run GLFW/OpenGL3, SDL3, and WGPU backend integration frames"
78
+ task :integration do
79
+ previous_backends = ENV["IMGUI_RUBY_BACKENDS"]
80
+ ENV["IMGUI_RUBY_BACKENDS"] = "glfw,opengl3,sdl3,wgpu"
81
+ Rake::Task["native:build"].invoke
82
+ library = Dir.glob(File.join(install_root, "*cimgui_ruby.{so,dylib,dll}")).first
83
+ raise "built cimgui library was not found" unless library
84
+
85
+ require "bundler"
86
+ Bundler.with_unbundled_env do
87
+ sh({ "IMGUI_RUBY_LIB" => library, "IMGUI_RUBY_REQUIRE_GLFW" => "1" },
88
+ RbConfig.ruby, "-Ilib", "spec/glfw_opengl_smoke.rb")
89
+ sh({ "IMGUI_RUBY_LIB" => library, "IMGUI_RUBY_REQUIRE_SDL3" => "1" },
90
+ RbConfig.ruby, "-Ilib", "spec/sdl3_smoke.rb")
91
+ sh({ "IMGUI_RUBY_LIB" => library },
92
+ RbConfig.ruby, "-Ilib", "spec/wgpu_smoke.rb")
93
+ end
94
+ ensure
95
+ ENV["IMGUI_RUBY_BACKENDS"] = previous_backends
96
+ end
97
+ end
data/api/v1.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "schema_version": 1,
3
+ "surfaces": {
4
+ "ImGui": {
5
+ "method_count": 387,
6
+ "sha256": "2a530e9c72597da0b6095c9a71626fc379c354d596acd0b02946a1069419844c"
7
+ },
8
+ "ImPlot": {
9
+ "method_count": 21,
10
+ "sha256": "d17bd05b4d1f92b4a2c12af3ebacead53d4c8c3d73c969b7b1b170a259e1e702"
11
+ },
12
+ "ImGui::Backends::Glfw": {
13
+ "method_count": 8,
14
+ "sha256": "7fe06d1fe8a70fc5da9506aa35781aee9c93b27886bd1a980109c5e702b8e621"
15
+ },
16
+ "ImGui::Backends": {
17
+ "method_count": 3,
18
+ "sha256": "7da32543c540d627d33ebd0bf0826cebf3ef7ebadc55391c6c38d1ec98fca320"
19
+ },
20
+ "ImGui::Backends::OpenGL3": {
21
+ "method_count": 8,
22
+ "sha256": "e4c26cc73c9536480f28cac617206774aff663e571979ab0a1e2c87ab593a803"
23
+ },
24
+ "ImGui::Backends::SDL3": {
25
+ "method_count": 12,
26
+ "sha256": "b125914e0fb9a73aa36fded3c308c67395a564759d521b72a5e03a3f91bf644a"
27
+ },
28
+ "ImGui::Backends::WGPU": {
29
+ "method_count": 5,
30
+ "sha256": "b84c3315a395d4086fd34f6bd3af3a1d743c51423bac80c8da84dbf60167ab9d"
31
+ },
32
+ "ImGui::IO": {
33
+ "method_count": 40,
34
+ "sha256": "f7718b34d921f9358a6e982694f2b18998dab1885c465693e81bfe94c2f5fe4f"
35
+ },
36
+ "ImGui::Style": {
37
+ "method_count": 8,
38
+ "sha256": "45e66164917622943d3318bc0b65230eee280061d4a191a5860d9b897c7a8110"
39
+ },
40
+ "ImGui::Fonts": {
41
+ "method_count": 6,
42
+ "sha256": "8185515769a642357bb4b10165ce862a264a87f674cd453233cb8f4293aacfa1"
43
+ },
44
+ "ImGui::DrawData": {
45
+ "method_count": 10,
46
+ "sha256": "1bc1067e5e8fe91bd3b438e1391913164681b35af9cdd60059d5fabf360ec8f8"
47
+ },
48
+ "ImGui::Value": {
49
+ "method_count": 6,
50
+ "sha256": "edb310c84ff76eca385fd5634b960f9b95245a42498fecbbe0570202a38cc799"
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,128 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+ project(cimgui_ruby LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 17)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7
+
8
+ option(IMGUI_RUBY_WITH_GLFW "Compile the Dear ImGui GLFW backend" OFF)
9
+ option(IMGUI_RUBY_WITH_OPENGL3 "Compile the Dear ImGui OpenGL3 backend" OFF)
10
+ option(IMGUI_RUBY_WITH_SDL3 "Compile the Dear ImGui SDL3 backend" OFF)
11
+ option(IMGUI_RUBY_WITH_IMPLOT "Compile the bundled ImPlot extension" ON)
12
+ option(IMGUI_RUBY_WITH_WGPU "Compile the Dear ImGui WebGPU backend" OFF)
13
+
14
+ get_filename_component(IMGUI_RUBY_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
15
+ set(IMGUI_RUBY_VENDOR_DIR "" CACHE PATH "Directory containing native dependency sources")
16
+ if(NOT IMGUI_RUBY_VENDOR_DIR)
17
+ if(EXISTS "${IMGUI_RUBY_ROOT}/vendor-src")
18
+ set(IMGUI_RUBY_VENDOR_DIR "${IMGUI_RUBY_ROOT}/vendor-src")
19
+ else()
20
+ set(IMGUI_RUBY_VENDOR_DIR "${IMGUI_RUBY_ROOT}/tmp/vendor")
21
+ endif()
22
+ endif()
23
+
24
+ set(CIMGUI_DIR "${IMGUI_RUBY_VENDOR_DIR}/cimgui")
25
+ set(IMGUI_DIR "${CIMGUI_DIR}/imgui")
26
+ set(CIMPLOT_DIR "${IMGUI_RUBY_VENDOR_DIR}/cimplot")
27
+ set(SDL_DIR "${IMGUI_RUBY_VENDOR_DIR}/sdl")
28
+ set(WEBGPU_HEADERS_DIR "${IMGUI_RUBY_VENDOR_DIR}")
29
+
30
+ if(NOT EXISTS "${CIMGUI_DIR}/cimgui.cpp")
31
+ message(FATAL_ERROR "cimgui source is missing; run bundle exec rake vendor:fetch")
32
+ endif()
33
+
34
+ set(IMGUI_RUBY_SOURCES
35
+ "${CIMGUI_DIR}/cimgui.cpp"
36
+ "${IMGUI_DIR}/imgui.cpp"
37
+ "${IMGUI_DIR}/imgui_draw.cpp"
38
+ "${IMGUI_DIR}/imgui_tables.cpp"
39
+ "${IMGUI_DIR}/imgui_widgets.cpp"
40
+ "${IMGUI_DIR}/imgui_demo.cpp"
41
+ )
42
+
43
+ set(IMGUI_RUBY_BACKEND_DEFINITIONS)
44
+ if(IMGUI_RUBY_WITH_IMPLOT)
45
+ if(NOT EXISTS "${CIMPLOT_DIR}/cimplot.cpp")
46
+ message(FATAL_ERROR "cimplot source is missing; run bundle exec rake vendor:fetch")
47
+ endif()
48
+ list(APPEND IMGUI_RUBY_SOURCES
49
+ "${CIMPLOT_DIR}/cimplot.cpp"
50
+ "${CIMPLOT_DIR}/implot/implot.cpp"
51
+ "${CIMPLOT_DIR}/implot/implot_demo.cpp"
52
+ "${CIMPLOT_DIR}/implot/implot_items.cpp"
53
+ )
54
+ endif()
55
+
56
+ if(IMGUI_RUBY_WITH_GLFW)
57
+ list(APPEND IMGUI_RUBY_SOURCES
58
+ "${CMAKE_CURRENT_LIST_DIR}/backend_function_bridge.cpp"
59
+ "${CMAKE_CURRENT_LIST_DIR}/glfw_vulkan_bridge.cpp"
60
+ "${CMAKE_CURRENT_LIST_DIR}/imgui_ruby_glfw.cpp"
61
+ "${CIMGUI_DIR}/cimgui_impl.cpp"
62
+ )
63
+ list(APPEND IMGUI_RUBY_BACKEND_DEFINITIONS CIMGUI_USE_GLFW)
64
+ endif()
65
+
66
+ if(IMGUI_RUBY_WITH_OPENGL3)
67
+ list(APPEND IMGUI_RUBY_SOURCES
68
+ "${CIMGUI_DIR}/cimgui_impl.cpp"
69
+ "${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp"
70
+ )
71
+ list(APPEND IMGUI_RUBY_BACKEND_DEFINITIONS CIMGUI_USE_OPENGL3)
72
+ endif()
73
+
74
+ if(IMGUI_RUBY_WITH_SDL3)
75
+ if(NOT EXISTS "${SDL_DIR}/include/SDL3/SDL.h")
76
+ message(FATAL_ERROR "SDL headers are missing; run bundle exec rake vendor:fetch")
77
+ endif()
78
+ list(APPEND IMGUI_RUBY_SOURCES
79
+ "${CMAKE_CURRENT_LIST_DIR}/backend_function_bridge.cpp"
80
+ "${CMAKE_CURRENT_LIST_DIR}/imgui_ruby_sdl3.cpp"
81
+ "${CIMGUI_DIR}/cimgui_impl.cpp"
82
+ )
83
+ list(APPEND IMGUI_RUBY_BACKEND_DEFINITIONS CIMGUI_USE_SDL3)
84
+ endif()
85
+
86
+ if(IMGUI_RUBY_WITH_WGPU)
87
+ if(NOT EXISTS "${WEBGPU_HEADERS_DIR}/webgpu/webgpu.h")
88
+ message(FATAL_ERROR "WebGPU headers are missing; run bundle exec rake vendor:fetch")
89
+ endif()
90
+ list(APPEND IMGUI_RUBY_SOURCES
91
+ "${CMAKE_CURRENT_LIST_DIR}/imgui_ruby_wgpu.cpp"
92
+ "${CMAKE_CURRENT_LIST_DIR}/webgpu_function_bridge.cpp"
93
+ "${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp"
94
+ )
95
+ list(APPEND IMGUI_RUBY_BACKEND_DEFINITIONS IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
96
+ endif()
97
+
98
+ list(REMOVE_DUPLICATES IMGUI_RUBY_SOURCES)
99
+ add_library(cimgui_ruby SHARED ${IMGUI_RUBY_SOURCES})
100
+ set(IMGUI_RUBY_BUILD_CONFIG "${CMAKE_CURRENT_LIST_DIR}/imgui_ruby_build_config.h")
101
+ if(MSVC)
102
+ target_compile_options(cimgui_ruby PRIVATE "/FI${IMGUI_RUBY_BUILD_CONFIG}")
103
+ else()
104
+ target_compile_options(cimgui_ruby PRIVATE "-include${IMGUI_RUBY_BUILD_CONFIG}")
105
+ endif()
106
+ target_include_directories(cimgui_ruby PRIVATE
107
+ "${CIMGUI_DIR}"
108
+ "${IMGUI_DIR}"
109
+ "${IMGUI_DIR}/backends"
110
+ "${IMGUI_DIR}/examples/libs/glfw/include"
111
+ "${CIMPLOT_DIR}"
112
+ "${CIMPLOT_DIR}/implot"
113
+ "${SDL_DIR}/include"
114
+ "${WEBGPU_HEADERS_DIR}"
115
+ )
116
+ target_compile_definitions(cimgui_ruby PRIVATE
117
+ IMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
118
+ ${IMGUI_RUBY_BACKEND_DEFINITIONS}
119
+ )
120
+
121
+ target_link_libraries(cimgui_ruby PRIVATE ${CMAKE_DL_LIBS})
122
+
123
+ set_target_properties(cimgui_ruby PROPERTIES OUTPUT_NAME cimgui_ruby)
124
+ install(TARGETS cimgui_ruby
125
+ RUNTIME DESTINATION .
126
+ LIBRARY DESTINATION .
127
+ ARCHIVE DESTINATION .
128
+ )
data/ext/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rbconfig"
5
+
6
+ require_relative "build_cimgui"
7
+
8
+ host_os = RbConfig::CONFIG.fetch("host_os")
9
+ platform_os = if host_os.include?("darwin")
10
+ "darwin"
11
+ elsif host_os.match?(/mswin|mingw/)
12
+ "windows"
13
+ else
14
+ "linux"
15
+ end
16
+ host_cpu = RbConfig::CONFIG.fetch("host_cpu")
17
+ platform_cpu = host_cpu == "arm64" ? "aarch64" : host_cpu
18
+ platform = "#{platform_cpu}-#{platform_os}"
19
+ extension_root = ENV.fetch("RUBYARCHDIR", File.expand_path("../lib", __dir__))
20
+ install_dir = File.join(extension_root, "imgui", "vendor", platform)
21
+
22
+ desc "Build the bundled cimgui shared library"
23
+ task :compile do
24
+ ImGuiRuby::NativeBuilder.new(
25
+ source_dir: __dir__,
26
+ build_dir: File.join(__dir__, "build"),
27
+ install_dir: install_dir
28
+ ).build!
29
+ end
30
+
31
+ task default: :compile