-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimgui_h.lua
More file actions
2043 lines (1763 loc) · 68.1 KB
/
Copy pathimgui_h.lua
File metadata and controls
2043 lines (1763 loc) · 68.1 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- ImGui Sincerely WIP
-- (Definitions)
--- @meta
-- [LuaBitOp](https://bitop.luajit.org/semantics.html)
local _band = bit.band
--- @class char : integer
--- @class unsigned_char : integer
--- @alias ImS8 char
--- @alias ImU8 unsigned_char
--- @class ImU16 : integer
--- @class ImS16 : integer
--- @class ImU32 : integer
--- @class ImS32 : integer
--- @param val number
--- @return ImU8
function ImU8(val) return _band(val, 0xFF) end
--- @param val number
--- @return ImS8
function ImS8(val) return _band(val, 0xFF) - (_band(val, 0x80) ~= 0 and 0x100 or 0) end
--- @param val number
--- @return ImU16
function ImU16(val) return _band(val, 0xFFFF) end
--- @param val number
--- @return ImS16
function ImS16(val) return _band(val, 0xFFFF) - (_band(val, 0x8000) ~= 0 and 0x10000 or 0) end
--- @param val number
--- @return ImU32
function ImU32(val) return _band(val, 0xFFFFFFFF) end
--- @param val number
--- @return ImS32
function ImS32(val) return _band(val, 0xFFFFFFFF) end
--- @alias float number
--- @class double : number
--- @alias int integer
--- @alias unsigned_int integer
--- @alias short integer
--- @alias unsigned_short integer
--- @alias size_t unsigned_int
--- @alias ImWchar16 unsigned_short
--- @alias ImWchar ImWchar16
--- @alias bool boolean
--- @alias ImGuiID unsigned_int
--- @alias ImTextureID integer
--- @alias ImGuiKeyChord int
--- @alias ImDrawIdx unsigned_int
IM_UNICODE_CODEPOINT_INVALID = 0xFFFD
IM_UNICODE_CODEPOINT_MAX = 0xFFFF
IM_ALLOC = ImGui.MemAlloc
IM_FREE = ImGui.MemFree
---------------------------------------------------------------------------------------
-- [SECTION] METATABLE MANAGEMENT
---------------------------------------------------------------------------------------
--- File-scope metatable storage
local MT = {}
function ImGui.GetMetatables() return MT end
--- @param _EXPR any
--- @param _MSG string?
function IM_ASSERT(_EXPR, _MSG) assert((_EXPR), _MSG) end
IM_ASSERT_PARANOID = IM_ASSERT
IM_DRAWLIST_TEX_LINES_WIDTH_MAX = 32
ImTextureID_Invalid = -1
--- @enum ImTextureFormat
ImTextureFormat = {
RGBA32 = 0,
Alpha8 = 1
}
--- @enum ImTextureStatus
ImTextureStatus = {
OK = 0,
Destroyed = 1,
WantCreate = 2,
WantUpdates = 3,
WantDestroy = 4
}
--- @enum ImFontAtlasFlags
ImFontAtlasFlags = {
None = 0,
NoPowerOfTwoHeight = bit.lshift(1, 0),
NoMouseCursors = bit.lshift(1, 1),
NoBakedLines = bit.lshift(1, 2)
}
--- @class ImTextureRect
--- @field x unsigned_short
--- @field y unsigned_short
--- @field w unsigned_short
--- @field h unsigned_short
--- @param x? unsigned_short
--- @param y? unsigned_short
--- @param w? unsigned_short
--- @param h? unsigned_short
--- @return ImTextureRect
function ImTextureRect(x, y, w, h)
return {
x = x, y = y,
w = w, h = h
}
end
local rawget = rawget; local rawset = rawset
-- This structure supports indexing on string keys `x`, `y` and number keys 1, 2.
-- But note that the former is likely to be more expensive.
--- @class ImVec2
--- @operator add(ImVec2): ImVec2
--- @operator sub(ImVec2): ImVec2
--- @operator mul(number): ImVec2
--- @field [1] number
--- @field [2] number
--- @field x number
--- @field y number
MT.ImVec2 = {}
--- @param t ImVec2
--- @param k int
MT.ImVec2.__index = function(t, k)
if k == "x" then return rawget(t, 1)
elseif k == "y" then return rawget(t, 2)
end
end
--- @param t ImVec2
--- @param k int
--- @param v number
MT.ImVec2.__newindex = function(t, k, v)
if k == "x" then rawset(t, 1, v)
elseif k == "y" then rawset(t, 2, v)
end
end
--- @param x? number
--- @param y? number
--- @return ImVec2
--- @nodiscard
function ImVec2(x, y) return setmetatable({x or 0, y or 0}, MT.ImVec2) end
function MT.ImVec2.__add(lhs, rhs) return ImVec2(lhs[1] + rhs[1], lhs[2] + rhs[2]) end
function MT.ImVec2.__sub(lhs, rhs) return ImVec2(lhs[1] - rhs[1], lhs[2] - rhs[2]) end
function MT.ImVec2.__mul(lhs, rhs) return ImVec2(lhs[1] * rhs, lhs[2] * rhs) end
function MT.ImVec2.__eq(lhs, rhs) return lhs[1] == rhs[1] and lhs[2] == rhs[2] end
function MT.ImVec2:__tostring() return string.format("ImVec2(%g, %g)", self.x, self.y) end
--- @param dest ImVec2
--- @param src ImVec2
function ImVec2_Copy(dest, src) dest[1] = src[1]; dest[2] = src[2] end
--- @param dest ImVec2
--- @param src_x number
--- @param src_y number
function ImVec2_CopyV(dest, src_x, src_y) dest[1] = src_x; dest[2] = src_y end
--- @param lhs ImVec2
--- @param rhs ImVec2
function ImVec2_AddV(lhs, rhs) return lhs[1] + rhs[1], lhs[2] + rhs[2] end
--- @param lhs ImVec2
--- @param rhs ImVec2
function ImVec2_SubV(lhs, rhs) return lhs[1] - rhs[1], lhs[2] - rhs[2] end
--- @param v ImVec2
--- @param add_x number
--- @param add_y number
function ImVec2_AddVA(v, add_x, add_y) return v[1] + add_x, v[2] + add_y end
--- @param v ImVec2
--- @param sub_x number
--- @param sub_y number
function ImVec2_SubVA(v, sub_x, sub_y) return v[1] - sub_x, v[2] - sub_y end
--- @param lhs ImVec2
--- @param rhs number
function ImVec2_MulNV(lhs, rhs) return lhs[1] * rhs, lhs[2] * rhs end
--- @param lhs ImVec2
--- @param rhs ImVec2
--- @nodiscard
function ImVec2_MulComp(lhs, rhs) return ImVec2(lhs[1] * rhs[1], lhs[2] * rhs[2]) end
--- @param lhs ImVec2
--- @param rhs ImVec2
function ImVec2_MulCompV(lhs, rhs) return lhs[1] * rhs[1], lhs[2] * rhs[2] end
--- An inlined version of `ImVec2_Copy` currently for use in certain ImVector<ImVec2> `push_back`
--- @param t ImVec2[]
--- @param k int
--- @param v ImVec2
local function ImVec2_TCopy(t, k, v) local dest = t[k]; dest[1] = v[1]; dest[2] = v[2]; end
-- This structure supports indexing on string keys `x`, `y`, `z`, `w` and number keys 1, 2, 3, 4.
-- But note that the former is likely to be more expensive.
--- @class ImVec4
--- @operator add(ImVec4): ImVec4
--- @operator sub(ImVec4): ImVec4
--- @operator mul(number): ImVec4
--- @field [1] number
--- @field [2] number
--- @field [3] number
--- @field [4] number
--- @field x number
--- @field y number
--- @field z number
--- @field w number
MT.ImVec4 = {}
--- @param t ImVec4
--- @param k int
MT.ImVec4.__index = function(t, k)
if k == "x" then return rawget(t, 1)
elseif k == "y" then return rawget(t, 2)
elseif k == "z" then return rawget(t, 3)
elseif k == "w" then return rawget(t, 4)
end
end
--- @param t ImVec4
--- @param k int
--- @param v number
MT.ImVec4.__newindex = function(t, k, v)
if k == "x" then rawset(t, 1, v)
elseif k == "y" then rawset(t, 2, v)
elseif k == "z" then rawset(t, 3, v)
elseif k == "w" then rawset(t, 4, v)
end
end
--- @param x? number
--- @param y? number
--- @param z? number
--- @param w? number
--- @return ImVec4
--- @nodiscard
function ImVec4(x, y, z, w) return setmetatable({x or 0, y or 0, z or 0, w or 0}, MT.ImVec4) end
function MT.ImVec4.__add(lhs, rhs) return ImVec4(lhs[1] + rhs[1], lhs[2] + rhs[2], lhs[3] + rhs[3], lhs[4] + rhs[4]) end
function MT.ImVec4.__sub(lhs, rhs) return ImVec4(lhs[1] - rhs[1], lhs[2] - rhs[2], lhs[3] - rhs[3], lhs[4] - rhs[4]) end
function MT.ImVec4.__mul(lhs, rhs) return ImVec4(lhs[1] * rhs, lhs[2] * rhs, lhs[3] * rhs, lhs[4] * rhs) end
function MT.ImVec4.__eq(lhs, rhs) return lhs[1] == rhs[1] and lhs[2] == rhs[2] and lhs[3] == rhs[3] and lhs[4] == rhs[4] end
function MT.ImVec4:__tostring() return string.format("ImVec4(%g, %g, %g, %g)", self.x, self.y, self.z, self.w) end
--- @param dest ImVec4
--- @param src ImVec4
function ImVec4_Copy(dest, src) dest[1] = src[1]; dest[2] = src[2]; dest[3] = src[3]; dest[4] = src[4] end
--- A compact ImVector clone
--- @class ImVector<T>
--- @field Data T[] # 1-based table
--- @field Size int # >= 0
--- @field _Constructor function
--- @field _CopyFunc function
MT.ImVector = {}
-- Support 1-based number key indexing while keep method accessing speed
--- @param t ImVector
--- @param k string|int
--- @return any
MT.ImVector.__index = function(t, k)
return MT.ImVector[k] or t.Data[IM_ASSERT(k >= 1 and k <= t.Size) or k] -- if the mt access turns out nil, the k must be int index into Data
end
--- @param t ImVector
--- @param k int
--- @param v any
MT.ImVector.__newindex = function(t, k, v)
IM_ASSERT(k >= 1 and k <= t.Size)
t.Data[k] = v
end
local _default_constructor = function() return nil end
local _default_copyfunc = function(t, k, v) t[k] = v end
local function _grow_capacity(v, sz) local new_capacity = (v.Capacity ~= 0) and (v.Capacity + v.Capacity / 2) or 8; return (new_capacity > sz) and new_capacity or sz; end
--- @param T? function
--- @param COPY_FUNC? function
--- @return ImVector
--- @nodiscard
function ImVector(T, COPY_FUNC) return setmetatable({Data = {}, Size = 0, Capacity = 0, _Constructor = T or _default_constructor, _CopyFunc = COPY_FUNC or _default_copyfunc}, MT.ImVector) end
function MT.ImVector:push_back(value) if self.Size == self.Capacity then self:reserve(_grow_capacity(self, self.Size + 1)) end; self._CopyFunc(self.Data, self.Size + 1, value); self.Size = self.Size + 1; return value end
function MT.ImVector:pop_back() IM_ASSERT(self.Size > 0); self.Size = self.Size - 1; end
function MT.ImVector:push_front(value) if self.Size == 0 then self:push_back(value) else self:insert(1, value) end end
function MT.ImVector:clear() self.Size = 0 end
function MT.ImVector:clear_delete() for i = 1, self.Size do self.Data[i] = nil end self.Size = 0 end
function MT.ImVector:empty() return self.Size == 0 end
function MT.ImVector:back() IM_ASSERT(self.Size > 0) return self.Data[self.Size] end
function MT.ImVector:erase(i) IM_ASSERT(i >= 1 and i <= self.Size) local removed = (table.remove(self.Data, i)) ~= nil self.Size = self.Size - 1 return removed end
local function _iter(v, i) i = i + 1 if i <= v.Size then return i, v.Data[i] end end
function MT.ImVector:iter() return _iter, self, 0 end
function MT.ImVector:find_index(value) for i = 1, self.Size do if self.Data[i] == value then return i end end return nil end
function MT.ImVector:erase_unsorted(index) IM_ASSERT(index >= 1 and index <= self.Size) local last_idx = self.Size if index ~= last_idx then self.Data[index] = self.Data[last_idx] end self.Data[last_idx] = nil self.Size = self.Size - 1 return true end
function MT.ImVector:find_erase(value) local idx = self:find_index(value) if idx then return self:erase(idx) end return false end
function MT.ImVector:find_erase_unsorted(value) local idx = self:find_index(value) if idx then return self:erase_unsorted(idx) end return false end
function MT.ImVector:reserve(new_capacity)
if new_capacity <= self.Capacity then return end
local new_data = IM_ALLOC(self._Constructor, self.Size + 1, new_capacity)
if self.Data then
ImStd.memmove(new_data, 1, self.Data, 1, self.Size)
IM_FREE(self, "Data")
end
self.Data = new_data
self.Capacity = new_capacity
end
function MT.ImVector:reserve_discard(new_capacity)
if new_capacity <= self.Capacity then return end
if self.Data then IM_FREE(self, "Data") end
self.Data = IM_ALLOC(self._Constructor, 1, new_capacity)
self.Capacity = new_capacity
end
function MT.ImVector:shrink(new_size) IM_ASSERT(new_size <= self.Size) self.Size = new_size end
function MT.ImVector:resize(new_size, v)
if new_size > self.Capacity then self:reserve(_grow_capacity(self, new_size)) end
if v ~= nil and new_size > self.Size then
local data = self.Data
for n = self.Size + 1, new_size do data[n] = v end
end
self.Size = new_size
end
function MT.ImVector:swap(other) self.Size, other.Size = other.Size, self.Size; self.Capacity, other.Capacity = other.Capacity, self.Capacity; self.Data, other.Data = other.Data, self.Data end
function MT.ImVector:contains(v) for i = 1, self.Size do if self.Data[i] == v then return true end end return false end
--- NOTE: This currently does not use type-aware copy!
function MT.ImVector:insert(pos, value) IM_ASSERT(pos >= 1 and pos <= self.Size + 1); if self.Size == self.Capacity then self:reserve(_grow_capacity(self, self.Size + 1)) end; for i = self.Size, pos, -1 do self.Data[i + 1] = self.Data[i] end self.Data[pos] = value self.Size = self.Size + 1 return value end
--- @nodiscard
function MT.ImVector:copy() local other = ImVector() other.Size = self.Size for i = 1, self.Size do other.Data[i] = self.Data[i] end return other end
-- Not keeping value-key records inside `ImVector`, instead just find it
--- @return int # 0-based index
function MT.ImVector:index_from_ptr(p)
local data = self.Data
local size = self.Size
local mid = bit.rshift(size, 1)
for i = size, mid + 1, -1 do if data[i] == p then return i - 1 end end
for i = 1, mid, 1 do if data[i] == p then return i - 1 end end
--- @diagnostic disable-next-line
IM_ASSERT(false, "index_from_ptr failed!")
end
--- @class ImDrawCmd
MT.ImDrawCmd = {}
MT.ImDrawCmd.__index = MT.ImDrawCmd
--- @return ImDrawCmd
--- @nodiscard
function ImDrawCmd()
return setmetatable({
ClipRect = ImVec4(),
TexRef = nil,
VtxOffset = 0,
IdxOffset = 0,
ElemCount = 0,
UserCallback = nil,
UserCallbackData = nil,
UserCallbackDataSize = 0,
UserCallbackDataOffset = 0
}, MT.ImDrawCmd)
end
--- @return ImTextureID
function MT.ImDrawCmd:GetTexID()
local tex_id = (self.TexRef._TexData) and self.TexRef._TexData.TexID or self.TexRef._TexID
if self.TexRef._TexData ~= nil then
IM_ASSERT(tex_id ~= ImTextureID_Invalid, "ImDrawCmd is referring to ImTextureData that wasn't uploaded to graphics system. Backend must call ImTextureData::SetTexID() after handling ImTextureStatus_WantCreate request!")
end
return tex_id
end
--- @class ImDrawVert
--- @field [1] ImVec2 # pos
--- @field [2] ImVec2 # uv
--- @field [3] ImU32 # col
--- @return ImDrawVert
--- @nodiscard
function ImDrawVert() return { ImVec2(), ImVec2(), nil } end
--- @class ImDrawCmdHeader
--- @field ClipRect ImVec4
--- @field TexRef ImTextureRef
--- @field VtxOffset unsigned_int
MT.ImDrawCmdHeader = {}
MT.ImDrawCmdHeader.__index = MT.ImDrawCmdHeader
--- @return ImDrawCmdHeader
--- @nodiscard
function ImDrawCmdHeader()
return setmetatable({
ClipRect = ImVec4(),
TexRef = nil,
VtxOffset = 0
}, MT.ImDrawCmdHeader)
end
--- @class ImDrawChannel
--- @field _CmdBuffer ImVector<ImDrawCmd>
--- @field _IdxBuffer ImVector<ImDrawIdx>
--- @return ImDrawChannel
--- @nodiscard
function ImDrawChannel()
return {
_CmdBuffer = ImVector(),
_IdxBuffer = ImVector()
}
end
--- @class ImDrawListSplitter
--- @field _Current int
--- @field _Count int
--- @field _Channels ImVector<ImDrawChannel>
--- @return ImDrawListSplitter
--- @nodiscard
function ImDrawListSplitter()
return {
_Current = 0,
_Count = 0,
_Channels = ImVector()
}
end
--- @class ImDrawList
--- @field CmdBuffer ImVector<ImDrawCmd>
--- @field IdxBuffer ImVector<ImDrawIdx>
--- @field VtxBuffer ImVector<ImDrawVert>
--- @field Flags ImDrawListFlags
--- @field _VtxCurrentIdx unsigned_int # 1-based, generally == (VtxBuffer.Size + 1)
--- @field _Data ImDrawListSharedData # Pointes to shared draw data
--- @field _VtxWritePtr unsigned_int # 1-based, points to the current writing index in VtxBuffer.Data
--- @field _IdxWritePtr unsigned_int # 1-based, points to the current writing index in IdxBuffer.Data
--- @field _Path ImVector<ImVec2> # current path building
--- @field _CmdHeader ImDrawCmdHeader # template of active commands. Fields should match those of CmdBuffer:back()
--- @field _Splitter ImDrawListSplitter
--- @field _ClipRectStack ImVector<ImVec4>
--- @field _TextureStack ImVector<ImTextureRef>
--- @field _CallbacksDataBuf any
--- @field _FringeScale float
--- @field _OwnerName string
MT.ImDrawList = {}
MT.ImDrawList.__index = MT.ImDrawList
--- @param pos ImVec2
--- @param uv ImVec2
--- @param col ImU32
function MT.ImDrawList:PrimWriteVtx(pos, uv, col)
local vtx = self.VtxBuffer.Data[self._VtxWritePtr]
ImVec2_Copy(vtx[1], pos)
ImVec2_Copy(vtx[2], uv)
vtx[3] = col
self._VtxWritePtr = self._VtxWritePtr + 1
self._VtxCurrentIdx = self._VtxCurrentIdx + 1
end
--- @param idx ImDrawIdx
function MT.ImDrawList:PrimWriteIdx(idx)
self.IdxBuffer.Data[self._IdxWritePtr] = idx
self._IdxWritePtr = self._IdxWritePtr + 1
end
--- @param pos ImVec2
--- @param uv ImVec2
--- @param col ImU32
function MT.ImDrawList:PrimVtx(pos, uv, col)
self:PrimWriteIdx(self._VtxCurrentIdx)
self:PrimWriteVtx(pos, uv, col)
end
--- @param data? ImDrawListSharedData
--- @return ImDrawList
--- @nodiscard
function ImDrawList(data)
--- @type ImDrawList
local this = setmetatable({
CmdBuffer = ImVector(),
IdxBuffer = ImVector(),
VtxBuffer = ImVector(ImDrawVert),
Flags = 0,
_VtxCurrentIdx = 1,
_Data = nil,
_VtxWritePtr = 1,
_IdxWritePtr = 1,
_Path = ImVector(ImVec2, ImVec2_TCopy),
_CmdHeader = ImDrawCmdHeader(),
_Splitter = ImDrawListSplitter(),
_ClipRectStack = ImVector(),
_TextureStack = ImVector(),
_CallbacksDataBuf = nil,
_FringeScale = 0,
_OwnerName = nil
}, MT.ImDrawList)
this:_SetDrawListSharedData(data)
return this
end
--- @class ImDrawData
--- @field Valid bool
--- @field CmdListsCount int
--- @field TotalIdxCount int
--- @field TotalVtxCount int
--- @field CmdLists ImVector<ImDrawList>
--- @field DisplayPos ImVec2
--- @field DisplaySize ImVec2
--- @field FramebufferScale ImVec2
--- @field OwnerViewport ImGuiViewport
--- @field Textures ImVector<ImTextureData>
MT.ImDrawData = {}
MT.ImDrawData.__index = MT.ImDrawData
--- @return ImDrawData
function ImDrawData()
--- @type ImDrawData
local this = setmetatable({}, MT.ImDrawData)
this.CmdLists = ImVector()
this:Clear()
return this
end
--- @class ImTextureData
--- @field UniqueID int
--- @field Status ImTextureStatus
--- @field BackendUserData any
--- @field TexID ImTextureID
--- @field Format ImTextureFormat
--- @field Width int
--- @field Height int
--- @field BytesPerPixel int
--- @field Pixels unsigned_char[]
--- @field UsedRect ImTextureRect
--- @field UpdateRect ImTextureRect
--- @field Updates ImVector<ImTextureRect>
--- @field UnusedFrames int
--- @field RefCount unsigned_short
--- @field UseColors bool
--- @field WantDestroyNextFrame bool
MT.ImTextureData = {}
MT.ImTextureData.__index = MT.ImTextureData
--- @return ImTextureData
--- @nodiscard
function ImTextureData()
--- @type ImTextureData
local this = setmetatable({}, MT.ImTextureData)
this.UniqueID = 0
this.Status = ImTextureStatus.Destroyed
this.BackendUserData = nil
this.TexID = ImTextureID_Invalid
this.Format = 0
this.Width = 0
this.Height = 0
this.BytesPerPixel = 0
this.Pixels = nil
this.UsedRect = ImTextureRect()
this.UpdateRect = ImTextureRect()
this.Updates = ImVector()
this.UnusedFrames = 0
this.RefCount = 0
this.UseColors = false
this.WantDestroyNextFrame = false
return this
end
--- @param x int
--- @param y int
function MT.ImTextureData:GetPixelsAt(x, y)
return self.Pixels, (x + y * self.Width) * self.BytesPerPixel + 1
end
function MT.ImTextureData:GetPitch() return self.Width * self.BytesPerPixel end
function MT.ImTextureData:GetTexID() return self.TexID end
--- @param tex_id ImTextureID
function MT.ImTextureData:SetTexID(tex_id) self.TexID = tex_id end
--- @param status ImTextureStatus
function MT.ImTextureData:SetStatus(status) self.Status = status if (status == ImTextureStatus.Destroyed and not self.WantDestroyNextFrame and self.Pixels ~= nil) then self.Status = ImTextureStatus.WantCreate end end
--- @class ImTextureRef
MT.ImTextureRef = {}
MT.ImTextureRef.__index = MT.ImTextureRef
--- @return ImTextureRef
--- @nodiscard
function ImTextureRef(tex_id)
return setmetatable({
_TexData = nil,
_TexID = tex_id or ImTextureID_Invalid
}, MT.ImTextureRef)
end
--- @class ImFontBaked
--- @field IndexAdvanceX ImVector<float> # Glyphs->AdvanceX in a directly indexable way. Note that codepoint starts from 0, so IndexAdvanceX.Data[0 + 1] holds the advanceX of glyph at codepoint 0
--- @field FallbackAdvanceX float
--- @field Size float
--- @field RasterizerDensity float
--- @field IndexLookup ImVector<ImU16> # Index glyphs by Unicode codepoint. use IndexLookup.Data[codepoint + 1] for codepoint. Stores 1-based index!
--- @field Glyphs ImVector<ImFontGlyph>
--- @field FallbackGlyphIndex int # Initial value = -1, then becomes 1-based index if fallback char is set
--- @field Ascent float
--- @field Descent float
--- @field MetricsTotalSurface unsigned_int
--- @field WantDestroy bool
--- @field LoadNoFallback bool
--- @field LoadNoRenderOnLayout bool
--- @field LastUsedFrame int
--- @field BakedId ImGuiID
--- @field OwnerFont ImFont
--- @field FontLoaderDatas any
MT.ImFontBaked = {}
MT.ImFontBaked.__index = MT.ImFontBaked
--- @return ImFontBaked
--- @nodiscard
function ImFontBaked()
--- @type ImFontBaked
local this = setmetatable({}, MT.ImFontBaked)
this.IndexAdvanceX = ImVector()
this.FallbackAdvanceX = 0
this.Size = 0
this.RasterizerDensity = 0
this.IndexLookup = ImVector()
this.Glyphs = ImVector()
this.FallbackGlyphIndex = -1
this.Ascent = 0
this.Descent = 0
this.MetricsTotalSurface = 0
this.WantDestroy = false
this.LoadNoFallback = false
this.LoadNoRenderOnLayout = false
this.LastUsedFrame = 0
this.BakedId = 0
this.OwnerFont = nil
this.FontLoaderDatas = nil
return this
end
--- @class ImFont
--- @field LastBaked ImFontBaked
--- @field OwnerAtlas ImFontAtlas
--- @field Flags ImFontFlags
--- @field CurrentRasterizerDensity float
--- @field FontId ImGuiID
--- @field LegacySize float
--- @field Sources ImVector<ImFontConfig>
--- @field EllipsisChar ImWchar
--- @field FallbackChar ImWchar
--- @field Used8kPagesMap ImU8[] # 1-based table
--- @field EllipsisAutoBake bool
--- @field RemapPairs table<ImGuiID, any> # LUA: No ImGuiStorage
--- @field Scale float
MT.ImFont = {}
MT.ImFont.__index = MT.ImFont
function MT.ImFont:IsLoaded() return self.OwnerAtlas ~= nil end
--- @return ImFont
--- @nodiscard
function ImFont()
--- @type ImFont
local this = setmetatable({}, MT.ImFont)
this.LastBaked = nil
this.OwnerAtlas = nil
this.Flags = 0
this.CurrentRasterizerDensity = 0
this.FontId = 0
this.LegacySize = 0
this.Sources = ImVector()
this.EllipsisChar = 0
this.FallbackChar = 0
this.Used8kPagesMap = {}
this.EllipsisAutoBake = false
this.RemapPairs = {}
this.Scale = 0
return this
end
--- @class ImFontConfig
--- @field Name string
--- @field FontData table
--- @field FontDataSize int
--- @field FontDataOwnedByAtlas bool
--- @field MergeMode bool
--- @field PixelSnapH bool
--- @field OversampleH ImS8
--- @field OversampleV ImS8
--- @field EllipsisChar ImWchar
--- @field SizePixels float
--- @field GlyphRanges ImWchar[]
--- @field GlyphExcludeRanges ImWchar[]
--- @field GlyphOffset ImVec2
--- @field GlyphMinAdvanceX float
--- @field GlyphMaxAdvanceX float
--- @field GlyphExtraAdvanceX float
--- @field FontNo ImU32
--- @field FontLoaderFlags unsigned_int
--- @field RasterizerMultiply float
--- @field RasterizerDensity float
--- @field ExtraSizeScale float
--- @field Flags ImFontFlags
--- @field DstFont ImFont
--- @field FontLoader ImFontLoader
--- @field FontLoaderData ImGui_ImplStbTrueType_FontSrcData|
MT.ImFontConfig = {}
MT.ImFontConfig.__index = MT.ImFontConfig
--- @return ImFontConfig
--- @nodiscard
function ImFontConfig()
--- @type ImFontConfig
local this = setmetatable({}, MT.ImFontConfig)
this.Name = nil
this.FontData = nil
this.FontDataSize = 0
this.FontDataOwnedByAtlas = true
this.MergeMode = false
this.PixelSnapH = false
this.OversampleH = 0
this.OversampleV = 0
this.EllipsisChar = 0
this.SizePixels = 0
this.GlyphRanges = nil
this.GlyphExcludeRanges = nil
this.GlyphOffset = ImVec2()
this.GlyphMinAdvanceX = 0
this.GlyphMaxAdvanceX = FLT_MAX
this.GlyphExtraAdvanceX = 0
this.FontNo = 0
this.FontLoaderFlags = 0
this.RasterizerMultiply = 1.0
this.RasterizerDensity = 1.0
this.ExtraSizeScale = 1.0
this.Flags = 0
this.DstFont = nil
this.FontLoader = nil
this.FontLoaderData = nil
return this
end
--- @class ImFontAtlas
--- @field Flags ImFontAtlasFlags
--- @field TexDesiredFormat ImTextureFormat
--- @field TexGlyphPadding int
--- @field TexMinWidth int
--- @field TexMinHeight int
--- @field TexMaxWidth int
--- @field TexMaxHeight int
--- @field TexRef ImTextureRef
--- @field TexData ImTextureData
--- @field TexList ImVector<ImTextureData>
--- @field Locked bool
--- @field RendererHasTextures bool
--- @field TexPixelsUseColors bool
--- @field TexUvScale ImVec2
--- @field TexUvWhitePixel ImVec2
--- @field Fonts ImVector<ImFont>
--- @field Sources ImVector<ImFontConfig>
--- @field TexUvLines ImVec4[] # 0-based table
--- @field TexNextUniqueID int
--- @field FontNextUniqueID int
--- @field DrawListSharedDatas ImVector<ImDrawListSharedData>
--- @field Builder ImFontAtlasBuilder
--- @field FontLoader ImFontLoader
--- @field FontLoaderName string
--- @field FontLoaderData any
--- @field FontLoaderFlags unsigned_int
--- @field RefCount int
--- @field OwnerContext ImGuiContext
MT.ImFontAtlas = {}
MT.ImFontAtlas.__index = MT.ImFontAtlas
--- @return ImFontAtlas
--- @nodiscard
function ImFontAtlas()
--- @type ImFontAtlas
local this = setmetatable({}, MT.ImFontAtlas)
this.Flags = 0
this.TexDesiredFormat = ImTextureFormat.RGBA32
this.TexGlyphPadding = 1
this.TexMinWidth = 512
this.TexMinHeight = 128
this.TexMaxWidth = 8192
this.TexMaxHeight = 8192
this.TexRef = ImTextureRef()
this.TexData = nil
this.TexList = ImVector()
this.Locked = false
this.RendererHasTextures = false
this.TexPixelsUseColors = nil
this.TexUvScale = nil
this.TexUvWhitePixel = nil
this.Fonts = ImVector()
this.Sources = ImVector()
this.TexUvLines = {} -- size = IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1
this.TexNextUniqueID = 1
this.FontNextUniqueID = 1
this.DrawListSharedDatas = ImVector()
this.Builder = nil
this.FontLoader = nil
this.FontLoaderName = nil
this.FontLoaderData = nil
this.FontLoaderFlags = nil
this.RefCount = 0
this.OwnerContext = nil
return this
end
--- @class ImFontAtlasRect
--- @field x unsigned_short
--- @field y unsigned_short
--- @field w unsigned_short
--- @field h unsigned_short
--- @field uv0 ImVec2
--- @field uv1 ImVec2
--- @alias ImFontAtlasRectId int
ImFontAtlasRectId_Invalid = -1
--- @return ImFontAtlasRect
--- @nodiscard
function ImFontAtlasRect()
return {
x = nil, y = nil,
w = nil, h = nil,
uv0 = ImVec2(),
uv1 = ImVec2()
}
end
--- @class ImFontGlyph
--- @field Colored boolean
--- @field Visible boolean
--- @field SourceIdx unsigned_int
--- @field Codepoint unsigned_int
--- @field AdvanceX float
--- @field X0 float
--- @field Y0 float
--- @field X1 float
--- @field Y1 float
--- @field U0 float
--- @field V0 float
--- @field U1 float
--- @field V1 float
--- @field PackId int
--- @return ImFontGlyph
--- @nodiscard
function ImFontGlyph()
return {
Colored = false,
Visible = false,
SourceIdx = 0,
Codepoint = 0,
AdvanceX = 0,
X0 = 0, Y0 = 0, X1 = 0, Y1 = 0,
U0 = 0, V0 = 0, U1 = 0, V1 = 0,
PackId = -1
}
end
--- @class ImGuiKeyData
--- @field Down bool
--- @field DownDuration float
--- @field DownDurationPrev float
--- @field AnalogValue float
--- @return ImGuiKeyData
--- @nodiscard
function ImGuiKeyData()
return {
Down = false,
DownDuration = nil,
DownDurationPrev = nil,
AnalogValue = nil
}
end
--- @enum ImGuiConfigFlags
ImGuiConfigFlags = {
None = 0,
NavEnableKeyboard = bit.lshift(1, 0), -- Master keyboard navigation enable flag. Enable full Tabbing + directional arrows + space/enter to activate
NavEnableGamepad = bit.lshift(1, 1), -- Master gamepad navigation enable flag. Backend also needs to set ImGuiBackendFlags.HasGamepad
NoMouse = bit.lshift(1, 4), -- Instruct dear imgui to disable mouse inputs and interactions
NoMouseCursorChange = bit.lshift(1, 5), -- Instruct backend to not alter mouse cursor shape and visibility. Use if the backend cursor changes are interfering with yours and you don't want to use SetMouseCursor() to change mouse cursor. You may want to honor requests from imgui by reading GetMouseCursor() yourself instead
NoKeyboard = bit.lshift(1, 6), -- Instruct dear imgui to disable keyboard inputs and interactions. This is done by ignoring keyboard events and clearing existing states
ViewportsEnable = bit.lshift(1, 10),
IsSRGB = bit.lshift(1, 20), -- Application is SRGB-aware
IsTouchScreen = bit.lshift(1, 21) -- Application is using a touch screen instead of a mouse
}
--- @class ImGuiIO
MT.ImGuiIO = {}
MT.ImGuiIO.__index = MT.ImGuiIO
--- @return ImGuiIO
function ImGuiIO()
local this = {
Ctx = nil,
KeyCtrl = false,
KeyShift = false,
KeyAlt = false,
KeySuper = false,
KeyMods = nil,
BackendFlags = ImGuiBackendFlags.None,
ConfigFlags = ImGuiConfigFlags.None,
DisplaySize = ImVec2(-1.0, -1.0),
DeltaTime = 1.0 / 60.0,
DisplayFramebufferScale = ImVec2(1.0, 1.0),
MousePos = ImVec2(),
MousePosPrev = ImVec2(),
WantSetMousePos = false,
MouseDelta = ImVec2(),
MouseDown = {[0] = false, [1] = false, [2] = false},
MouseWheel = 0,
MouseWheelH = 0,
MouseCtrlLeftAsRightClick = false,
MouseWheelRequestAxisSwap = false,
ConfigMacOSXBehaviors = false,
ConfigNavCursorVisibleAuto = true,
ConfigInputTrickleEventQueue = true,
ConfigWindowsResizeFromEdges = true,
ConfigViewportsNoAutoMerge = false,