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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +273 -0
- data/Rakefile +97 -0
- data/api/v1.json +53 -0
- data/ext/CMakeLists.txt +128 -0
- data/ext/Rakefile +31 -0
- data/ext/backend_function_bridge.cpp +180 -0
- data/ext/backend_function_bridge.h +40 -0
- data/ext/build_cimgui.rb +59 -0
- data/ext/extconf.rb +25 -0
- data/ext/glfw_vulkan_bridge.cpp +14 -0
- data/ext/imgui_ruby_build_config.h +17 -0
- data/ext/imgui_ruby_glfw.cpp +73 -0
- data/ext/imgui_ruby_sdl3.cpp +70 -0
- data/ext/imgui_ruby_wgpu.cpp +75 -0
- data/ext/install_cimgui.rb +25 -0
- data/ext/webgpu_function_bridge.cpp +245 -0
- data/generator/api_emitter.rb +164 -0
- data/generator/emitter.rb +317 -0
- data/generator/generate.rb +47 -0
- data/generator/native-dependencies.yml +88 -0
- data/generator/native_dependency_lock.rb +78 -0
- data/generator/native_dependency_snapshot.rb +159 -0
- data/generator/overrides.yml +11 -0
- data/generator/type_mapper.rb +112 -0
- data/generator/update_vendor.rb +30 -0
- data/lib/imgui/api.rb +88 -0
- data/lib/imgui/api_generated.rb +1633 -0
- data/lib/imgui/api_support.rb +144 -0
- data/lib/imgui/backends/glfw.rb +75 -0
- data/lib/imgui/backends/opengl3.rb +44 -0
- data/lib/imgui/backends/sdl3.rb +133 -0
- data/lib/imgui/backends/wgpu.rb +176 -0
- data/lib/imgui/backends.rb +60 -0
- data/lib/imgui/draw_data.rb +43 -0
- data/lib/imgui/dsl.rb +311 -0
- data/lib/imgui/dsl_support.rb +107 -0
- data/lib/imgui/easy_loop.rb +25 -0
- data/lib/imgui/errors.rb +11 -0
- data/lib/imgui/fonts.rb +46 -0
- data/lib/imgui/io.rb +91 -0
- data/lib/imgui/layout.rb +138 -0
- data/lib/imgui/memory_pool.rb +18 -0
- data/lib/imgui/native/enums.rb +2251 -0
- data/lib/imgui/native/functions.rb +1470 -0
- data/lib/imgui/native/structs.rb +1926 -0
- data/lib/imgui/native/typedefs.rb +93 -0
- data/lib/imgui/native.rb +130 -0
- data/lib/imgui/plot/api.rb +273 -0
- data/lib/imgui/plot/native/enums.rb +593 -0
- data/lib/imgui/plot/native/functions.rb +749 -0
- data/lib/imgui/plot/native/structs.rb +363 -0
- data/lib/imgui/plot/native/typedefs.rb +79 -0
- data/lib/imgui/plot.rb +13 -0
- data/lib/imgui/struct_value.rb +33 -0
- data/lib/imgui/style.rb +44 -0
- data/lib/imgui/value.rb +104 -0
- data/lib/imgui/version.rb +5 -0
- data/lib/imgui/widgets.rb +187 -0
- data/lib/imgui.rb +30 -0
- data/rakelib/platform_gem.rake +54 -0
- data/rakelib/source_gem.rake +75 -0
- metadata +129 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ImGuiRuby
|
|
4
|
+
module Generator
|
|
5
|
+
class TypeMapper
|
|
6
|
+
PRIMITIVES = {
|
|
7
|
+
"void" => ":void",
|
|
8
|
+
"bool" => ":bool",
|
|
9
|
+
"char" => ":char",
|
|
10
|
+
"signed char" => ":char",
|
|
11
|
+
"unsigned char" => ":uchar",
|
|
12
|
+
"short" => ":short",
|
|
13
|
+
"unsigned short" => ":ushort",
|
|
14
|
+
"int" => ":int",
|
|
15
|
+
"unsigned int" => ":uint",
|
|
16
|
+
"long" => ":long",
|
|
17
|
+
"unsigned long" => ":ulong",
|
|
18
|
+
"long long" => ":long_long",
|
|
19
|
+
"unsigned long long" => ":ulong_long",
|
|
20
|
+
"float" => ":float",
|
|
21
|
+
"double" => ":double",
|
|
22
|
+
"size_t" => ":size_t",
|
|
23
|
+
"ptrdiff_t" => ":ptrdiff_t"
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
26
|
+
def initialize(typedefs:, structs:, enum_types:, struct_references: {})
|
|
27
|
+
@typedefs = typedefs
|
|
28
|
+
@structs = structs
|
|
29
|
+
@enum_types = enum_types
|
|
30
|
+
@struct_references = struct_references
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def ffi_type(c_type, member: nil)
|
|
34
|
+
type = normalize(c_type)
|
|
35
|
+
array_size = member&.fetch("size", nil) || array_size_from(type)
|
|
36
|
+
return ":pointer" if member.nil? && array_size
|
|
37
|
+
|
|
38
|
+
type = type.sub(/\s*\[[^\]]+\]\z/, "") if array_size
|
|
39
|
+
mapped = map_scalar(type, struct_member: !member.nil?)
|
|
40
|
+
return mapped unless array_size
|
|
41
|
+
|
|
42
|
+
"[#{mapped}, #{array_size}]"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def typedef_type(c_type)
|
|
46
|
+
type = normalize(c_type)
|
|
47
|
+
return ":pointer" if pointer?(type) || callback?(type) || type.include?("<")
|
|
48
|
+
return PRIMITIVES.fetch(type) if PRIMITIVES.key?(type)
|
|
49
|
+
return ":int" if enum_type?(type)
|
|
50
|
+
|
|
51
|
+
resolved = @typedefs[type]
|
|
52
|
+
return typedef_type(resolved) if resolved && resolved != c_type
|
|
53
|
+
|
|
54
|
+
":pointer"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def map_scalar(type, struct_member: false)
|
|
60
|
+
return ":pointer" if struct_member && pointer?(type)
|
|
61
|
+
return ":string" if type.match?(/\Aconst\s+char\s*\*\z/)
|
|
62
|
+
return ":pointer" if pointer?(type) || callback?(type)
|
|
63
|
+
|
|
64
|
+
bare = type.sub(/\Aconst\s+/, "").strip
|
|
65
|
+
return PRIMITIVES.fetch(bare) if PRIMITIVES.key?(bare)
|
|
66
|
+
return ":int" if enum_type?(bare)
|
|
67
|
+
return "#{struct_reference(bare)}.by_value" if @structs.key?(bare)
|
|
68
|
+
|
|
69
|
+
template_base = bare.split("_").first
|
|
70
|
+
return "#{struct_reference(template_base)}.by_value" if @structs.key?(template_base)
|
|
71
|
+
|
|
72
|
+
resolved = @typedefs[bare]
|
|
73
|
+
return ":#{bare}" if resolved && callback?(resolved)
|
|
74
|
+
return typedef_type(resolved) if resolved
|
|
75
|
+
|
|
76
|
+
":pointer"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def normalize(c_type)
|
|
80
|
+
c_type.to_s
|
|
81
|
+
.gsub(/\bvolatile\b/, "")
|
|
82
|
+
.gsub(/\bstruct\s+/, "")
|
|
83
|
+
.gsub(/\s+/, " ")
|
|
84
|
+
.strip
|
|
85
|
+
.sub(/;\z/, "")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def pointer?(type)
|
|
89
|
+
type.include?("*") || type.end_with?("&")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def callback?(type)
|
|
93
|
+
type.include?("(*)") || type.include?("(*")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def enum_type?(type)
|
|
97
|
+
@enum_types.include?(type) ||
|
|
98
|
+
type.match?(/\AImGui_Impl\w+_(?:Gamepad)?Mode\z/) ||
|
|
99
|
+
@typedefs[type] == "int" && type.match?(/Flags|ImGuiCol\z|ImGuiKey\z/)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def array_size_from(type)
|
|
103
|
+
match = type.match(/\[([^\]]+)\]\z/)
|
|
104
|
+
match && match[1]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def struct_reference(name)
|
|
108
|
+
@struct_references.fetch(name, name)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
require_relative "native_dependency_snapshot"
|
|
6
|
+
|
|
7
|
+
options = { latest: false, verify: false, checkout: nil }
|
|
8
|
+
OptionParser.new do |parser|
|
|
9
|
+
parser.banner = "Usage: ruby generator/update_vendor.rb [--latest | --verify | --checkout SOURCE:DIR]"
|
|
10
|
+
parser.on("--latest", "Refresh snapshots from configured upstream branches") { options[:latest] = true }
|
|
11
|
+
parser.on("--verify", "Verify cached snapshots without network access") { options[:verify] = true }
|
|
12
|
+
parser.on("--checkout SOURCE:DIR", "Checkout a complete pinned upstream source tree") do |value|
|
|
13
|
+
options[:checkout] = value.split(":", 2)
|
|
14
|
+
end
|
|
15
|
+
end.parse!
|
|
16
|
+
|
|
17
|
+
selected_modes = [options[:latest], options[:verify], options[:checkout]].count { |value| value }
|
|
18
|
+
abort "--latest, --verify, and --checkout cannot be combined" if selected_modes > 1
|
|
19
|
+
abort "--checkout requires SOURCE:DIR" if options[:checkout]&.length == 1
|
|
20
|
+
|
|
21
|
+
snapshot = ImGuiRuby::NativeDependencySnapshot.new
|
|
22
|
+
if options[:checkout]
|
|
23
|
+
snapshot.checkout_source!(*options[:checkout])
|
|
24
|
+
elsif options[:verify]
|
|
25
|
+
snapshot.verify!
|
|
26
|
+
elsif options[:latest]
|
|
27
|
+
snapshot.refresh!(latest: true)
|
|
28
|
+
else
|
|
29
|
+
snapshot.fetch!
|
|
30
|
+
end
|
data/lib/imgui/api.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ImGui
|
|
4
|
+
class << self
|
|
5
|
+
def create_context(shared_font_atlas = nil)
|
|
6
|
+
context = Native.igCreateContext(shared_font_atlas)
|
|
7
|
+
raise Error, "cimgui returned a null context" if null_pointer?(context)
|
|
8
|
+
|
|
9
|
+
context_threads[context_key(context)] = Thread.current
|
|
10
|
+
context
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def destroy_context(context = nil)
|
|
14
|
+
context ||= Native.igGetCurrentContext
|
|
15
|
+
return if null_pointer?(context)
|
|
16
|
+
|
|
17
|
+
check_context_thread!(context)
|
|
18
|
+
Native.igDestroyContext(context)
|
|
19
|
+
context_threads.delete(context_key(context))
|
|
20
|
+
clear_context_views(context)
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def current_context
|
|
25
|
+
context = Native.igGetCurrentContext
|
|
26
|
+
null_pointer?(context) ? nil : context
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def current_context=(context)
|
|
30
|
+
check_context_thread!(context) unless null_pointer?(context)
|
|
31
|
+
Native.igSetCurrentContext(context)
|
|
32
|
+
context
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def new_frame
|
|
36
|
+
guarded_native_call(:igNewFrame)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def end_frame
|
|
40
|
+
guarded_native_call(:igEndFrame)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render
|
|
44
|
+
guarded_native_call(:igRender)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def draw_data
|
|
48
|
+
guard_context!
|
|
49
|
+
pointer = Native.igGetDrawData
|
|
50
|
+
return if null_pointer?(pointer)
|
|
51
|
+
|
|
52
|
+
DrawData.new(pointer)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def io
|
|
56
|
+
context = guard_context!
|
|
57
|
+
key = context_key(context)
|
|
58
|
+
io_views[key] ||= IO.new(Native.igGetIO)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def style
|
|
62
|
+
context = guard_context!
|
|
63
|
+
key = context_key(context)
|
|
64
|
+
style_views[key] ||= Style.new(Native.igGetStyle)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def ini_filename=(filename)
|
|
68
|
+
io.ini_filename = filename
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def unsafe_allow_threads!
|
|
72
|
+
@thread_checks_enabled = false
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def enforce_thread_safety!
|
|
76
|
+
@thread_checks_enabled = true
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def thread_checks_enabled?
|
|
80
|
+
@thread_checks_enabled != false
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def version_string
|
|
84
|
+
Native.igGetVersion
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|