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,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImGui
4
+ class << self
5
+ def text(value, *format_arguments)
6
+ string = format_arguments.empty? ? value.to_s : format(value.to_s, *format_arguments)
7
+ guarded_native_call(:igTextUnformatted, string, nil)
8
+ end
9
+
10
+ def text_wrapped(value, *format_arguments)
11
+ guard_context!
12
+ Native.igPushTextWrapPos(0.0)
13
+ wrapped = true
14
+ text(value, *format_arguments)
15
+ ensure
16
+ Native.igPopTextWrapPos if wrapped
17
+ end
18
+
19
+ def text_disabled(value, *format_arguments)
20
+ text_colored(style.color(Col::TextDisabled), value, *format_arguments)
21
+ end
22
+
23
+ def bullet_text(value, *format_arguments)
24
+ guard_context!
25
+ Native.igBullet
26
+ text(value, *format_arguments)
27
+ end
28
+
29
+ def label_text(label, value, *format_arguments)
30
+ string = format_arguments.empty? ? value.to_s : format(value.to_s, *format_arguments)
31
+ text("#{label}: #{string}")
32
+ end
33
+
34
+ def set_tooltip(value, *format_arguments)
35
+ guard_context!
36
+ opened = Native.igBeginTooltip
37
+ return false unless opened
38
+
39
+ text(value, *format_arguments)
40
+ ensure
41
+ Native.igEndTooltip if opened
42
+ end
43
+
44
+ def text_colored(color, value, *format_arguments)
45
+ string = format_arguments.empty? ? value.to_s : format(value.to_s, *format_arguments)
46
+ guard_context!
47
+ Native.igPushStyleColor_Vec4(Col::Text, StructValue.vec4(color))
48
+ pushed = true
49
+ Native.igTextUnformatted(string, nil)
50
+ ensure
51
+ Native.igPopStyleColor(1) if pushed
52
+ end
53
+
54
+ def button(label, size: [0, 0])
55
+ guarded_native_call(:igButton, label.to_s, StructValue.vec2(size))
56
+ end
57
+
58
+ def small_button(label)
59
+ guarded_native_call(:igSmallButton, label.to_s)
60
+ end
61
+
62
+ def invisible_button(id, size, flags: 0)
63
+ guarded_native_call(:igInvisibleButton, id.to_s, StructValue.vec2(size), Integer(flags))
64
+ end
65
+
66
+ def checkbox(label, value)
67
+ edit_scalar(:igCheckbox, label.to_s, value, type: :bool, arguments: [])
68
+ end
69
+
70
+ def radio_button(label, active)
71
+ guarded_native_call(:igRadioButton_Bool, label.to_s, !!active)
72
+ end
73
+
74
+ def slider_float(label, value, minimum, maximum, format: "%.3f", flags: 0)
75
+ edit_scalar(
76
+ :igSliderFloat,
77
+ label.to_s,
78
+ value,
79
+ type: :float,
80
+ arguments: [Float(minimum), Float(maximum), format, Integer(flags)]
81
+ )
82
+ end
83
+
84
+ def slider_int(label, value, minimum, maximum, format: "%d", flags: 0)
85
+ edit_scalar(
86
+ :igSliderInt,
87
+ label.to_s,
88
+ value,
89
+ type: :int,
90
+ arguments: [Integer(minimum), Integer(maximum), format, Integer(flags)]
91
+ )
92
+ end
93
+
94
+ (2..4).each do |count|
95
+ define_method("slider_float#{count}") do |label, value, minimum, maximum, format: "%.3f", flags: 0|
96
+ edit_vector(
97
+ "igSliderFloat#{count}".to_sym,
98
+ label.to_s,
99
+ value,
100
+ count: count,
101
+ arguments: [Float(minimum), Float(maximum), format, Integer(flags)]
102
+ )
103
+ end
104
+ end
105
+
106
+ def drag_float(label, value, speed: 1.0, minimum: 0.0, maximum: 0.0, format: "%.3f", flags: 0)
107
+ edit_scalar(
108
+ :igDragFloat,
109
+ label.to_s,
110
+ value,
111
+ type: :float,
112
+ arguments: [Float(speed), Float(minimum), Float(maximum), format, Integer(flags)]
113
+ )
114
+ end
115
+
116
+ def drag_int(label, value, speed: 1.0, minimum: 0, maximum: 0, format: "%d", flags: 0)
117
+ edit_scalar(
118
+ :igDragInt,
119
+ label.to_s,
120
+ value,
121
+ type: :int,
122
+ arguments: [Float(speed), Integer(minimum), Integer(maximum), format, Integer(flags)]
123
+ )
124
+ end
125
+
126
+ def input_float(label, value, step: 0.0, fast_step: 0.0, format: "%.3f", flags: 0)
127
+ edit_scalar(
128
+ :igInputFloat,
129
+ label.to_s,
130
+ value,
131
+ type: :float,
132
+ arguments: [Float(step), Float(fast_step), format, Integer(flags)]
133
+ )
134
+ end
135
+
136
+ def input_int(label, value, step: 1, fast_step: 100, flags: 0)
137
+ edit_scalar(
138
+ :igInputInt,
139
+ label.to_s,
140
+ value,
141
+ type: :int,
142
+ arguments: [Integer(step), Integer(fast_step), Integer(flags)]
143
+ )
144
+ end
145
+
146
+ def color_edit3(label, value, flags: 0)
147
+ edit_vector(:igColorEdit3, label.to_s, value, count: 3, arguments: [Integer(flags)])
148
+ end
149
+
150
+ def color_edit4(label, value, flags: 0)
151
+ edit_vector(:igColorEdit4, label.to_s, value, count: 4, arguments: [Integer(flags)])
152
+ end
153
+
154
+ def input_text(label, value, capacity: nil, flags: 0, callback: nil, user_data: nil)
155
+ guard_context!
156
+ state = value.is_a?(Value) ? value : Value.text(value, capacity: capacity)
157
+ require_value_type!(state, :text)
158
+ changed = Native.igInputText(
159
+ label.to_s,
160
+ state.pointer,
161
+ state.capacity,
162
+ Integer(flags),
163
+ callback,
164
+ user_data
165
+ )
166
+ value.is_a?(Value) ? changed : [changed, state.get]
167
+ end
168
+
169
+ def selectable(label, selected = false, flags: 0, size: [0, 0])
170
+ guarded_native_call(
171
+ :igSelectable_Bool,
172
+ label.to_s,
173
+ !!selected,
174
+ Integer(flags),
175
+ StructValue.vec2(size)
176
+ )
177
+ end
178
+
179
+ def menu_item(label, shortcut: nil, selected: false, enabled: true)
180
+ guarded_native_call(:igMenuItem_Bool, label.to_s, shortcut, !!selected, !!enabled)
181
+ end
182
+
183
+ def progress_bar(fraction, size: [-Float::MIN, 0], overlay: nil)
184
+ guarded_native_call(:igProgressBar, Float(fraction), StructValue.vec2(size), overlay)
185
+ end
186
+ end
187
+ end
data/lib/imgui.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+
5
+ require_relative "imgui/version"
6
+ require_relative "imgui/errors"
7
+ require_relative "imgui/native"
8
+ require_relative "imgui/memory_pool"
9
+ require_relative "imgui/struct_value"
10
+ require_relative "imgui/value"
11
+ require_relative "imgui/fonts"
12
+ require_relative "imgui/io"
13
+ require_relative "imgui/style"
14
+ require_relative "imgui/draw_data"
15
+ require_relative "imgui/api"
16
+ require_relative "imgui/api_support"
17
+ require_relative "imgui/api_generated"
18
+ require_relative "imgui/widgets"
19
+ require_relative "imgui/layout"
20
+ require_relative "imgui/dsl"
21
+ require_relative "imgui/dsl_support"
22
+ require_relative "imgui/backends"
23
+ require_relative "imgui/backends/glfw"
24
+ require_relative "imgui/backends/opengl3"
25
+ require_relative "imgui/backends/sdl3"
26
+ require_relative "imgui/backends/wgpu"
27
+ require_relative "imgui/easy_loop"
28
+
29
+ module ImGui
30
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "ffi"
5
+ require "rubygems/package"
6
+
7
+ namespace :gem do
8
+ desc "Build a gem with the native library for the current platform"
9
+ task :platform do
10
+ root = File.expand_path("..", __dir__)
11
+ ENV["IMGUI_RUBY_BACKENDS"] ||= "glfw,opengl3,sdl3,wgpu"
12
+ Rake::Task["native:build"].invoke
13
+ install_root = File.join(root, "tmp", "native-install")
14
+ library = Dir.glob(File.join(install_root, "*cimgui_ruby.{so,dylib,dll}")).first
15
+ raise "built cimgui library was not found" unless library
16
+
17
+ stage = File.join(root, "tmp", "platform-gem")
18
+ package_dir = File.join(root, "pkg")
19
+ FileUtils.rm_rf(stage)
20
+ FileUtils.mkdir_p(stage)
21
+ FileUtils.mkdir_p(package_dir)
22
+
23
+ specification = Gem::Specification.load(File.join(root, "imgui.gemspec"))
24
+ local_platform = Gem::Platform.local
25
+ specification.platform = if %w[darwin linux].include?(local_platform.os)
26
+ cpu = local_platform.cpu == "aarch64" ? "arm64" : local_platform.cpu
27
+ Gem::Platform.new("#{cpu}-#{local_platform.os}")
28
+ else
29
+ local_platform
30
+ end
31
+ specification.extensions = []
32
+ specification.files = specification.files.reject do |file|
33
+ file.start_with?("ext/", "vendor-src/")
34
+ end
35
+
36
+ platform = "#{FFI::Platform::ARCH}-#{FFI::Platform::OS}"
37
+ native_file = File.join("vendor", platform, File.basename(library))
38
+ specification.files << native_file
39
+
40
+ specification.files.each do |relative_path|
41
+ source = relative_path == native_file ? library : File.join(root, relative_path)
42
+ destination = File.join(stage, relative_path)
43
+ FileUtils.mkdir_p(File.dirname(destination))
44
+ FileUtils.cp(source, destination)
45
+ end
46
+
47
+ built_gem = Dir.chdir(stage) { Gem::Package.build(specification) }
48
+ FileUtils.mv(File.join(stage, built_gem), File.join(package_dir, built_gem))
49
+ puts File.join(package_dir, built_gem)
50
+ end
51
+
52
+ desc "Build source and current-platform gems"
53
+ task all: ["build", "gem:platform"]
54
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "rubygems/package"
5
+
6
+ module ImGuiRuby
7
+ class SourceGemBuilder
8
+ def initialize(root:)
9
+ @root = root
10
+ @cache_root = File.join(root, "tmp", "vendor")
11
+ @stage = File.join(root, "tmp", "source-gem")
12
+ @package_dir = File.join(root, "pkg")
13
+ end
14
+
15
+ def build!
16
+ specification = Gem::Specification.load(File.join(@root, "imgui.gemspec")).dup
17
+ project_files = specification.files
18
+ native_files = native_source_files
19
+ specification.files = (project_files + native_files.keys).sort
20
+
21
+ prepare_stage!
22
+ copy_project_files!(project_files)
23
+ copy_native_files!(native_files)
24
+ package = Dir.chdir(@stage) { Gem::Package.build(specification) }
25
+ destination = File.join(@package_dir, package)
26
+ FileUtils.rm_f(destination)
27
+ FileUtils.mv(File.join(@stage, package), destination)
28
+ puts "#{specification.full_name} built to #{relative(destination)}."
29
+ end
30
+
31
+ private
32
+
33
+ def native_source_files
34
+ Dir.glob(File.join(@cache_root, "**", "*"))
35
+ .select { |path| File.file?(path) }
36
+ .reject { |path| path.include?("/generator/output/") }
37
+ .to_h do |path|
38
+ relative_path = path.delete_prefix("#{@cache_root}/")
39
+ [File.join("vendor-src", relative_path), path]
40
+ end
41
+ end
42
+
43
+ def prepare_stage!
44
+ FileUtils.rm_rf(@stage)
45
+ FileUtils.mkdir_p(@stage)
46
+ FileUtils.mkdir_p(@package_dir)
47
+ end
48
+
49
+ def copy_project_files!(files)
50
+ files.each do |relative_path|
51
+ source = File.join(@root, relative_path)
52
+ copy!(source, File.join(@stage, relative_path))
53
+ end
54
+ end
55
+
56
+ def copy_native_files!(files)
57
+ files.each { |relative_path, source| copy!(source, File.join(@stage, relative_path)) }
58
+ end
59
+
60
+ def copy!(source, destination)
61
+ FileUtils.mkdir_p(File.dirname(destination))
62
+ FileUtils.cp(source, destination)
63
+ end
64
+
65
+ def relative(path)
66
+ path.delete_prefix("#{@root}/")
67
+ end
68
+ end
69
+ end
70
+
71
+ Rake::Task["build"].clear
72
+ desc "Build the source gem with pinned native sources"
73
+ task build: "vendor:fetch" do
74
+ ImGuiRuby::SourceGemBuilder.new(root: File.expand_path("..", __dir__)).build!
75
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imgui
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yudai Takada
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ffi
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.16'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1.16'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '2'
32
+ description: Generated native bindings and an idiomatic Ruby API for Dear ImGui's
33
+ docking branch.
34
+ email:
35
+ - t.yudai92@gmail.com
36
+ executables: []
37
+ extensions:
38
+ - ext/extconf.rb
39
+ extra_rdoc_files: []
40
+ files:
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - api/v1.json
45
+ - ext/CMakeLists.txt
46
+ - ext/Rakefile
47
+ - ext/backend_function_bridge.cpp
48
+ - ext/backend_function_bridge.h
49
+ - ext/build_cimgui.rb
50
+ - ext/extconf.rb
51
+ - ext/glfw_vulkan_bridge.cpp
52
+ - ext/imgui_ruby_build_config.h
53
+ - ext/imgui_ruby_glfw.cpp
54
+ - ext/imgui_ruby_sdl3.cpp
55
+ - ext/imgui_ruby_wgpu.cpp
56
+ - ext/install_cimgui.rb
57
+ - ext/webgpu_function_bridge.cpp
58
+ - generator/api_emitter.rb
59
+ - generator/emitter.rb
60
+ - generator/generate.rb
61
+ - generator/native-dependencies.yml
62
+ - generator/native_dependency_lock.rb
63
+ - generator/native_dependency_snapshot.rb
64
+ - generator/overrides.yml
65
+ - generator/type_mapper.rb
66
+ - generator/update_vendor.rb
67
+ - lib/imgui.rb
68
+ - lib/imgui/api.rb
69
+ - lib/imgui/api_generated.rb
70
+ - lib/imgui/api_support.rb
71
+ - lib/imgui/backends.rb
72
+ - lib/imgui/backends/glfw.rb
73
+ - lib/imgui/backends/opengl3.rb
74
+ - lib/imgui/backends/sdl3.rb
75
+ - lib/imgui/backends/wgpu.rb
76
+ - lib/imgui/draw_data.rb
77
+ - lib/imgui/dsl.rb
78
+ - lib/imgui/dsl_support.rb
79
+ - lib/imgui/easy_loop.rb
80
+ - lib/imgui/errors.rb
81
+ - lib/imgui/fonts.rb
82
+ - lib/imgui/io.rb
83
+ - lib/imgui/layout.rb
84
+ - lib/imgui/memory_pool.rb
85
+ - lib/imgui/native.rb
86
+ - lib/imgui/native/enums.rb
87
+ - lib/imgui/native/functions.rb
88
+ - lib/imgui/native/structs.rb
89
+ - lib/imgui/native/typedefs.rb
90
+ - lib/imgui/plot.rb
91
+ - lib/imgui/plot/api.rb
92
+ - lib/imgui/plot/native/enums.rb
93
+ - lib/imgui/plot/native/functions.rb
94
+ - lib/imgui/plot/native/structs.rb
95
+ - lib/imgui/plot/native/typedefs.rb
96
+ - lib/imgui/struct_value.rb
97
+ - lib/imgui/style.rb
98
+ - lib/imgui/value.rb
99
+ - lib/imgui/version.rb
100
+ - lib/imgui/widgets.rb
101
+ - rakelib/platform_gem.rake
102
+ - rakelib/source_gem.rake
103
+ homepage: https://github.com/ydah/imgui
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ homepage_uri: https://github.com/ydah/imgui
108
+ source_code_uri: https://github.com/ydah/imgui/tree/main
109
+ documentation_uri: https://github.com/ydah/imgui#readme
110
+ bug_tracker_uri: https://github.com/ydah/imgui/issues
111
+ rubygems_mfa_required: 'true'
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 3.2.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 4.0.6
127
+ specification_version: 4
128
+ summary: Ruby bindings for Dear ImGui through cimgui and FFI
129
+ test_files: []