imgui.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. package imgui
  2. // #cgo CXXFLAGS: -std=c++11
  3. // #cgo CPPFLAGS: -DIMGUI_USE_WCHAR32 -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS
  4. // #cgo windows CPPFLAGS: -DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
  5. // #cgo windows LDFLAGS: -limm32
  6. // #include "imguiWrapper.h"
  7. import "C"
  8. import (
  9. "math"
  10. )
  11. // Version returns a version string e.g. "1.23".
  12. func Version() string {
  13. return C.GoString(C.iggGetVersion())
  14. }
  15. // CurrentIO returns access to the ImGui communication struct for the currently active context.
  16. func CurrentIO() IO {
  17. return IO{handle: C.iggGetCurrentIO()}
  18. }
  19. // CurrentStyle returns the UI Style for the currently active context.
  20. func CurrentStyle() Style {
  21. return Style(C.iggGetCurrentStyle())
  22. }
  23. // NewFrame starts a new ImGui frame, you can submit any command from this point until Render()/EndFrame().
  24. func NewFrame() {
  25. C.iggNewFrame()
  26. }
  27. // Render ends the ImGui frame, finalize the draw data.
  28. // After this method, call RenderedDrawData to retrieve the draw commands and execute them.
  29. func Render() {
  30. C.iggRender()
  31. }
  32. // EndFrame ends the ImGui frame. Automatically called by Render(), so most likely don't need to ever
  33. // call that yourself directly. If you don't need to render you may call EndFrame() but you'll have
  34. // wasted CPU already. If you don't need to render, better to not create any imgui windows instead!
  35. func EndFrame() {
  36. C.iggEndFrame()
  37. }
  38. func GetEventWaitingTime() float64 {
  39. return float64(C.iggGetEventWaitingTime())
  40. }
  41. // RenderedDrawData returns the created draw commands, which are valid after Render() and
  42. // until the next call to NewFrame(). This is what you have to render.
  43. func RenderedDrawData() DrawData {
  44. return DrawData(C.iggGetDrawData())
  45. }
  46. // ShowDemoWindow creates a demo/test window. Demonstrates most ImGui features.
  47. // Call this to learn about the library! Try to make it always available in your application!
  48. func ShowDemoWindow(open *bool) {
  49. openArg, openFin := wrapBool(open)
  50. defer openFin()
  51. C.iggShowDemoWindow(openArg)
  52. }
  53. // ShowUserGuide adds basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
  54. func ShowUserGuide() {
  55. C.iggShowUserGuide()
  56. }
  57. // BeginV pushes a new window to the stack and start appending to it.
  58. // You may append multiple times to the same window during the same frame.
  59. // If the open argument is provided, the window can be closed, in which case the value will be false after the call.
  60. //
  61. // Returns false if the window is currently not visible.
  62. // Regardless of the return value, End() must be called for each call to Begin().
  63. func BeginV(id string, open *bool, flags int) bool {
  64. idArg, idFin := wrapString(id)
  65. defer idFin()
  66. openArg, openFin := wrapBool(open)
  67. defer openFin()
  68. return C.iggBegin(idArg, openArg, C.int(flags)) != 0
  69. }
  70. // Begin calls BeginV(id, nil, 0).
  71. func Begin(id string) bool {
  72. return BeginV(id, nil, 0)
  73. }
  74. // End closes the scope for the previously opened window.
  75. // Every call to Begin() must be matched with a call to End().
  76. func End() {
  77. C.iggEnd()
  78. }
  79. // BeginChildV pushes a new child to the stack and starts appending to it.
  80. // flags are the WindowFlags to apply.
  81. func BeginChildV(id string, size Vec2, border bool, flags int) bool {
  82. idArg, idFin := wrapString(id)
  83. defer idFin()
  84. sizeArg, _ := size.wrapped()
  85. return C.iggBeginChild(idArg, sizeArg, castBool(border), C.int(flags)) != 0
  86. }
  87. // BeginChild calls BeginChildV(id, Vec2{0,0}, false, 0).
  88. func BeginChild(id string) bool {
  89. return BeginChildV(id, Vec2{}, false, 0)
  90. }
  91. // EndChild closes the scope for the previously opened child.
  92. // Every call to BeginChild() must be matched with a call to EndChild().
  93. func EndChild() {
  94. C.iggEndChild()
  95. }
  96. // WindowPos returns the current window position in screen space.
  97. // This is useful if you want to do your own drawing via the DrawList API.
  98. func WindowPos() Vec2 {
  99. var value Vec2
  100. valueArg, valueFin := value.wrapped()
  101. C.iggWindowPos(valueArg)
  102. valueFin()
  103. return value
  104. }
  105. // WindowSize returns the size of the current window.
  106. func WindowSize() Vec2 {
  107. var value Vec2
  108. valueArg, valueFin := value.wrapped()
  109. C.iggWindowSize(valueArg)
  110. valueFin()
  111. return value
  112. }
  113. // WindowWidth returns the width of the current window.
  114. func WindowWidth() float32 {
  115. return float32(C.iggWindowWidth())
  116. }
  117. // WindowHeight returns the height of the current window.
  118. func WindowHeight() float32 {
  119. return float32(C.iggWindowHeight())
  120. }
  121. // ContentRegionAvail returns the size of the content region that is available (based on the current cursor position).
  122. func ContentRegionAvail() Vec2 {
  123. var value Vec2
  124. valueArg, valueFin := value.wrapped()
  125. C.iggContentRegionAvail(valueArg)
  126. valueFin()
  127. return value
  128. }
  129. func IsWindowAppearing() bool {
  130. return C.iggIsWindowAppearing() != 0
  131. }
  132. func IsWindowCollapsed() bool {
  133. return C.iggIsWindowCollapsed() != 0
  134. }
  135. func IsWindowFocused(flags int) bool {
  136. return C.iggIsWindowFocused(C.int(flags)) != 0
  137. }
  138. func IsWindowHovered(flags int) bool {
  139. return C.iggIsWindowHovered(C.int(flags)) != 0
  140. }
  141. // SetNextWindowPosV sets next window position.
  142. // Call before Begin(). Use pivot=(0.5,0.5) to center on given point, etc.
  143. func SetNextWindowPosV(pos Vec2, cond Condition, pivot Vec2) {
  144. posArg, _ := pos.wrapped()
  145. pivotArg, _ := pivot.wrapped()
  146. C.iggSetNextWindowPos(posArg, C.int(cond), pivotArg)
  147. }
  148. // SetNextWindowPos calls SetNextWindowPosV(pos, 0, Vec{0,0})
  149. func SetNextWindowPos(pos Vec2) {
  150. SetNextWindowPosV(pos, 0, Vec2{})
  151. }
  152. // SetNextWindowSizeV sets next window size.
  153. // Set axis to 0.0 to force an auto-fit on this axis. Call before Begin().
  154. func SetNextWindowSizeV(size Vec2, cond Condition) {
  155. sizeArg, _ := size.wrapped()
  156. C.iggSetNextWindowSize(sizeArg, C.int(cond))
  157. }
  158. // SetNextWindowSize calls SetNextWindowSizeV(size, 0)
  159. func SetNextWindowSize(size Vec2) {
  160. SetNextWindowSizeV(size, 0)
  161. }
  162. // SetNextWindowContentSize sets next window content size (~ enforce the range of scrollbars).
  163. // Does not include window decorations (title bar, menu bar, etc.).
  164. // Set one axis to 0.0 to leave it automatic. This function must be called before Begin() to take effect.
  165. func SetNextWindowContentSize(size Vec2) {
  166. sizeArg, _ := size.wrapped()
  167. C.iggSetNextWindowContentSize(sizeArg)
  168. }
  169. // SetNextWindowFocus sets next window to be focused / front-most. Call before Begin().
  170. func SetNextWindowFocus() {
  171. C.iggSetNextWindowFocus()
  172. }
  173. // SetNextWindowBgAlpha sets next window background color alpha.
  174. // Helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg.
  175. func SetNextWindowBgAlpha(value float32) {
  176. C.iggSetNextWindowBgAlpha(C.float(value))
  177. }
  178. // PushFont adds the given font on the stack. Use DefaultFont to refer to the default font.
  179. func PushFont(font Font) {
  180. C.iggPushFont(font.handle())
  181. }
  182. // PopFont removes the previously pushed font from the stack.
  183. func PopFont() {
  184. C.iggPopFont()
  185. }
  186. // PushStyleColor pushes the current style color for given ID on a stack and sets the given one.
  187. // To revert to the previous color, call PopStyleColor().
  188. func PushStyleColor(id StyleColorID, color Vec4) {
  189. colorArg, _ := color.wrapped()
  190. C.iggPushStyleColor(C.int(id), colorArg)
  191. }
  192. // PopStyleColorV reverts the given amount of style color changes.
  193. func PopStyleColorV(count int) {
  194. C.iggPopStyleColor(C.int(count))
  195. }
  196. // PopStyleColor calls PopStyleColorV(1).
  197. func PopStyleColor() {
  198. PopStyleColorV(1)
  199. }
  200. // PushStyleVarFloat pushes a float value on the stack to temporarily modify a style variable.
  201. func PushStyleVarFloat(id StyleVarID, value float32) {
  202. C.iggPushStyleVarFloat(C.int(id), C.float(value))
  203. }
  204. // PushStyleVarVec2 pushes a Vec2 value on the stack to temporarily modify a style variable.
  205. func PushStyleVarVec2(id StyleVarID, value Vec2) {
  206. valueArg, _ := value.wrapped()
  207. C.iggPushStyleVarVec2(C.int(id), valueArg)
  208. }
  209. // PopStyleVarV reverts the given amount of style variable changes.
  210. func PopStyleVarV(count int) {
  211. C.iggPopStyleVar(C.int(count))
  212. }
  213. // PopStyleVar calls PopStyleVarV(1).
  214. func PopStyleVar() {
  215. PopStyleVarV(1)
  216. }
  217. // FontSize returns the current font size (= height in pixels) of the current font with the current scale applied.
  218. func FontSize() float32 {
  219. return float32(C.iggGetFontSize())
  220. }
  221. // CalcTextSize calculate the size of the text
  222. func CalcTextSize(text string, hideTextAfterDoubleHash bool, wrapWidth float32) Vec2 {
  223. CString := newStringBuffer(text)
  224. defer CString.free()
  225. var vec2 Vec2
  226. valueArg, returnFunc := vec2.wrapped()
  227. C.iggCalcTextSize((*C.char)(CString.ptr), C.int(CString.size), castBool(hideTextAfterDoubleHash), C.float(wrapWidth), valueArg)
  228. returnFunc()
  229. return vec2
  230. }
  231. // Get ColorU32 from Vec4
  232. func GetColorU32(col Vec4) uint {
  233. valueArg, _ := col.wrapped()
  234. return uint(C.iggGetColorU32(*valueArg))
  235. }
  236. func BeginDisabled(disabled bool) {
  237. C.iggBeginDisabled(castBool(disabled))
  238. }
  239. func EndDisabled() {
  240. C.iggEndDisabled()
  241. }
  242. func StyleColorsDark() {
  243. C.iggStyleColorsDark()
  244. }
  245. func StyleColorsClassic() {
  246. C.iggStyleColorsClassic()
  247. }
  248. func StyleColorsLight() {
  249. C.iggStyleColorsLight()
  250. }
  251. // PushItemWidth sets width of items for the common item+label case, in pixels.
  252. // 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels,
  253. // <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side).
  254. func PushItemWidth(width float32) {
  255. C.iggPushItemWidth(C.float(width))
  256. }
  257. // PopItemWidth must be called for each call to PushItemWidth().
  258. func PopItemWidth() {
  259. C.iggPopItemWidth()
  260. }
  261. // CalcItemWidth returns the width of items given pushed settings and current cursor position.
  262. func CalcItemWidth() float32 {
  263. return float32(C.iggCalcItemWidth())
  264. }
  265. // PushTextWrapPosV defines word-wrapping for Text() commands.
  266. // < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrapPosX' position in window local space.
  267. // Requires a matching call to PopTextWrapPos().
  268. func PushTextWrapPosV(wrapPosX float32) {
  269. C.iggPushTextWrapPos(C.float(wrapPosX))
  270. }
  271. // PushTextWrapPos calls PushTextWrapPosV(0.0).
  272. func PushTextWrapPos() {
  273. PushTextWrapPosV(0.0)
  274. }
  275. // PopTextWrapPos resets the last pushed position.
  276. func PopTextWrapPos() {
  277. C.iggPopTextWrapPos()
  278. }
  279. // PushID pushes the given identifier into the ID stack. IDs are hash of the entire stack!
  280. func PushID(id string) {
  281. idArg, idFin := wrapString(id)
  282. defer idFin()
  283. C.iggPushID(idArg)
  284. }
  285. // PopID removes the last pushed identifier from the ID stack.
  286. func PopID() {
  287. C.iggPopID()
  288. }
  289. // Text adds formatted text. See PushTextWrapPosV() or PushStyleColorV() for modifying the output.
  290. // Without any modified style stack, the text is unformatted.
  291. func Text(text string) {
  292. textArg, textFin := wrapString(text)
  293. defer textFin()
  294. // Internally we use ImGui::TextUnformatted, for the most direct call.
  295. C.iggTextUnformatted(textArg)
  296. }
  297. // LabelText adds text+label aligned the same way as value+label widgets.
  298. func LabelText(label, text string) {
  299. labelArg, labelFin := wrapString(label)
  300. defer labelFin()
  301. textArg, textFin := wrapString(text)
  302. defer textFin()
  303. C.iggLabelText(labelArg, textArg)
  304. }
  305. // ButtonV returning true if it is pressed.
  306. func ButtonV(id string, size Vec2) bool {
  307. idArg, idFin := wrapString(id)
  308. defer idFin()
  309. sizeArg, _ := size.wrapped()
  310. return C.iggButton(idArg, sizeArg) != 0
  311. }
  312. // Button calls ButtonV(id, Vec2{0,0}).
  313. func Button(id string) bool {
  314. return ButtonV(id, Vec2{})
  315. }
  316. func SmallButton(id string) bool {
  317. idArg, idFin := wrapString(id)
  318. defer idFin()
  319. return C.iggSmallButton(idArg) != 0
  320. }
  321. func InvisibleButton(id string, size Vec2) bool {
  322. idArg, idFin := wrapString(id)
  323. defer idFin()
  324. sizeArg, _ := size.wrapped()
  325. return C.iggInvisibleButton(idArg, sizeArg) != 0
  326. }
  327. func ArrowButton(id string, dir uint8) bool {
  328. idArg, idFin := wrapString(id)
  329. defer idFin()
  330. return C.iggArrowButton(idArg, C.uchar(dir)) != 0
  331. }
  332. func Bullet() {
  333. C.iggBullet()
  334. }
  335. // BulletText.
  336. // Text with a little bullet aligned to the typical tree node.
  337. func BulletText(text string) {
  338. textArg, textFin := wrapString(text)
  339. defer textFin()
  340. C.iggBulletText(textArg)
  341. }
  342. // ImageV adds an image based on given texture ID.
  343. // Refer to TextureID what this represents and how it is drawn.
  344. func ImageV(id TextureID, size Vec2, uv0, uv1 Vec2, tintCol, borderCol Vec4) {
  345. sizeArg, _ := size.wrapped()
  346. uv0Arg, _ := uv0.wrapped()
  347. uv1Arg, _ := uv1.wrapped()
  348. tintColArg, _ := tintCol.wrapped()
  349. borderColArg, _ := borderCol.wrapped()
  350. C.iggImage(id.handle(), sizeArg, uv0Arg, uv1Arg, tintColArg, borderColArg)
  351. }
  352. // Image calls ImageV(id, size, Vec2{0,0}, Vec2{1,1}, Vec4{1,1,1,1}, Vec4{0,0,0,0}).
  353. func Image(id TextureID, size Vec2) {
  354. ImageV(id, size, Vec2{X: 0, Y: 0}, Vec2{X: 1, Y: 1}, Vec4{X: 1, Y: 1, Z: 1, W: 1}, Vec4{X: 0, Y: 0, Z: 0, W: 0})
  355. }
  356. // ImageButtonV adds a button with an image, based on given texture ID.
  357. // Refer to TextureID what this represents and how it is drawn.
  358. // <0 framePadding uses default frame padding settings. 0 for no padding.
  359. func ImageButtonV(id TextureID, size Vec2, uv0, uv1 Vec2, framePadding int, bgCol Vec4, tintCol Vec4) bool {
  360. sizeArg, _ := size.wrapped()
  361. uv0Arg, _ := uv0.wrapped()
  362. uv1Arg, _ := uv1.wrapped()
  363. bgColArg, _ := bgCol.wrapped()
  364. tintColArg, _ := tintCol.wrapped()
  365. return C.iggImageButton(id.handle(), sizeArg, uv0Arg, uv1Arg, C.int(framePadding), bgColArg, tintColArg) != 0
  366. }
  367. // ImageButton calls ImageButtonV(id, size, Vec2{0,0}, Vec2{1,1}, -1, Vec4{0,0,0,0}, Vec4{1,1,1,1}).
  368. func ImageButton(id TextureID, size Vec2) bool {
  369. return ImageButtonV(id, size, Vec2{X: 0, Y: 0}, Vec2{X: 1, Y: 1}, -1, Vec4{X: 0, Y: 0, Z: 0, W: 0}, Vec4{X: 1, Y: 1, Z: 1, W: 1})
  370. }
  371. // Checkbox creates a checkbox in the selected state.
  372. // The return value indicates if the selected state has changed.
  373. func Checkbox(id string, selected *bool) bool {
  374. idArg, idFin := wrapString(id)
  375. defer idFin()
  376. selectedArg, selectedFin := wrapBool(selected)
  377. defer selectedFin()
  378. return C.iggCheckbox(idArg, selectedArg) != 0
  379. }
  380. func RadioButton(label string, active bool) bool {
  381. labelArg, labelFin := wrapString(label)
  382. defer labelFin()
  383. return C.iggRadioButton(labelArg, castBool(active)) != 0
  384. }
  385. // ProgressBarV creates a progress bar.
  386. // size (for each axis) < 0.0f: align to end, 0.0f: auto, > 0.0f: specified size
  387. func ProgressBarV(fraction float32, size Vec2, overlay string) {
  388. sizeArg, _ := size.wrapped()
  389. overlayArg, overlayFin := wrapString(overlay)
  390. defer overlayFin()
  391. C.iggProgressBar(C.float(fraction), sizeArg, overlayArg)
  392. }
  393. // ProgressBar calls ProgressBarV(fraction, Vec2{X: -1, Y: 0}, "").
  394. func ProgressBar(fraction float32) {
  395. ProgressBarV(fraction, Vec2{X: -1, Y: 0}, "")
  396. }
  397. // BeginComboV creates a combo box with complete control over the content to the user.
  398. // Call EndCombo() if this function returns true.
  399. // flags are the ComboFlags to apply.
  400. func BeginComboV(label, previewValue string, flags int) bool {
  401. labelArg, labelFin := wrapString(label)
  402. defer labelFin()
  403. previewValueArg, previewValueFin := wrapString(previewValue)
  404. defer previewValueFin()
  405. return C.iggBeginCombo(labelArg, previewValueArg, C.int(flags)) != 0
  406. }
  407. // BeginCombo calls BeginComboV(label, previewValue, 0).
  408. func BeginCombo(label, previewValue string) bool {
  409. return BeginComboV(label, previewValue, 0)
  410. }
  411. // EndCombo must be called if BeginComboV() returned true.
  412. func EndCombo() {
  413. C.iggEndCombo()
  414. }
  415. // DragFloatV creates a draggable slider for floats.
  416. func DragFloatV(label string, value *float32, speed, min, max float32, format string, power float32) bool {
  417. labelArg, labelFin := wrapString(label)
  418. defer labelFin()
  419. valueArg, valueFin := wrapFloat(value)
  420. defer valueFin()
  421. formatArg, formatFin := wrapString(format)
  422. defer formatFin()
  423. return C.iggDragFloat(labelArg, valueArg, C.float(speed), C.float(min), C.float(max), formatArg, C.float(power)) != 0
  424. }
  425. // DragFloat calls DragFloatV(label, value, 1.0, 0.0, 0.0, "%.3f", 1.0).
  426. func DragFloat(label string, value *float32) bool {
  427. return DragFloatV(label, value, 1.0, 0.0, 0.0, "%.3f", 1.0)
  428. }
  429. // DragIntV creates a draggable slider for integers.
  430. func DragIntV(label string, value *int32, speed float32, min, max int32, format string) bool {
  431. labelArg, labelFin := wrapString(label)
  432. defer labelFin()
  433. valueArg, valueFin := wrapInt32(value)
  434. defer valueFin()
  435. formatArg, formatFin := wrapString(format)
  436. defer formatFin()
  437. return C.iggDragInt(labelArg, valueArg, C.float(speed), C.int(min), C.int(max), formatArg) != 0
  438. }
  439. // DragInt calls DragIntV(label, value, 1.0, 0, 0, "%d").
  440. func DragInt(label string, value *int32) bool {
  441. return DragIntV(label, value, 1.0, 0, 0, "%d")
  442. }
  443. // SliderFloatV creates a slider for floats.
  444. func SliderFloatV(label string, value *float32, min, max float32, format string, power float32) bool {
  445. labelArg, labelFin := wrapString(label)
  446. defer labelFin()
  447. valueArg, valueFin := wrapFloat(value)
  448. defer valueFin()
  449. formatArg, formatFin := wrapString(format)
  450. defer formatFin()
  451. return C.iggSliderFloat(labelArg, valueArg, C.float(min), C.float(max), formatArg, C.float(power)) != 0
  452. }
  453. // SliderFloat calls SliderIntV(label, value, min, max, "%.3f", 1.0).
  454. func SliderFloat(label string, value *float32, min, max float32) bool {
  455. return SliderFloatV(label, value, min, max, "%.3f", 1.0)
  456. }
  457. // SliderFloat3V creates slider for a 3D vector.
  458. func SliderFloat3V(label string, values *[3]float32, min, max float32, format string, power float32) bool {
  459. labelArg, labelFin := wrapString(label)
  460. defer labelFin()
  461. formatArg, formatFin := wrapString(format)
  462. defer formatFin()
  463. cvalues := (*C.float)(&values[0])
  464. return C.iggSliderFloatN(labelArg, cvalues, 3, C.float(min), C.float(max), formatArg, C.float(power)) != 0
  465. }
  466. // SliderFloat3 calls SliderFloat3V(label, values, min, max, "%.3f", 1,0).
  467. func SliderFloat3(label string, values *[3]float32, min, max float32) bool {
  468. return SliderFloat3V(label, values, min, max, "%.3f", 1.0)
  469. }
  470. // SliderIntV creates a slider for integers.
  471. func SliderIntV(label string, value *int32, min, max int32, format string) bool {
  472. labelArg, labelFin := wrapString(label)
  473. defer labelFin()
  474. valueArg, valueFin := wrapInt32(value)
  475. defer valueFin()
  476. formatArg, formatFin := wrapString(format)
  477. defer formatFin()
  478. return C.iggSliderInt(labelArg, valueArg, C.int(min), C.int(max), formatArg) != 0
  479. }
  480. // SliderInt calls SliderIntV(label, value, min, max, "%d").
  481. func SliderInt(label string, value *int32, min, max int32) bool {
  482. return SliderIntV(label, value, min, max, "%d")
  483. }
  484. func VSliderIntV(label string, size Vec2, value *int32, min, max int32, format string, flags int) bool {
  485. labelArg, labelDeleter := wrapString(label)
  486. defer labelDeleter()
  487. sizeArg, _ := size.wrapped()
  488. valueArg, valueDeleter := wrapInt32(value)
  489. defer valueDeleter()
  490. formatArg, formatDeleter := wrapString(format)
  491. defer formatDeleter()
  492. return C.iggVSliderInt(labelArg, sizeArg, valueArg, C.int(min), C.int(max), formatArg, C.int(flags)) != 0
  493. }
  494. // InputText creates a text field for dynamic text input.
  495. //
  496. // Contrary to the original library, this wrapper does not limit the maximum number of possible characters.
  497. // Dynamic resizing of the internal buffer is handled within the wrapper and the user will never be called for such requests.
  498. //
  499. // The provided callback is called for any of the requested InputTextFlagsCallback* flags.
  500. //
  501. // To implement a character limit, provide a callback that drops input characters when the requested length has been reached.
  502. func InputTextWithHint(label, hint string, text *string, flags int, cb InputTextCallback) bool {
  503. if text == nil {
  504. panic("text can't be nil")
  505. }
  506. labelArg, labelFin := wrapString(label)
  507. defer labelFin()
  508. hintArg, hintFin := wrapString(hint)
  509. defer hintFin()
  510. state := newInputTextState(*text, cb)
  511. defer func() {
  512. *text = state.buf.toGo()
  513. state.release()
  514. }()
  515. return C.iggInputTextWithHint(labelArg, hintArg, (*C.char)(state.buf.ptr), C.uint(state.buf.size),
  516. C.int(flags|inputTextFlagsCallbackResize), state.key) != 0
  517. }
  518. func InputTextV(label string, text *string, flags int, cb InputTextCallback) bool {
  519. return InputTextWithHint(label, "", text, flags, cb)
  520. }
  521. // InputText calls InputTextV(label, string, 0, nil)
  522. func InputText(label string, text *string) bool {
  523. return InputTextV(label, text, 0, nil)
  524. }
  525. // InputTextMultilineV provides a field for dynamic text input of multiple lines.
  526. //
  527. // Contrary to the original library, this wrapper does not limit the maximum number of possible characters.
  528. // Dynamic resizing of the internal buffer is handled within the wrapper and the user will never be called for such requests.
  529. //
  530. // The provided callback is called for any of the requested InputTextFlagsCallback* flags.
  531. //
  532. // To implement a character limit, provide a callback that drops input characters when the requested length has been reached.
  533. func InputTextMultilineV(label string, text *string, size Vec2, flags int, cb InputTextCallback) bool {
  534. if text == nil {
  535. panic("text can't be nil")
  536. }
  537. labelArg, labelFin := wrapString(label)
  538. defer labelFin()
  539. sizeArg, _ := size.wrapped()
  540. state := newInputTextState(*text, cb)
  541. defer func() {
  542. *text = state.buf.toGo()
  543. state.release()
  544. }()
  545. return C.iggInputTextMultiline(labelArg, (*C.char)(state.buf.ptr), C.uint(state.buf.size), sizeArg,
  546. C.int(flags|inputTextFlagsCallbackResize), state.key) != 0
  547. }
  548. // InputTextMultiline calls InputTextMultilineV(label, text, Vec2{0,0}, 0, nil)
  549. func InputTextMultiline(label string, text *string) bool {
  550. return InputTextMultilineV(label, text, Vec2{}, 0, nil)
  551. }
  552. func InputInt(label string, value *int32) bool {
  553. return InputIntV(label, value, 0, 100, 0)
  554. }
  555. func InputIntV(label string, value *int32, step, step_fast int, flags int) bool {
  556. labelArg, labelFin := wrapString(label)
  557. defer labelFin()
  558. valueArg, valueFin := wrapInt32(value)
  559. defer valueFin()
  560. return C.iggInputInt(labelArg, valueArg, C.int(0), C.int(100), C.int(flags)) != 0
  561. }
  562. func InputFloat(label string, value *float32) bool {
  563. return InputFloatV(label, value, 0.0, 0.0, "%.3f", 0)
  564. }
  565. func InputFloatV(label string, value *float32, step, step_fast float32, format string, flags int) bool {
  566. labelArg, labelFin := wrapString(label)
  567. defer labelFin()
  568. valueArg, valueFin := wrapFloat(value)
  569. defer valueFin()
  570. formatArg, formatFin := wrapString(format)
  571. defer formatFin()
  572. return C.iggInputFloat(labelArg, valueArg, C.float(step), C.float(step_fast), formatArg, C.int(flags)) != 0
  573. }
  574. // ColorEdit3 calls ColorEdit3V(label, col, 0)
  575. func ColorEdit3(label string, col *[3]float32) bool {
  576. return ColorEdit3V(label, col, 0)
  577. }
  578. // ColorEdit3V will show a clickable little square which will open a color picker window for 3D vector (rgb format).
  579. func ColorEdit3V(label string, col *[3]float32, flags int) bool {
  580. labelArg, labelFin := wrapString(label)
  581. defer labelFin()
  582. ccol := (*C.float)(&col[0])
  583. return C.iggColorEdit3(labelArg, ccol, C.int(flags)) != 0
  584. }
  585. // ColorEdit4 calls ColorEdit4V(label, col, 0)
  586. func ColorEdit4(label string, col *[4]float32) bool {
  587. return ColorEdit4V(label, col, 0)
  588. }
  589. // ColorEdit4V will show a clickable little square which will open a color picker window for 4D vector (rgba format).
  590. func ColorEdit4V(label string, col *[4]float32, flags int) bool {
  591. labelArg, labelFin := wrapString(label)
  592. defer labelFin()
  593. ccol := (*C.float)(&col[0])
  594. return C.iggColorEdit4(labelArg, ccol, C.int(flags)) != 0
  595. }
  596. // ColorPicker3 calls ColorPicker3(label, col, 0)
  597. func ColorPicker3(label string, col *[3]float32, flags int) bool {
  598. return ColorPicker3V(label, col, 0)
  599. }
  600. // ColorPicker3V will show directly a color picker control for editing a color in 3D vector (rgb format).
  601. func ColorPicker3V(label string, col *[3]float32, flags int) bool {
  602. labelArg, labelFin := wrapString(label)
  603. defer labelFin()
  604. ccol := (*C.float)(&col[0])
  605. return C.iggColorPicker3(labelArg, ccol, C.int(flags)) != 0
  606. }
  607. // ColorPicker4 calls ColorPicker4(label, col, 0)
  608. func ColorPicker4(label string, col *[4]float32) bool {
  609. return ColorPicker4V(label, col, 0)
  610. }
  611. // ColorPicker4V will show directly a color picker control for editing a color in 4D vector (rgba format).
  612. func ColorPicker4V(label string, col *[4]float32, flags int) bool {
  613. labelArg, labelFin := wrapString(label)
  614. defer labelFin()
  615. ccol := (*C.float)(&col[0])
  616. return C.iggColorPicker4(labelArg, ccol, C.int(flags)) != 0
  617. }
  618. // Separator is generally horizontal. Inside a menu bar or in horizontal layout mode, this becomes a vertical separator.
  619. func Separator() {
  620. C.iggSeparator()
  621. }
  622. // SameLineV is between widgets or groups to layout them horizontally.
  623. func SameLineV(posX float32, spacingW float32) {
  624. C.iggSameLine(C.float(posX), C.float(spacingW))
  625. }
  626. // SameLine calls SameLineV(0, -1).
  627. func SameLine() {
  628. SameLineV(0, -1)
  629. }
  630. // Spacing adds vertical spacing.
  631. func Spacing() {
  632. C.iggSpacing()
  633. }
  634. // Dummy adds a dummy item of given size.
  635. func Dummy(size Vec2) {
  636. sizeArg, _ := size.wrapped()
  637. C.iggDummy(sizeArg)
  638. }
  639. // BeginGroup locks horizontal starting position + capture group bounding box into one "item"
  640. // (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.)
  641. func BeginGroup() {
  642. C.iggBeginGroup()
  643. }
  644. // EndGroup must be called for each call to BeginGroup().
  645. func EndGroup() {
  646. C.iggEndGroup()
  647. }
  648. // CursorPos returns the cursor position in window coordinates (relative to window position).
  649. func CursorPos() Vec2 {
  650. var value Vec2
  651. valueArg, valueFin := value.wrapped()
  652. C.iggCursorPos(valueArg)
  653. valueFin()
  654. return value
  655. }
  656. // CursorPosX returns the x-coordinate of the cursor position in window coordinates.
  657. func CursorPosX() float32 {
  658. return float32(C.iggCursorPosX())
  659. }
  660. // CursorPosY returns the y-coordinate of the cursor position in window coordinates.
  661. func CursorPosY() float32 {
  662. return float32(C.iggCursorPosY())
  663. }
  664. // CursorStartPos returns the initial cursor position in window coordinates.
  665. func CursorStartPos() Vec2 {
  666. var value Vec2
  667. valueArg, valueFin := value.wrapped()
  668. C.iggCursorStartPos(valueArg)
  669. valueFin()
  670. return value
  671. }
  672. // CursorScreenPos returns the cursor position in absolute screen coordinates.
  673. func CursorScreenPos() Vec2 {
  674. var value Vec2
  675. valueArg, valueFin := value.wrapped()
  676. C.iggCursorScreenPos(valueArg)
  677. valueFin()
  678. return value
  679. }
  680. // SetCursorPos sets the cursor relative to the current window.
  681. func SetCursorPos(localPos Vec2) {
  682. localPosArg, _ := localPos.wrapped()
  683. C.iggSetCursorPos(localPosArg)
  684. }
  685. // SetCursorScreenPos sets the cursor position in absolute screen coordinates.
  686. func SetCursorScreenPos(absPos Vec2) {
  687. absPosArg, _ := absPos.wrapped()
  688. C.iggSetCursorScreenPos(absPosArg)
  689. }
  690. // MousePos returns the mouse position in absolute screen coordinates.
  691. func MousePos() Vec2 {
  692. var value Vec2
  693. valueArg, valueFin := value.wrapped()
  694. C.iggMousePos(valueArg)
  695. valueFin()
  696. return value
  697. }
  698. // AlignTextToFramePadding vertically aligns upcoming text baseline to
  699. // FramePadding.y so that it will align properly to regularly framed
  700. // items. Call if you have text on a line before a framed item.
  701. func AlignTextToFramePadding() {
  702. C.iggAlignTextToFramePadding()
  703. }
  704. // TextLineHeight returns ~ FontSize.
  705. func TextLineHeight() float32 {
  706. return float32(C.iggGetTextLineHeight())
  707. }
  708. // TextLineHeightWithSpacing returns ~ FontSize + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of text).
  709. func TextLineHeightWithSpacing() float32 {
  710. return float32(C.iggGetTextLineHeightWithSpacing())
  711. }
  712. // FrameHeightWithSpacing return ~ FontSize + style.FramePadding.y * 2.0f + style.ItemSpacing.y;
  713. func FrameHeightWithSpacing() float32 {
  714. return float32(C.iggFrameHeightWithSpacing())
  715. }
  716. // TreeNodeV returns true if the tree branch is to be rendered. Call TreePop() in this case.
  717. func TreeNodeV(label string, flags int) bool {
  718. labelArg, labelFin := wrapString(label)
  719. defer labelFin()
  720. return C.iggTreeNode(labelArg, C.int(flags)) != 0
  721. }
  722. // TreeNode calls TreeNodeV(label, 0).
  723. func TreeNode(label string) bool {
  724. return TreeNodeV(label, 0)
  725. }
  726. // TreePop finishes a tree branch. This has to be called for a matching TreeNodeV call returning true.
  727. func TreePop() {
  728. C.iggTreePop()
  729. }
  730. // SetNextItemOpen sets the open/collapsed state of the following tree node.
  731. func SetNextItemOpen(open bool, cond Condition) {
  732. C.iggSetNextItemOpen(castBool(open), C.int(cond))
  733. }
  734. // TreeNodeToLabelSpacing returns the horizontal distance preceding label for a regular unframed TreeNode.
  735. func TreeNodeToLabelSpacing() float32 {
  736. return float32(C.iggGetTreeNodeToLabelSpacing())
  737. }
  738. // SelectableV returns true if the user clicked it, so you can modify your selection state.
  739. // flags are the SelectableFlags to apply.
  740. // size.x==0.0: use remaining width, size.x>0.0: specify width.
  741. // size.y==0.0: use label height, size.y>0.0: specify height
  742. func SelectableV(label string, selected bool, flags int, size Vec2) bool {
  743. labelArg, labelFin := wrapString(label)
  744. defer labelFin()
  745. sizeArg, _ := size.wrapped()
  746. return C.iggSelectable(labelArg, castBool(selected), C.int(flags), sizeArg) != 0
  747. }
  748. // Selectable calls SelectableV(label, false, 0, Vec2{0, 0})
  749. func Selectable(label string) bool {
  750. return SelectableV(label, false, 0, Vec2{})
  751. }
  752. // ListBoxV creates a list of selectables of given items with equal height, enclosed with header and footer.
  753. // This version accepts a custom item height.
  754. // The function returns true if the selection was changed. The value of currentItem will indicate the new selected item.
  755. func ListBoxV(label string, currentItem *int32, items []string, heightItems int) bool {
  756. labelArg, labelFin := wrapString(label)
  757. defer labelFin()
  758. valueArg, valueFin := wrapInt32(currentItem)
  759. defer valueFin()
  760. itemsCount := len(items)
  761. argv := make([]*C.char, itemsCount)
  762. for i, item := range items {
  763. itemArg, itemDeleter := wrapString(item)
  764. defer itemDeleter()
  765. argv[i] = itemArg
  766. }
  767. return C.iggListBoxV(labelArg, valueArg, &argv[0], C.int(itemsCount), C.int(heightItems)) != 0
  768. }
  769. // ListBox calls ListBoxV(label, currentItem, items, -1)
  770. // The function returns true if the selection was changed. The value of currentItem will indicate the new selected item.
  771. func ListBox(label string, currentItem *int32, items []string) bool {
  772. return ListBoxV(label, currentItem, items, -1)
  773. }
  774. // PlotLines draws an array of floats as a line graph.
  775. // It calls PlotLinesV using no overlay text and automatically calculated scale and graph size.
  776. func PlotLines(label string, values []float32) {
  777. PlotLinesV(label, values, 0, "", math.MaxFloat32, math.MaxFloat32, Vec2{})
  778. }
  779. // PlotLinesV draws an array of floats as a line graph with additional options.
  780. // valuesOffset specifies an offset into the values array at which to start drawing, wrapping around when the end of the values array is reached.
  781. // overlayText specifies a string to print on top of the graph.
  782. // scaleMin and scaleMax define the scale of the y axis, if either is math.MaxFloat32 that value is calculated from the input data.
  783. // graphSize defines the size of the graph, if either coordinate is zero the default size for that direction is used.
  784. func PlotLinesV(label string, values []float32, valuesOffset int, overlayText string, scaleMin float32, scaleMax float32, graphSize Vec2) {
  785. labelArg, labelFin := wrapString(label)
  786. defer labelFin()
  787. valuesCount := len(values)
  788. valuesArray := make([]C.float, valuesCount)
  789. for i, value := range values {
  790. valuesArray[i] = C.float(value)
  791. }
  792. var overlayTextArg *C.char
  793. if overlayText != "" {
  794. var overlayTextFinisher func()
  795. overlayTextArg, overlayTextFinisher = wrapString(overlayText)
  796. defer overlayTextFinisher()
  797. }
  798. graphSizeArg, _ := graphSize.wrapped()
  799. C.iggPlotLines(labelArg, &valuesArray[0], C.int(valuesCount), C.int(valuesOffset), overlayTextArg, C.float(scaleMin), C.float(scaleMax), graphSizeArg)
  800. }
  801. // PlotHistogram draws an array of floats as a bar graph.
  802. // It calls PlotHistogramV using no overlay text and automatically calculated scale and graph size.
  803. func PlotHistogram(label string, values []float32) {
  804. PlotHistogramV(label, values, 0, "", math.MaxFloat32, math.MaxFloat32, Vec2{})
  805. }
  806. // PlotHistogramV draws an array of floats as a bar graph with additional options.
  807. // valuesOffset specifies an offset into the values array at which to start drawing, wrapping around when the end of the values array is reached.
  808. // overlayText specifies a string to print on top of the graph.
  809. // scaleMin and scaleMax define the scale of the y axis, if either is math.MaxFloat32 that value is calculated from the input data.
  810. // graphSize defines the size of the graph, if either coordinate is zero the default size for that direction is used.
  811. func PlotHistogramV(label string, values []float32, valuesOffset int, overlayText string, scaleMin float32, scaleMax float32, graphSize Vec2) {
  812. labelArg, labelFin := wrapString(label)
  813. defer labelFin()
  814. valuesCount := len(values)
  815. valuesArray := make([]C.float, valuesCount)
  816. for i, value := range values {
  817. valuesArray[i] = C.float(value)
  818. }
  819. var overlayTextArg *C.char
  820. if overlayText != "" {
  821. var overlayTextFinisher func()
  822. overlayTextArg, overlayTextFinisher = wrapString(overlayText)
  823. defer overlayTextFinisher()
  824. }
  825. graphSizeArg, _ := graphSize.wrapped()
  826. C.iggPlotHistogram(labelArg, &valuesArray[0], C.int(valuesCount), C.int(valuesOffset), overlayTextArg, C.float(scaleMin), C.float(scaleMax), graphSizeArg)
  827. }
  828. // SetTooltip sets a text tooltip under the mouse-cursor, typically use with IsItemHovered().
  829. // Overrides any previous call to SetTooltip().
  830. func SetTooltip(text string) {
  831. textArg, textFin := wrapString(text)
  832. defer textFin()
  833. C.iggSetTooltip(textArg)
  834. }
  835. // BeginTooltip begins/appends to a tooltip window. Used to create full-featured tooltip (with any kind of contents).
  836. // Requires a call to EndTooltip().
  837. func BeginTooltip() {
  838. C.iggBeginTooltip()
  839. }
  840. // EndTooltip closes the previously started tooltip window.
  841. func EndTooltip() {
  842. C.iggEndTooltip()
  843. }
  844. // BeginMainMenuBar creates and appends to a full screen menu-bar.
  845. // If the return value is true, then EndMainMenuBar() must be called!
  846. func BeginMainMenuBar() bool {
  847. return C.iggBeginMainMenuBar() != 0
  848. }
  849. // EndMainMenuBar finishes a main menu bar.
  850. // Only call EndMainMenuBar() if BeginMainMenuBar() returns true!
  851. func EndMainMenuBar() {
  852. C.iggEndMainMenuBar()
  853. }
  854. // BeginMenuBar appends to menu-bar of current window.
  855. // This requires WindowFlagsMenuBar flag set on parent window.
  856. // If the return value is true, then EndMenuBar() must be called!
  857. func BeginMenuBar() bool {
  858. return C.iggBeginMenuBar() != 0
  859. }
  860. // EndMenuBar finishes a menu bar.
  861. // Only call EndMenuBar() if BeginMenuBar() returns true!
  862. func EndMenuBar() {
  863. C.iggEndMenuBar()
  864. }
  865. // BeginMenuV creates a sub-menu entry.
  866. // If the return value is true, then EndMenu() must be called!
  867. func BeginMenuV(label string, enabled bool) bool {
  868. labelArg, labelFin := wrapString(label)
  869. defer labelFin()
  870. return C.iggBeginMenu(labelArg, castBool(enabled)) != 0
  871. }
  872. // BeginMenu calls BeginMenuV(label, true).
  873. func BeginMenu(label string) bool {
  874. return BeginMenuV(label, true)
  875. }
  876. // EndMenu finishes a sub-menu entry.
  877. // Only call EndMenu() if BeginMenu() returns true!
  878. func EndMenu() {
  879. C.iggEndMenu()
  880. }
  881. // MenuItemV adds a menu item with given label.
  882. // Returns true if the item is selected.
  883. // If selected is not nil, it will be toggled when true is returned.
  884. // Shortcuts are displayed for convenience but not processed by ImGui at the moment.
  885. func MenuItemV(label string, shortcut string, selected bool, enabled bool) bool {
  886. labelArg, labelFin := wrapString(label)
  887. defer labelFin()
  888. shortcutArg, shortcutFin := wrapString(shortcut)
  889. defer shortcutFin()
  890. return C.iggMenuItem(labelArg, shortcutArg, castBool(selected), castBool(enabled)) != 0
  891. }
  892. // MenuItem calls MenuItemV(label, "", false, true).
  893. func MenuItem(label string) bool {
  894. return MenuItemV(label, "", false, true)
  895. }
  896. // OpenPopup marks popup as open (don't call every frame!).
  897. // Popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
  898. // By default, Selectable()/MenuItem() are calling CloseCurrentPopup().
  899. // Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
  900. func OpenPopup(id string) {
  901. idArg, idFin := wrapString(id)
  902. defer idFin()
  903. C.iggOpenPopup(idArg)
  904. }
  905. // Popups, Modals
  906. // - They block normal mouse hovering detection (and therefore most mouse
  907. // interactions) behind them.
  908. // - If not modal: they can be closed by clicking anywhere outside them, or by
  909. // pressing ESCAPE.
  910. // - Their visibility state (~bool) is held internally instead of being held by
  911. // the programmer as we are used to with regular Begin*() calls.
  912. // - The 3 properties above are related: we need to retain popup visibility
  913. // state in the library because popups may be closed as any time.
  914. // - You can bypass the hovering restriction by using
  915. // ImGuiHoveredFlags_AllowWhenBlockedByPopup when calling IsItemHovered() or
  916. // IsWindowHovered().
  917. // - IMPORTANT: Popup identifiers are relative to the current ID stack, so
  918. // OpenPopup and BeginPopup generally needs to be at the same level of the
  919. // stack.
  920. // This is sometimes leading to confusing mistakes. May rework this in the
  921. // future.
  922. // Popups: begin/end functions
  923. // - BeginPopup(): query popup state, if open start appending into the window.
  924. // Call EndPopup() afterwards. ImGuiWindowFlags are forwarded to the window.
  925. // - BeginPopupModal(): block every interactions behind the window, cannot be
  926. // closed by user, add a dimming background, has a title bar.
  927. func BeginPopup(name string, flags int) bool {
  928. nameArg, nameFin := wrapString(name)
  929. defer nameFin()
  930. return C.iggBeginPopup(nameArg, C.int(flags)) != 0
  931. }
  932. // BeginPopupModalV creates modal dialog (regular window with title bar, block interactions behind the modal window,
  933. // can't close the modal window by clicking outside).
  934. func BeginPopupModalV(name string, open *bool, flags int) bool {
  935. nameArg, nameFin := wrapString(name)
  936. defer nameFin()
  937. openArg, openFin := wrapBool(open)
  938. defer openFin()
  939. return C.iggBeginPopupModal(nameArg, openArg, C.int(flags)) != 0
  940. }
  941. // BeginPopupModal calls BeginPopupModalV(name, nil, 0)
  942. func BeginPopupModal(name string) bool {
  943. return BeginPopupModalV(name, nil, 0)
  944. }
  945. // BeginPopupContextItemV returns true if the identified mouse button was pressed
  946. // while hovering over the last item.
  947. func BeginPopupContextItemV(label string, mouseButton int) bool {
  948. labelArg, labelFin := wrapString(label)
  949. defer labelFin()
  950. return C.iggBeginPopupContextItem(labelArg, C.int(mouseButton)) != 0
  951. }
  952. // BeginPopupContextItem calls BeginPopupContextItemV("", 1)
  953. func BeginPopupContextItem() bool {
  954. return BeginPopupContextItemV("", 1)
  955. }
  956. // EndPopup finshes a popup. Only call EndPopup() if BeginPopupXXX() returns true!
  957. func EndPopup() {
  958. C.iggEndPopup()
  959. }
  960. // CloseCurrentPopup closes the popup we have begin-ed into.
  961. // Clicking on a MenuItem or Selectable automatically close the current popup.
  962. func CloseCurrentPopup() {
  963. C.iggCloseCurrentPopup()
  964. }
  965. // IsItemHoveredV returns true if the last item is hovered.
  966. // (and usable, aka not blocked by a popup, etc.). See HoveredFlags for more options.
  967. func IsItemHoveredV(flags int) bool {
  968. return C.iggIsItemHovered(C.int(flags)) != 0
  969. }
  970. // IsItemHovered calls IsItemHoveredV(HoveredFlagsNone)
  971. func IsItemHovered() bool {
  972. return IsItemHoveredV(HoveredFlagsNone)
  973. }
  974. // Is the last item clicked? (e.g. button/node just clicked on) == IsMouseClicked(mouse_button) && IsItemHovered()
  975. func IsItemClicked(mouseButton int) bool {
  976. return C.iggIsItemClicked(C.int(mouseButton)) != 0
  977. }
  978. func IsItemActive() bool {
  979. return C.iggIsItemActive() != 0
  980. }
  981. // IsAnyItemActive returns true if the any item is active.
  982. func IsAnyItemActive() bool {
  983. return C.iggIsAnyItemActive() != 0
  984. }
  985. // IsKeyDown returns true if the corresponding key is currently being held down.
  986. func IsKeyDown(key int) bool {
  987. return C.iggIsKeyDown(C.int(key)) != 0
  988. }
  989. // IsKeyPressedV returns true if the corresponding key was pressed (went from !Down to Down).
  990. // If repeat=true and the key is being held down then the press is repeated using io.KeyRepeatDelay and KeyRepeatRate
  991. func IsKeyPressedV(key int, repeat bool) bool {
  992. return C.iggIsKeyPressed(C.int(key), castBool(repeat)) != 0
  993. }
  994. // IsKeyPressed calls IsKeyPressedV(key, true).
  995. func IsKeyPressed(key int) bool {
  996. return IsKeyPressedV(key, true)
  997. }
  998. // IsKeyReleased returns true if the corresponding key was released (went from Down to !Down).
  999. func IsKeyReleased(key int) bool {
  1000. return C.iggIsKeyReleased(C.int(key)) != 0
  1001. }
  1002. // IsMouseDown returns true if the corresponding mouse button is currently being held down.
  1003. func IsMouseDown(button int) bool {
  1004. return C.iggIsMouseDown(C.int(button)) != 0
  1005. }
  1006. // IsAnyMouseDown returns true if any mouse button is currently being held down.
  1007. func IsAnyMouseDown() bool {
  1008. return C.iggIsAnyMouseDown() != 0
  1009. }
  1010. // IsMouseClickedV returns true if the mouse button was clicked (0=left, 1=right, 2=middle)
  1011. // If repeat=true and the mouse button is being held down then the click is repeated using io.KeyRepeatDelay and KeyRepeatRate
  1012. func IsMouseClickedV(button int, repeat bool) bool {
  1013. return C.iggIsMouseClicked(C.int(button), castBool(repeat)) != 0
  1014. }
  1015. // IsMouseClicked calls IsMouseClickedV(key, false).
  1016. func IsMouseClicked(button int) bool {
  1017. return IsMouseClickedV(button, false)
  1018. }
  1019. // IsMouseReleased returns true if the mouse button was released (went from Down to !Down).
  1020. func IsMouseReleased(button int) bool {
  1021. return C.iggIsMouseReleased(C.int(button)) != 0
  1022. }
  1023. // IsMouseDoubleClicked returns true if the mouse button was double-clicked (0=left, 1=right, 2=middle).
  1024. func IsMouseDoubleClicked(button int) bool {
  1025. return C.iggIsMouseDoubleClicked(C.int(button)) != 0
  1026. }
  1027. // Columns calls ColumnsV(1, "", false).
  1028. func Columns() {
  1029. ColumnsV(1, "", false)
  1030. }
  1031. // ColumnsV creates a column layout of the specified number of columns.
  1032. // The brittle columns API will be superseded by an upcoming 'table' API.
  1033. func ColumnsV(count int, label string, border bool) {
  1034. labelArg, labelFin := wrapString(label)
  1035. defer labelFin()
  1036. C.iggColumns(C.int(count), labelArg, castBool(border))
  1037. }
  1038. // NextColumn next column, defaults to current row or next row if the current row is finished.
  1039. func NextColumn() {
  1040. C.iggNextColumn()
  1041. }
  1042. // ColumnIndex get current column index.
  1043. func ColumnIndex() int {
  1044. return int(C.iggGetColumnIndex())
  1045. }
  1046. // ColumnWidth calls ColumnWidthV(-1).
  1047. func ColumnWidth() int {
  1048. return ColumnWidthV(-1)
  1049. }
  1050. // ColumnWidthV get column width (in pixels). pass -1 to use current column.
  1051. func ColumnWidthV(index int) int {
  1052. return int(C.iggGetColumnWidth(C.int(index)))
  1053. }
  1054. // SetColumnWidth sets column width (in pixels). pass -1 to use current column.
  1055. func SetColumnWidth(index int, width float32) {
  1056. C.iggSetColumnWidth(C.int(index), C.float(width))
  1057. }
  1058. // ColumnOffset calls ColumnOffsetV(-1)
  1059. func ColumnOffset() float32 {
  1060. return ColumnOffsetV(-1)
  1061. }
  1062. // ColumnOffsetV get position of column line (in pixels, from the left side of the contents region). pass -1 to use
  1063. // current column, otherwise 0..GetColumnsCount() inclusive. column 0 is typically 0.0.
  1064. func ColumnOffsetV(index int) float32 {
  1065. return float32(C.iggGetColumnOffset(C.int(index)))
  1066. }
  1067. // SetColumnOffset set position of column line (in pixels, from the left side of the contents region). pass -1 to use
  1068. // current column.
  1069. func SetColumnOffset(index int, offsetX float32) {
  1070. C.iggSetColumnOffset(C.int(index), C.float(offsetX))
  1071. }
  1072. // ColumnsCount returns number of current columns.
  1073. func ColumnsCount() int {
  1074. return int(C.iggGetColumnsCount())
  1075. }
  1076. // BeginTabBarV create and append into a TabBar
  1077. func BeginTabBarV(strID string, flags int) bool {
  1078. idArg, idFin := wrapString(strID)
  1079. defer idFin()
  1080. return C.iggBeginTabBar(idArg, C.int(flags)) != 0
  1081. }
  1082. // BeginTabBar calls BeginTabBarV(strId, 0)
  1083. func BeginTabBar(strID string) bool {
  1084. return BeginTabBarV(strID, 0)
  1085. }
  1086. // EndTabBar only call EndTabBar() if BeginTabBar() returns true!
  1087. func EndTabBar() {
  1088. C.iggEndTabBar()
  1089. }
  1090. // BeginTabItemV create a Tab. Returns true if the Tab is selected.
  1091. func BeginTabItemV(label string, open *bool, flags int) bool {
  1092. labelArg, labelFin := wrapString(label)
  1093. defer labelFin()
  1094. openArg, openFin := wrapBool(open)
  1095. defer openFin()
  1096. return C.iggBeginTabItem(labelArg, openArg, C.int(flags)) != 0
  1097. }
  1098. // BeginTabItem calls BeginTabItemV(label, nil, 0)
  1099. func BeginTabItem(label string) bool {
  1100. return BeginTabItemV(label, nil, 0)
  1101. }
  1102. // EndTabItem Don't call PushID(tab->ID)/PopID() on BeginTabItem()/EndTabItem()
  1103. func EndTabItem() {
  1104. C.iggEndTabItem()
  1105. }
  1106. // SetTabItemClosed notify TabBar or Docking system of a closed tab/window ahead
  1107. // (useful to reduce visual flicker on reorderable tab bars). For tab-bar: call
  1108. // after BeginTabBar() and before Tab submissions. Otherwise call with a window name.
  1109. func SetTabItemClosed(tabOrDockedWindowLabel string) {
  1110. labelArg, labelFin := wrapString(tabOrDockedWindowLabel)
  1111. defer labelFin()
  1112. C.iggSetTabItemClosed(labelArg)
  1113. }
  1114. // ScrollX returns the horizontal scrolling amount [0..GetScrollMaxX()].
  1115. func ScrollX() float32 {
  1116. return float32(C.iggGetScrollX())
  1117. }
  1118. // ScrollY returns the vertical scrolling amount [0..GetScrollMaxY()].
  1119. func ScrollY() float32 {
  1120. return float32(C.iggGetScrollY())
  1121. }
  1122. // ScrollMaxX returns the maximum horizontal scrolling amount: ContentSize.X - WindowSize.X .
  1123. func ScrollMaxX() float32 {
  1124. return float32(C.iggGetScrollMaxX())
  1125. }
  1126. // ScrollMaxY returns the maximum vertical scrolling amount: ContentSize.Y - WindowSize.Y .
  1127. func ScrollMaxY() float32 {
  1128. return float32(C.iggGetScrollMaxY())
  1129. }
  1130. // SetScrollHereX adjusts horizontal scrolling amount to make current cursor
  1131. // position visible. ratio=0.0: left, 0.5: center, 1.0: right. When using to
  1132. // make a "default/current item" visible, consider using SetItemDefaultFocus()
  1133. // instead.
  1134. func SetScrollHereX(ratio float32) {
  1135. C.iggSetScrollHereX(C.float(ratio))
  1136. }
  1137. // SetScrollHereY adjusts scrolling amount to make current cursor position visible.
  1138. // ratio=0.0: top, 0.5: center, 1.0: bottom.
  1139. // When using to make a "default/current item" visible, consider using SetItemDefaultFocus() instead.
  1140. func SetScrollHereY(ratio float32) {
  1141. C.iggSetScrollHereY(C.float(ratio))
  1142. }
  1143. // SetScrollX sets horizontal scrolling amount [0..GetScrollMaxX()].
  1144. func SetScrollX(scrollX float32) {
  1145. C.iggSetScrollX(C.float(scrollX))
  1146. }
  1147. // SetScrollY sets vertical scrolling amount [0..GetScrollMaxY()].
  1148. func SetScrollY(scrollY float32) {
  1149. C.iggSetScrollY(C.float(scrollY))
  1150. }
  1151. // SetItemDefaultFocus makes the last item the default focused item of a window.
  1152. func SetItemDefaultFocus() {
  1153. C.iggSetItemDefaultFocus()
  1154. }
  1155. // IsItemFocused returns true if the last item is focused.
  1156. func IsItemFocused() bool {
  1157. return C.iggIsItemFocused() != 0
  1158. }
  1159. // IsAnyItemFocused returns true if any item is focused.
  1160. func IsAnyItemFocused() bool {
  1161. return C.iggIsAnyItemFocused() != 0
  1162. }
  1163. // MouseCursor returns desired cursor type, reset in imgui.NewFrame(), this is updated during the frame.
  1164. // Valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you.
  1165. func MouseCursor() int {
  1166. return int(C.iggGetMouseCursor())
  1167. }
  1168. // SetMouseCursor sets desired cursor type.
  1169. func SetMouseCursor(cursor int) {
  1170. C.iggSetMouseCursor(C.int(cursor))
  1171. }
  1172. // SetKeyboardFocusHere calls SetKeyboardFocusHereV(0)
  1173. func SetKeyboardFocusHere() {
  1174. C.iggSetKeyboardFocusHere(0)
  1175. }
  1176. // SetKeyboardFocusHereV gives keyboard focus to next item
  1177. func SetKeyboardFocusHereV(offset int) {
  1178. C.iggSetKeyboardFocusHere(C.int(offset))
  1179. }
  1180. func GetWindowDrawList() DrawList {
  1181. return DrawList(C.iggGetWindowDrawList())
  1182. }
  1183. func GetItemRectMin() Vec2 {
  1184. var value Vec2
  1185. valueArg, valueFin := value.wrapped()
  1186. C.iggGetItemRectMin(valueArg)
  1187. valueFin()
  1188. return value
  1189. }
  1190. func GetItemRectMax() Vec2 {
  1191. var value Vec2
  1192. valueArg, valueFin := value.wrapped()
  1193. C.iggGetItemRectMax(valueArg)
  1194. valueFin()
  1195. return value
  1196. }
  1197. func GetItemRectSize() Vec2 {
  1198. var value Vec2
  1199. valueArg, valueFin := value.wrapped()
  1200. C.iggGetItemRectSize(valueArg)
  1201. valueFin()
  1202. return value
  1203. }
  1204. func PushClipRect(clipRectMin, clipRectMax Vec2, intersectWithClipRect bool) {
  1205. clipMin, _ := clipRectMin.wrapped()
  1206. clipMax, _ := clipRectMax.wrapped()
  1207. C.iggPushClipRect(clipMin, clipMax, castBool(intersectWithClipRect))
  1208. }
  1209. func PopClipRect() {
  1210. C.iggPopClipRect()
  1211. }
  1212. func PushAllowKeyboardFocus(allowKeyboardFocus bool) {
  1213. C.iggPushAllowKeyboardFocus(castBool(allowKeyboardFocus))
  1214. }
  1215. func PopAllowKeyboardFocus() {
  1216. C.iggPopAllowKeyboardFocus()
  1217. }