-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nim
187 lines (158 loc) · 8.83 KB
/
main.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
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
import json, dynlib, strutils, sequtils, rdstdin
type
ImGuiCol = enum
Text = 0, TextDisabled, WindowBg, ChildBg, PopupBg,
Border, BorderShadow, FrameBg, FrameBgHovered, FrameBgActive,
TitleBg, TitleBgActive, TitleBgCollapsed, MenuBarBg,
ScrollbarBg, ScrollbarGrab, ScrollbarGrabHovered, ScrollbarGrabActive,
CheckMark, SliderGrab, SliderGrabActive, Button, ButtonHovered,
ButtonActive, Header, HeaderHovered, HeaderActive, Separator,
SeparatorHovered, SeparatorActive, ResizeGrip, ResizeGripHovered,
ResizeGripActive, Tab, TabHovered, TabActive, TabUnfocused,
TabUnfocusedActive, PlotLines, PlotLinesHovered, PlotHistogram,
PlotHistogramHovered, TableHeaderBg, TableBorderStrong, TableBorderLight,
TableRowBg, TableRowBgAlt, TextSelectedBg, DragDropTarget,
NavHighlight, NavWindowingHighlight, NavWindowingDimBg, ModalWindowDimBg,
COUNT
var theme2colors = %* {
"darkestGrey": "#141f2c",
"darkerGrey": "#2a2e39" ,
"darkGrey": "#363b4a",
"lightGrey": "#5a5a5a",
"lighterGrey": "#7A818C",
"evenLighterGrey": "#8491a3",
"black": "#0A0B0D",
"green": "#75f986",
"red": "#ff0062",
"white": "#fff"
}
var theme2 = %* { "colors": {} }
theme2["colors"][$(ImGuiCol.Text.int)] = %* [theme2Colors["white"], 1.0]
theme2["colors"][$(ImGuiCol.TextDisabled.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.WindowBg.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.ChildBg.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.PopupBg.int)] = %* [theme2Colors["white"], 1.0]
theme2["colors"][$(ImGuiCol.Border.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.BorderShadow.int)] = %* [theme2Colors["darkestGrey"], 1.0]
theme2["colors"][$(ImGuiCol.FrameBg.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.FrameBgHovered.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.FrameBgActive.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TitleBg.int)] = %* [theme2Colors["darkGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TitleBgActive.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TitleBgCollapsed.int)] = %* [theme2Colors["darkGrey"], 1.0]
theme2["colors"][$(ImGuiCol.MenuBarBg.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ScrollbarBg.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ScrollbarGrab.int)] = %* [theme2Colors["darkestGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ScrollbarGrabHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ScrollbarGrabActive.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.CheckMark.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.SliderGrab.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.SliderGrabActive.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.Button.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.ButtonHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ButtonActive.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.Header.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.HeaderHovered.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.HeaderActive.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.Separator.int)] = %* [theme2Colors["darkestGrey"], 1.0]
theme2["colors"][$(ImGuiCol.SeparatorHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.SeparatorActive.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ResizeGrip.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.ResizeGripHovered.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ResizeGripActive.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.Tab.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.TabHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TabActive.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TabUnfocused.int)] = %* [theme2Colors["darkGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TabUnfocusedActive.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.PlotLines.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.PlotLinesHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.PlotHistogram.int)] = %* [theme2Colors["lightGrey"], 1.0]
theme2["colors"][$(ImGuiCol.PlotHistogramHovered.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TableHeaderBg.int)] = %* [theme2Colors["black"], 1.0]
theme2["colors"][$(ImGuiCol.TableBorderStrong.int)] = %* [theme2Colors["lighterGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TableBorderLight.int)] = %* [theme2Colors["darkGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TableRowBg.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TableRowBgAlt.int)] = %* [theme2Colors["darkestGrey"], 1.0]
theme2["colors"][$(ImGuiCol.TextSelectedBg.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.DragDropTarget.int)] = %* [theme2Colors["darkGrey"], 1.0]
theme2["colors"][$(ImGuiCol.NavHighlight.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.NavWindowingHighlight.int)] = %* [theme2Colors["darkerGrey"], 1.0]
theme2["colors"][$(ImGuiCol.NavWindowingDimBg.int)] = %* [theme2Colors["darkestGrey"], 1.0]
theme2["colors"][$(ImGuiCol.ModalWindowDimBg.int)] = %* [theme2Colors["darkestGrey"], 1.0]
# Base font definitions
let baseFontDefs = @[
("roboto-regular", @[16, 18, 20, 24, 28, 32, 36, 48])
]
var fontDefs = %* { "defs": [
{"name": "roboto-regular", "size": 16},
{"name": "roboto-regular", "size": 18},
{"name": "roboto-regular", "size": 20},
{"name": "roboto-regular", "size": 24},
{"name": "roboto-regular", "size": 28},
{"name": "roboto-regular", "size": 32},
{"name": "roboto-regular", "size": 36},
{"name": "roboto-regular", "size": 48}
]
}
when defined(windows):
const ffiLib = "./xframesshared.dll"
elif defined(linux):
const ffiLib = "./libxframesshared.so"
elif defined(macosx):
const ffiLib = "./libxframesshared.dylib"
elif defined(bsd):
const ffiLib = "./libxframesshared.so"
else:
echo "Unsupported platform"
quit(1)
proc init(
assetsBasePath: cstring,
rawFontDefinitions: cstring,
rawStyleOverrideDefinitions: cstring,
onInit: proc(): void {.cdecl.},
onTextChanged: proc(id: cint, value: cstring): void {.cdecl.},
onComboChanged: proc(id: cint, selected_index: cint): void {.cdecl.} ,
onNumericValueChanged: proc(id: cint, value: cfloat): void {.cdecl.},
onBooleanValueChanged: proc(id: cint, value: bool): void {.cdecl.},
onMultipleNumericValuesChanged: proc(id: cint, values: pointer, num_values: cint): void {.cdecl.},
onClick: proc(id: cint): void {.cdecl.}
) {.importc, dynlib: ffiLib.}
proc setElement(elementJson: cstring) {.importc, dynlib: ffiLib.}
proc setChildren(parentId: cint, childrenJson: cstring) {.importc, dynlib: ffiLib.}
proc onInit(): void {.cdecl.} =
let rootNodeJsonData = %* {
"type": "node",
"id": 0,
"root": true
}
let unformattedTextJsonData = %* {
"type": "unformatted-text",
"id": 1,
"text": "Hello, world"
}
let childrenIdsJsonData = %* [1]
let rootNodeJson = $rootNodeJsonData
let unformattedTextJson = $unformattedTextJsonData
let childrenIdsJson = $childrenIdsJsonData
setElement(rootNodeJson.cstring())
setElement(unformattedTextJson.cstring())
setChildren(0, childrenIdsJson.cstring())
proc onTextChanged(id: cint, value: cstring): void {.cdecl.} =
echo "onTextChanged"
proc onComboChanged(id: cint, selected_index: cint): void {.cdecl.} =
echo "onComboChanged"
proc onNumericValueChanged(id: cint, value: cfloat): void {.cdecl.} =
echo "onNumericValueChanged"
proc onBooleanValueChanged(id: cint, value: bool): void {.cdecl.} =
echo "onBooleanValueChanged"
proc onMultipleNumericValuesChanged(id: cint, values: pointer, num_values: cint): void {.cdecl.} =
echo "onMultipleNumericValuesChanged"
proc onClick(id: cint): void {.cdecl.} =
echo "onClick"
var baseAssetsPath = "./assets"
var a = newString(baseAssetsPath.len)
let fontDefsJson = $fontDefs
let theme2Json = $theme2
init(baseAssetsPath.cstring(), fontDefsJson.cstring(), theme2Json.cstring(), onInit, onTextChanged, onComboChanged, onNumericValueChanged, onBooleanValueChanged, onMultipleNumericValuesChanged, onClick)
echo readLineFromStdin("Press enter to exit")