-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglfw_opengl3_base.nim
125 lines (110 loc) · 3.81 KB
/
glfw_opengl3_base.nim
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
# Compiling:
# nim c glfw_opengl3_base
import std/[paths,math]
import ../utils/[appImGui, togglebutton]
when defined(windows):
when not defined(vcc): # imguinVcc.res TODO WIP
include ./res/resource
import tinydialogs
const MainWinWidth = 1024
const MainWinHeight = 800
#------
# main
#------
proc main() =
var win = createImGui(MainWinWidth, MainWinHeight, title="ImGui Window base")
defer: destroyImGui(win)
var
showDemoWindow = true
showAnotherWindow = false
showFirstWindow = true
fval = 0.5f
counter = 0
sBuf = newString(200)
sFnameSelected{.global.}:Path
sw:bool
strSw:string
if win.getTheme() == classic:
sw = false
strSw = "OFF"
else:
sw = true
strSw = "ON"
#-----------
# main loop
#-----------
while not win.handle.windowShouldClose:
glfwPollEvents()
newFrame()
if showDemoWindow:
igShowDemoWindow(addr showDemoWindow)
# show a simple window that we created ourselves.
if showFirstWindow:
igBegin("Nim: Dear ImGui test with Futhark", addr showFirstWindow, 0)
defer: igEnd()
if igToggleButton(strSw, sw):
if sw:
strSw = "ON"
win.setTheme(microsoft)
else:
strSw ="OFF"
win.setTheme(classic)
#
igText((ICON_FA_COMMENT & " " & getFrontendVersionString()).cstring)
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)
igText("%s %s", ICON_FA_COMMENT_DOTS & " Dear ImGui", igGetVersion())
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)
igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
igText(("Input result:" & sBuf).cstring)
igCheckbox("Demo window", addr showDemoWindow)
igCheckbox("Another window", addr showAnotherWindow)
igSliderFloat("Float", addr fval, 0.0f, 1.0f, "%.3f", 0)
igColorEdit3("Background color", win.ini.clearColor.array3, 0.ImGuiColorEditFlags)
# Show file open dialog
when defined(windows):
if igButton("Open file", vec2(0, 0)):
sFnameSelected = openFileDialog("File open dialog", (getCurrentDir() / "\0".Path).string, ["*.nim", "*.nims"], "Text file").Path
igSameLine(0.0f, -1.0f)
# Show hint
if igIsItemHovered(Imgui_HoveredFlagsDelayShort.cint) and igBeginTooltip():
igText("[Open file]")
const ary = [0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f]
igPlotLines("Curve", ary, overlayText = "Overlay string")
igText("Sin(time) = %.2f", sin(igGetTime()));
igEndTooltip();
let (_,fname,ext) = sFnameSelected.splitFile()
igText("Selected file = %s", (fname.string & ext).cstring)
# Counter up
if igButton("Button", vec2(0.0f, 0.0f)):
inc counter
igSameLine(0.0f, -1.0f)
igText("counter = %d", counter)
igText("Application average %.3f ms/frame (%.1f FPS)".cstring, (1000.0f / igGetIO().Framerate).cfloat, igGetIO().Framerate.cfloat)
igSeparatorText(ICON_FA_WRENCH & " Icon font test ")
igText(ICON_FA_TRASH_CAN & " Trash")
igText(ICON_FA_MAGNIFYING_GLASS_PLUS &
" " & ICON_FA_POWER_OFF &
" " & ICON_FA_MICROPHONE &
" " & ICON_FA_MICROCHIP &
" " & ICON_FA_VOLUME_HIGH &
" " & ICON_FA_SCISSORS &
" " & ICON_FA_SCREWDRIVER_WRENCH &
" " & ICON_FA_BLOG)
# show further samll window
if showAnotherWindow:
igBegin("imgui Another Window", addr showAnotherWindow, 0)
igText("Hello from imgui")
if igButton("Close me", vec2(0.0f, 0.0f)):
showAnotherWindow = false
igEnd()
#--------
# render
#--------
render(win)
if not showFirstWindow and not showDemoWindow and not showAnotherWindow:
win.handle.setWindowShouldClose(true) # Exit program
#### end while
#------
# main
#------
main()