-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
276 lines (244 loc) · 8.28 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
require 'ffi'
require 'json'
require 'eventmachine'
ImGuiCol = {
Text: 0,
TextDisabled: 1,
WindowBg: 2,
ChildBg: 3,
PopupBg: 4,
Border: 5,
BorderShadow: 6,
FrameBg: 7,
FrameBgHovered: 8,
FrameBgActive: 9,
TitleBg: 10,
TitleBgActive: 11,
TitleBgCollapsed: 12,
MenuBarBg: 13,
ScrollbarBg: 14,
ScrollbarGrab: 15,
ScrollbarGrabHovered: 16,
ScrollbarGrabActive: 17,
CheckMark: 18,
SliderGrab: 19,
SliderGrabActive: 20,
Button: 21,
ButtonHovered: 22,
ButtonActive: 23,
Header: 24,
HeaderHovered: 25,
HeaderActive: 26,
Separator: 27,
SeparatorHovered: 28,
SeparatorActive: 29,
ResizeGrip: 30,
ResizeGripHovered: 31,
ResizeGripActive: 32,
Tab: 33,
TabHovered: 34,
TabActive: 35,
TabUnfocused: 36,
TabUnfocusedActive: 37,
PlotLines: 38,
PlotLinesHovered: 39,
PlotHistogram: 40,
PlotHistogramHovered: 41,
TableHeaderBg: 42,
TableBorderStrong: 43,
TableBorderLight: 44,
TableRowBg: 45,
TableRowBgAlt: 46,
TextSelectedBg: 47,
DragDropTarget: 48,
NavHighlight: 49,
NavWindowingHighlight: 50,
NavWindowingDimBg: 51,
ModalWindowDimBg: 52,
COUNT: 53
}
# Colors for theme generation
theme2Colors = {
darkestGrey: "#141f2c",
darkerGrey: "#2a2e39",
darkGrey: "#363b4a",
lightGrey: "#5a5a5a",
lighterGrey: "#7A818C",
evenLighterGrey: "#8491a3",
black: "#0A0B0D",
green: "#75f986",
red: "#ff0062",
white: "#fff"
}
theme2 = {
colors: {
ImGuiCol[:Text] => [theme2Colors[:white], 1],
ImGuiCol[:TextDisabled] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:WindowBg] => [theme2Colors[:black], 1],
ImGuiCol[:ChildBg] => [theme2Colors[:black], 1],
ImGuiCol[:PopupBg] => [theme2Colors[:white], 1],
ImGuiCol[:Border] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:BorderShadow] => [theme2Colors[:darkestGrey], 1],
ImGuiCol[:FrameBg] => [theme2Colors[:black], 1],
ImGuiCol[:FrameBgHovered] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:FrameBgActive] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:TitleBg] => [theme2Colors[:darkGrey], 1],
ImGuiCol[:TitleBgActive] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:TitleBgCollapsed] => [theme2Colors[:darkGrey], 1],
ImGuiCol[:MenuBarBg] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:ScrollbarBg] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:ScrollbarGrab] => [theme2Colors[:darkestGrey], 1],
ImGuiCol[:ScrollbarGrabHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:ScrollbarGrabActive] => [theme2Colors[:black], 1],
ImGuiCol[:CheckMark] => [theme2Colors[:black], 1],
ImGuiCol[:SliderGrab] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:SliderGrabActive] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:Button] => [theme2Colors[:black], 1],
ImGuiCol[:ButtonHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:ButtonActive] => [theme2Colors[:black], 1],
ImGuiCol[:Header] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:HeaderHovered] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:HeaderActive] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:Separator] => [theme2Colors[:darkestGrey], 1],
ImGuiCol[:SeparatorHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:SeparatorActive] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:ResizeGrip] => [theme2Colors[:black], 1],
ImGuiCol[:ResizeGripHovered] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:ResizeGripActive] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:Tab] => [theme2Colors[:black], 1],
ImGuiCol[:TabHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:TabActive] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:TabUnfocused] => [theme2Colors[:darkGrey], 1],
ImGuiCol[:TabUnfocusedActive] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:PlotLines] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:PlotLinesHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:PlotHistogram] => [theme2Colors[:lightGrey], 1],
ImGuiCol[:PlotHistogramHovered] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:TableHeaderBg] => [theme2Colors[:black], 1],
ImGuiCol[:TableBorderStrong] => [theme2Colors[:lighterGrey], 1],
ImGuiCol[:TableBorderLight] => [theme2Colors[:darkGrey], 1],
ImGuiCol[:TableRowBg] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:TableRowBgAlt] => [theme2Colors[:darkestGrey], 1],
ImGuiCol[:TextSelectedBg] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:DragDropTarget] => [theme2Colors[:darkGrey], 1],
ImGuiCol[:NavHighlight] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:NavWindowingHighlight] => [theme2Colors[:darkerGrey], 1],
ImGuiCol[:NavWindowingDimBg] => [theme2Colors[:darkestGrey], 1],
ImGuiCol[:ModalWindowDimBg] => [theme2Colors[:darkestGrey], 1]
}
}
base_font_defs = {
defs: [
{ name: "roboto-regular", sizes: [16, 18, 20, 24, 28, 32, 36, 48] }
]
}
font_size_pairs = base_font_defs[:defs].flat_map { |font|
font[:sizes].map { |size| { name: font[:name], size: size } }
}
font_defs_json = JSON.pretty_generate(defs: font_size_pairs)
theme_json = JSON.pretty_generate(theme2)
class Node
attr_accessor :id, :root
def initialize(id, root)
@type = 'node'
@id = id
@root = root
end
def to_json(*options)
{
type: @type,
id: @id,
root: @root
}.to_json(*options)
end
end
class UnformattedText
attr_accessor :id, :text
def initialize(id, text)
@type = 'unformatted-text'
@id = id
@text = text
end
def to_json(*options)
{
type: @type,
id: @id,
text: @text
}.to_json(*options)
end
end
module XFrames
extend FFI::Library
if RUBY_PLATFORM =~ /win32|mingw|cygwin/
ffi_lib './xframesshared.dll'
else
ffi_lib './libxframesshared.so'
end
# Define callback types
callback :OnInitCb, [:pointer], :void
callback :OnTextChangedCb, [:int, :string], :void
callback :OnComboChangedCb, [:int, :int], :void
callback :OnNumericValueChangedCb, [:int, :float], :void
callback :OnBooleanValueChangedCb, [:int, :int], :void
callback :OnMultipleNumericValuesChangedCb, [:int, :pointer, :int], :void
callback :OnClickCb, [:int], :void
attach_function :init, [
:string, # assetsBasePath
:string, # rawFontDefinitions
:string, # rawStyleOverrideDefinitions
:OnInitCb,
:OnTextChangedCb,
:OnComboChangedCb,
:OnNumericValueChangedCb,
:OnBooleanValueChangedCb,
:OnMultipleNumericValuesChangedCb,
:OnClickCb
], :void
attach_function :setElement, [:string], :void
attach_function :setChildren, [:int, :string], :void
end
on_init = FFI::Function.new(:void, []) do
puts "OnInit called!"
node = Node.new(0, true)
unformatted_text = UnformattedText.new(1, "Hello, world")
children_ids = [1]
XFrames.setElement(node.to_json)
XFrames.setElement(unformatted_text.to_json)
XFrames.setChildren(0, children_ids.to_json)
end
on_text_changed = FFI::Function.new(:void, [:int, :string]) do |id, text|
puts "Text changed: ID=#{id}, Text=#{text}"
end
on_combo_changed = FFI::Function.new(:void, [:int, :int]) do |id, selected_index|
puts "Combo changed: ID=#{id}, Selected=#{selected_index}"
end
on_numeric_value_changed = FFI::Function.new(:void, [:int, :float]) do |id, value|
puts "Numeric value changed: ID=#{id}, Value=#{value}"
end
on_boolean_value_changed = FFI::Function.new(:void, [:int, :int]) do |id, state|
puts "Boolean value changed: ID=#{id}, State=#{state}"
end
on_multiple_numeric_values_changed = FFI::Function.new(:void, [:int, :pointer, :int]) do |id, values_ptr, num_values|
# Dereference the float array (you may need additional code to handle this)
puts "Multiple numeric values changed: ID=#{id}, NumValues=#{num_values}"
end
on_click = FFI::Function.new(:void, [:int]) do |id|
puts "Button clicked: ID=#{id}"
end
# Call init with callbacks
assets_base_path = './assets'
XFrames.init(
assets_base_path,
font_defs_json,
theme_json,
on_init,
on_text_changed,
on_combo_changed,
on_numeric_value_changed,
on_boolean_value_changed,
on_multiple_numeric_values_changed,
on_click
)
EM.run do
EM.add_periodic_timer(1) { }
end