rev: 21c5e6d2f665d0e8b4ff917a51b664c895dab2ed tukan/tukan/imgui/init.sc -rw-r--r-- 13.2 KiB View raw Log this file
21c5e6d2f665 — Leonard Ritter * renamed project from Liminal to Tukan 2 years ago
                                                                                
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
import ..core

using import glm

let lib =
    import-c "imgui_loader.cpp"
        """"
            #include "imgui.h"
            #include "cimgui.h"
            #include "tukan/imgui_dock.h"
            #include <stdio.h>
        list
            \ "-I" (module-dir .. "/../../cdefs")
            \ "-I" (module-dir .. "/../../include")
            \ "-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H"

using lib filter "^(ig(.+)|Im(.+))$"

fn vec2-getter (f)
    var size = (nullof ImVec2)
    f size
    vec2 size.x size.y

fn GetWindowSize ()
    vec2-getter igGetWindowSize

fn GetWindowPos ()
    vec2-getter igGetWindowPos

fn SetNextWindowSize (size cond)
    igSetNextWindowSize
        ImVec2 size.x size.y
        if (none? cond) 0
        else cond

fn GetWindowContentRegionMin ()
    vec2-getter igGetWindowContentRegionMin

fn GetWindowContentRegionMax ()
    vec2-getter igGetWindowContentRegionMax

fn GetContentRegionAvail ()
    vec2-getter igGetContentRegionAvail

fn Begin (name p_opened flags)
    igBegin name
        if (none? p_opened) null
        else p_opened
        if (none? flags) 0
        else flags

fn BeginChild (id size border extra_flags)
    fn dispatch (f id)
        f id
            if (none? size)
                ImVec2 0 0
            else
                ImVec2 size.x size.y
            if (none? border) false
            else border
            if (none? extra_flags) 0
            else extra_flags
    if ((typeof id) == string)
        dispatch igBeginChild (id as rawstring)
    elseif ((typeof id) == rawstring)
        dispatch igBeginChild id
    else
        dispatch igBeginChildEx id

fn Button (text size)
    igButton text
        if (none? size)
            ImVec2 0 0
        else
            ImVec2 size.x size.y

fn ImageFN (user_texture_id size uv0 uv1 tint_col border_col)
    igImage user_texture_id
        ImVec2 size.x size.y
        if (none? uv0)
            ImVec2 0 0
        else
            ImVec2 uv0.x uv0.y
        if (none? uv1)
            ImVec2 1 1
        else
            ImVec2 uv1.x uv1.y
        if (none? tint_col)
            ImVec4 255 255 255 255
        else
            ImVec4 tint_col.x tint_col.y tint_col.z tint_col.w
        if (none? border_col)
            ImVec4 255 255 255 128
        else
            ImVec4 border_col.x border_col.y border_col.z border_col.w

fn mutable-value? (value)
    (typeof value) <: reference

fn Selectable (text selected flags size)
    call
        if (mutable-value? selected)
            igSelectableEx
        else
            igSelectable
        imply text rawstring
        if (none? selected) false
        else selected

        if (none? flags) 0
        else flags

        if (none? size)
            ImVec2 0 0
        else
            ImVec2 size.x size.y

fn CollapsingHeader (text args...)
    let sz = (va-countof args...)
    if (sz == 0)
        igCollapsingHeader text 0
    elseif (sz == 1)
        let arg = (va@ 0 args...)
        if (mutable-value? arg)
            igCollapsingHeaderEx text args...
        else
            igCollapsingHeader text args...
    else
        igCollapsingHeaderEx text args...

fn InputText (text buf buf_size flags callback userdata)
    igInputText text buf buf_size
        if (none? flags) 0
        else flags
        if (none? callback) null
        else callback
        if (none? userdata) null
        else userdata

fn InputInt (text v step step_fast extra_flags)
    igInputInt text v
        if (none? step) 1
        else step
        if (none? step_fast) 100
        else step_fast
        if (none? extra_flags) 0
        else extra_flags

fn InputFloat (text v step step_fast decimal_precision extra_flags)
    igInputFloat text v
        if (none? step) 0
        else step
        if (none? step_fast) 0
        else step_fast
        if (none? decimal_precision) -1
        else decimal_precision
        if (none? extra_flags) 0
        else extra_flags

fn DragFloat (text v v_speed v_min v_max display_format power)
    igDragFloat text v
        if (none? v_speed) 1
        else v_speed
        if (none? v_min) 0
        else v_min
        if (none? v_max) 0
        else v_max
        if (none? display_format) "%.3f"
        else display_format
        if (none? power) 1
        else power

define FLT_MAX 1e+37

fn PlotLines (text values args...)
    if (function-pointer? values)
        let values_getter data values_count values_offset overlay_text scale_min scale_max graph_size = values args...
        igPlotLines2 text values_getter data values_count
            if (none? values_offset) 0
            else values_offset
            if (none? overlay_text) null
            else overlay_text
            if (none? scale_min) FLT_MAX
            else scale_min
            if (none? scale_max) FLT_MAX
            else scale_max
            if (none? graph_size) (ImVec2 0 0)
            else graph_size
    else
        let values_count values_offset overlay_text scale_min scale_max graph_size stride = args...
        igPlotLines text values values_count
            if (none? values_offset) 0
            else values_offset
            if (none? overlay_text) null
            else overlay_text
            if (none? scale_min) FLT_MAX
            else scale_min
            if (none? scale_max) FLT_MAX
            else scale_max
            if (none? graph_size) (ImVec2 0 0)
            else graph_size
            if (none? stride) (sizeof f32)
            else stride

fn Dummy (size)
    var imsize = (ImVec2 size.x size.y)
    igDummy imsize

fn SameLine (pos_x spacing_w)
    igSameLine
        if (none? pos_x) 0
        else pos_x
        if (none? spacing_w) -1
        else spacing_w

fn PushID (id args...)
    let sz = (va-countof args...)
    if (sz == 0)
        if ((va-countof (forward-imply id rawstring)) != 0)
            igPushIDStr id
        elseif (pointer? id)
            igPushIDPtr id
        else
            igPushIDInt id
    else
        igPushIDStrRange id args...

fn GetID (id args...)
    let sz = (va-countof args...)
    if (sz == 0)
        if ((va-countof (forward-imply id rawstring)) != 0)
            igGetIDStr id
        else
            igGetIDPtr id
    else
        igGetIDStrRange id args...

fn BeginMenu (text enabled)
    igBeginMenu text
        if (none? enabled) true
        else enabled

fn MenuItem (text shortcut selected enabled)
    call
        if (mutable-value? selected) igMenuItemPtr
        else igMenuItem
        text
        if (none? shortcut) null
        if (none? selected) false
        else selected
        if (none? enabled) true
        else enabled

fn BeginPopupContextItem (str_id mouse_button)
    igBeginPopupContextItem str_id
        if (none? mouse_button) 1
        else mouse_button

fn ShowDemoWindow (p_open)
    igShowDemoWindow
        if (none? p_open) null
        else p_open

fn BeginDock (text opened extra_flags)
    igBeginDock text
        if (none? opened) null
        else opened
        if (none? extra_flags) 0
        else extra_flags

fn CalcTextSize (text text_end hide_text_after_double_hash wrap_width)
    var size = (nullof ImVec2)
    igCalcTextSize size text
        if (none? text_end) null
        else text_end
        if (none? hide_text_after_double_hash) false
        else hide_text_after_double_hash
        if (none? wrap_width) -1
        else wrap_width
    vec2 size.x size.y

fn IsMouseClicked (button repeat)
    igIsMouseClicked button
        if (none? repeat) false
        else repeat

fn IsMouseDragging (button lock_threshold)
    igIsMouseDragging
        if (none? button) 0
        else button
        if (none? lock_threshold) -1
        else lock_threshold

fn IsMouseHoveringRect (r_min r_max clip)
    igIsMouseHoveringRect
        ImVec2 r_min.x r_min.y
        ImVec2 r_max.x r_max.y
        if (none? clip) true
        else clip

fn GetItemRectMin ()
    vec2-getter igGetItemRectMin

fn GetItemRectMax ()
    vec2-getter igGetItemRectMax

fn GetItemRectSize ()
    vec2-getter igGetItemRectSize

fn GetMousePos ()
    vec2-getter igGetMousePos

#var api ($)
#foreach (k v) (pairs cimgui)
    if (.startswith k "ImGui")
        api # k = v
#foreach (k v) (pairs lc)
    if (.startswith k "ImGui")
        api # k = v

fn PushStyleVar (idx val)
    if ((typeof val) == vec2)
        igPushStyleVarVec idx
            ImVec2 val.x val.y
    else
        igPushStyleVar idx val

fn PopStyleVar (count)
    igPopStyleVar
        if (none? count) 1
        else count

fn PushStyleColor (idx val)
    igPushStyleColor idx
        ImVec4 val.x val.y val.z val.w

fn PopStyleColor (count)
    igPopStyleColor
        if (none? count) 1
        else count

fn GetCursorPos ()
    vec2-getter igGetCursorPos

fn SetCursorPos (local_pos)
    igSetCursorPos
        ImVec2 local_pos.x local_pos.y

fn GetColorU32 (idx alpha_mul)
    if ((typeof idx) == vec4)
        let col = idx
        var color =
            ImVec4 col.r col.g col.b col.a
        igGetColorU32Vec color
    else
        igGetColorU32 idx
            if (none? alpha_mul) 1
            else alpha_mul

typefn ImDrawList 'AddRect (self a b col rounding rounding_corners thickness)
    ImDrawList_AddRect self
        ImVec2 a.x a.y
        ImVec2 b.x b.y
        col
        if (none? rounding) 0
        else rounding
        if (none? rounding_corners) 0xf
        else rounding_corners
        if (none? thickness) 1
        else thickness

typefn ImDrawList 'AddRectFilled (self a b col rounding rounding_corners)
    ImDrawList_AddRectFilled self
        ImVec2 a.x a.y
        ImVec2 b.x b.y
        col
        if (none? rounding) 0
        else rounding
        if (none? rounding_corners) 0xf
        else rounding_corners

typefn ImDrawList 'AddText (self pos col text_begin text_end)
    ImDrawList_AddText self
        ImVec2 pos.x pos.y
        col
        text_begin
        if (none? text_end) null
        else text_end

fn ColorConvertHSVtoRGB (h s v)
    var r = 0.0
    var g = 0.0
    var b = 0.0
    igColorConvertHSVtoRGB h s v r g b
    return (load r) (load g) (load b)

fn ColorConvertRGBtoHSV (r g b)
    var h = 0.0
    var s = 0.0
    var v = 0.0
    igColorConvertRGBtoHSV r g b h s v
    return (load h) (load s) (load v)

do
    using lib filter "^Im(.+)$"

    let GetIO = igGetIO
    let GetStyle = igGetStyle

    let GetWindowSize
    let GetWindowPos
    let SetNextWindowSize
    let GetWindowContentRegionMin
    let GetWindowContentRegionMax
    let GetContentRegionAvail
    let GetFontSize = igGetFontSize

    let Render = igRender

    let Begin
    let End = igEnd
    let BeginChild
    let EndChild = igEndChild

    let Separator = igSeparator

    let Text = igText
    let Button
    let Image = ImageFN
    let Selectable
    let CollapsingHeader
    let InputText
    let InputInt
    let InputFloat
    let DragFloat
    let Checkbox = igCheckbox
    let PlotLines
    #let ValuesGetterFunc
    let TreeNode = igTreeNode
    let TreePop = igTreePop

    let Dummy
    let SameLine
    let GetCursorPos
    let GetCursorPosX = igGetCursorPosX
    let GetCursorPosY = igGetCursorPosY
    let SetCursorPos
    let SetCursorPosX = igSetCursorPosX
    let SetCursorPosY = igSetCursorPosY

    let PushID
    let PopID = igPopID
    let GetID

    let BeginMainMenuBar = igBeginMainMenuBar
    let BeginMenuBar = igBeginMenuBar
    let EndMenuBar = igEndMenuBar
    let BeginMenu
    let MenuItem
    let EndMenu = igEndMenu
    let EndMainMenuBar = igEndMainMenuBar

    let BeginPopupContextItem
    let EndPopup = igEndPopup

    let BeginTooltip = igBeginTooltip
    let EndTooltip = igEndTooltip

    let BeginGroup = igBeginGroup
    let EndGroup = igEndGroup

    let IsItemHovered = igIsItemHovered
    let IsItemActive = igIsItemActive
    let IsItemVisible = igIsItemVisible
    let IsAnyItemHovered = igIsAnyItemHovered
    let IsAnyItemActive = igIsAnyItemActive
    let GetItemRectMin
    let GetItemRectMax
    let GetItemRectSize

    let CalcTextSize

    let IsKeyDown = igIsKeyDown
    let IsKeyPressed = igIsKeyPressed
    let IsKeyReleased = igIsKeyReleased
    let IsMouseDown = igIsMouseDown
    let IsMouseClicked
    let IsMouseDoubleClicked = igIsMouseDoubleClicked
    let IsMouseReleased = igIsMouseReleased
    let IsAnyWindowHovered = igIsAnyWindowHovered
    let IsAnyWindowFocused = igIsAnyWindowFocused
    let IsWindowHovered = igIsWindowHovered
    let IsWindowFocused = igIsWindowFocused
    let IsMouseHoveringRect
    let IsMouseDragging
    let GetMousePos

    let PushFont = igPushFont
    let PopFont = igPopFont
    let GetFontSize = igGetFontSize
    let PushStyleVar
    let PopStyleVar
    let PushStyleColor
    let PopStyleColor
    let PushItemWidth = igPushItemWidth
    let PopItemWidth = igPopItemWidth
    let GetColorU32

    let GetTextLineHeight = igGetTextLineHeight
    let GetTextLineHeightWithSpacing = igGetTextLineHeightWithSpacing
    let GetItemsLineHeightWithSpacing = igGetFrameHeightWithSpacing

    let ShowDemoWindow
    let ShowUserGuide = igShowUserGuide

    let ColorConvertHSVtoRGB
        ColorConvertRGBtoHSV

    let SetMouseCursor = igSetMouseCursor

    let BeginWorkspace = igBeginWorkspace
    let EndWorkspace = igEndWorkspace
    let ShutdownDock = igShutdownDock
    let BeginDock
    let EndDock = igEndDock
    let SetDockActive = igSetDockActive
    let SetNextDock = igSetNextDock
    let DockDebugWindow = igDockDebugWindow

    let GetWindowDrawList = igGetWindowDrawList

    locals;