Skip to content

Commit

Permalink
examples: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dinau committed Dec 30, 2024
1 parent 2124f42 commit 700b7e0
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 61 deletions.
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Install](#install)
- [Build examples](#build-examples)
- [Available libraries](#available-libraries)
- [Frontends and Backends](#frontends-and-backends)
- [Screen shot (examples)](#screen-shot-examples)
- [glfw_opengl3](#glfw_opengl3)
- [glfw_opengl3_imknobs](#glfw_opengl3_imknobs)
Expand All @@ -31,13 +32,13 @@
- [Similar project ImGui / CImGui](#similar-project-imgui--cimgui)
- [SDL Game tutorial Platfromer](#sdl-game-tutorial-platfromer)
- [Other link2](#other-link2)
- [Memo](#memo)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# ImGuin

![alt](https://github.com/dinau/imguin/actions/workflows/run.yml/badge.svg)
![alt](https://github.com/dinau/imguin/actions/workflows/linux.yml/badge.svg)
![alt](https://github.com/dinau/imguin/actions/workflows/run.yml/badge.svg) ![alt](https://github.com/dinau/imguin/actions/workflows/linux.yml/badge.svg)

Updated to latest ImGui/CImGui version: : **v1.91.6dock** (2024/12)

Expand All @@ -60,17 +61,15 @@ It may be better to use the **mainstream** project [nimgl/imgui](https://github.
- [Nim-2.0.14](https://nim-lang.org) or later
- Windows10 or later
[MSys2/MinGW](https://www.msys2.org/) command line tools (Unix tools), make, cp, rm, git, ...etc
- Linux Mint 22 (or Ubuntu / Debian families ?)
- Linux Mint 22 (or Ubuntu / Debian families )

```sh
$ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev
$ sudo apt install gcc g++ make git
```

and for glfw3 and sdl2,

```sh
$ sudo apt install libglfw3 libglfw3-dev
$ sudo apt install libsdl2-dev
$ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev
$ sudo apt install libglfw3 libglfw3-dev libsdl2-dev
```

### Install
Expand All @@ -93,14 +92,14 @@ nimble install https://github.com/dinau/imguin
```

1. Sample program is here, [examples](examples).
For instance [glfw_opengl3.nim](examples/glfw_opengl3/glfw_opengl3.nim),
For instance [glfw_opengl3_base.nim](examples/glfw_opengl3_base/glfw_opengl3_base.nim),

```sh
cd imguin/examples/glfw_opengl3
cd imguin/examples/glfw_opengl3_base
make # or make run
```

After build, run `./glfw_opengl3(.exe)`
After build, run `./glfw_opengl3_base(.exe)`
Compiation options depend on `./config.nims` and `./Makefile`.


Expand All @@ -110,16 +109,27 @@ For instance [glfw_opengl3.nim](examples/glfw_opengl3/glfw_opengl3.nim),

---

| | Library name | |
|-----|---------------------------------------------------------------------------------------------------------------------|--------------|
| v | ImGui / CImGui | Base library |
| v | ImPlot / CImPlot |
| v | ImNodes/ CImNodes |
| v | ImGuizmo/ CImGuizmo |
| v | ImGui-Knobs/ CImGui-Knobs |
| v | ImGuiFileDialog / [CImGuiFileDialog](https://github.com/dinau/CImGuiFileDialog) | Windows |
| ... | ... | ... |
| x | [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit) / [cimCTE](https://github.com/cimgui/cimCTE) | 2025 ? |
| | Library name | |
|-----|-------------------------------------------------------------------------------------------------------------------------------|--------------|
| v | [ImGui](https://github.com/ocornut/imgui) / [CImGui](https://github.com/cimgui/cimgui) | Base library |
| v | [ImPlot](https://github.com/epezent/implot) / [CImPlot](https://github.com/cimgui/cimplot) | |
| v | [ImNodes](https://github.com/Nelarius/imnodes) / [CImNodes](https://github.com/cimgui/cimnodes) | |
| v | [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo) / [CImGuizmo](https://github.com/cimgui/cimguizmo) | |
| v | [ImGui-Knobs]([https://github.com/altschuler/imgui-knobs)/ [CImGui-Knobs](src/imguin/private/cimgui-knobs) | |
| v | [ImGuiFileDialog](https://github.com/aiekick/ImGuiFileDialog) / [CImGuiFileDialog](https://github.com/dinau/CImGuiFileDialog) | |
| ... | ... | ... |
| x | [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit) / [cimCTE](https://github.com/cimgui/cimCTE) | 2025 ? |

#### Frontends and Backends

---

| | GLFW | SDL2 | SDL3 | |
| --- | :----: | :---- | :----: | --- |
| OpenGL3<br>backend | v | v | v | |
| SDL2<br>backend | - | ? | - | 2025? |
| SDL3<br>backend | - | - | ? | 2025? |


### Screen shot (examples)

Expand Down
4 changes: 2 additions & 2 deletions examples/glfw_opengl3_base/glfw_opengl3_base.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Window]
startupPosX=383
startupPosY=67
startupPosX=399
startupPosY=63
viewportWidth=1024
viewportHeigth=800
colBGx=0.4246913492679596
Expand Down
3 changes: 1 addition & 2 deletions examples/glfw_opengl3_base/glfw_opengl3_base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ proc main() =
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)

igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
var s = "Input result:" & sBuf
igText(s.cstring)
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)
Expand Down
2 changes: 1 addition & 1 deletion examples/glfw_opengl3_base/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Size=417,456
Collapsed=0

[Window][imgui Another Window]
Pos=47,338
Pos=24,478
Size=321,80
Collapsed=0

Expand Down
3 changes: 1 addition & 2 deletions examples/glfw_opengl3_image_load/glfw_opengl3_image_load.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ proc main() =
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)

igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
var s = "Input result:" & sBuf
igText(s.cstring)
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)
Expand Down
14 changes: 8 additions & 6 deletions examples/glfw_opengl3_image_save/glfw_opengl3_image_save.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[Window]
startupPosX=431
startupPosY=91
viewportWidth=1001
startupPosX=363
startupPosY=71
viewportWidth=1024
viewportHeigth=900
colBGx=0.06189299374818802
colBGy=0.355555534362793
colBGz=0.2250388562679291
colBGx=0.25
colBGy=0.6499999761581421
colBGz=0.8500000238418579
colBGw=1.0
[Image]
imageSaveFormatIndex=0
15 changes: 6 additions & 9 deletions examples/glfw_opengl3_image_save/glfw_opengl3_image_save.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const SaveImageName = "ImageSaved"
var
imageExt:string
imageFormatTbl = [(kind:"JPEG 90%",ext:".jpg"), ("PNG",".png"), ("BMP",".bmp"), ("TGA",".tga")]
cbItemIndex = 0

#------
# main
Expand Down Expand Up @@ -72,8 +71,7 @@ proc main() =
igText("%s%s", ICON_FA_COMMENT_MEDICAL & " Nim-", NimVersion)

igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
var s = "Input result:" & sBuf
igText(s.cstring)
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)
Expand All @@ -87,11 +85,11 @@ proc main() =
igPushStyleColorVec4(ImGuiCol_Text.ImGuiCol, ImVec4(x: 0.0, y: 0.0, z:0.0, w: 1.0))

# Image save button
imageExt = imageFormatTbl[cbItemIndex].ext
imageExt = imageFormatTbl[win.ini.imageSaveFormatIndex].ext
svName = fmt"{SaveImageName}_{counter:05}{imageExt}"
if igButton("Save Image", ImVec2(x: 0.0f, y: 0.0f)):
let wkSize = igGetMainViewport().Worksize
saveImage(svName,0, 0, wkSize.x.int, wkSize.y.int, 3) # --- Save Image !
saveImage(svName,0, 0, wkSize.x.int, wkSize.y.int) # --- Save Image !
igPopStyleColor(4)
igPopID()

Expand All @@ -103,14 +101,13 @@ proc main() =

#-- ComboBox: Select save image format
igSetNextItemWidth(100)
if igBeginCombo("##".cstring, imageFormatTbl[cbItemIndex].kind.cstring, 0):
if igBeginCombo("##".cstring, imageFormatTbl[win.ini.imageSaveFormatIndex].kind.cstring, 0):
for n,val in imageFormatTbl:
var is_selected = (cbItemIndex == n)
var is_selected = (win.ini.imageSaveFormatIndex == n)
if igSelectableBoolPtr(val.kind.cstring, is_selected.addr, 0, ImVec2(x: 0.0,y: 0.0)):
if is_selected:
igSetItemDefaultFocus()
cbItemIndex = n
#app.image.imageSaveFormatIndex = cbItemIndex
win.ini.imageSaveFormatIndex = n
igEndCombo()
setTooltip("Select image format")

Expand Down
10 changes: 4 additions & 6 deletions examples/glfw_opengl3_jp/glfw_opengl3_jp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ proc firstWindow(win:Window) =
igBegin("Window".cstring, showFirstWindow.addr, 0)
defer: igEnd()

var s = "GLFW v" & $glfwGetVersionString()
igText(s.cstring)
s = "OpenGL v" & ($cast[cstring](glGetString(GL_VERSION))).split[0]
igText(s.cstring)
igText((ICON_FA_COMMENT & " " & getFrontendVersionString()).cstring)
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)

igText("これは日本語表示テスト")
igInputTextWithHint("テキスト入力", "ここに日本語を入力", sBuf)
s = "入力結果:" & sBuf
igText(s.cstring)
igText(("入力結果:" & sBuf).cstring)
igCheckbox("デモ・ウインドウ表示", showDemoWindow.addr)
igSliderFloat("浮動小数", somefloat.addr, 0.0f, 1.0f, "%3f", 0)
igColorEdit3("背景色変更", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags)
Expand Down
3 changes: 2 additions & 1 deletion examples/makefile.common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ TARGET = $(notdir $(CURDIR))

ifeq ($(OS),Windows_NT)
EXE = .exe
else
OPT += --passL:-lstdc++
endif
TARGET_EXE = $(TARGET)$(EXE)

Expand All @@ -13,7 +15,6 @@ OPT += -d:strip
OPT += -o:$(TARGET_EXE)
#OPT += --listCmd
#OPT += --verbosity:2
OPT += --passL:-lstdc++

all: build dll

Expand Down
3 changes: 1 addition & 2 deletions examples/sdl2_opengl3/sdl2_opengl3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ proc main() =
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)

igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
var s = "Input result:" & sBuf
igText(s.cstring)
igText(("Input result:" & sBuf).cstring)
igCheckbox("Demo window", addr showDemoWindow)
igSliderFloat("Float", addr fval, 0.0f, 1.5f, "%.3f", 0)
igColorEdit3("Bcakground color", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags)
Expand Down
10 changes: 4 additions & 6 deletions examples/sdl3_opengl3/sdl3_opengl3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ proc main() =
igText((ICON_FA_COMMENT_SMS & " " & getBackendVersionString()).cstring)

igInputTextWithHint("InputText" ,"Input text here" ,sBuf)
var s = "Input result:" & sBuf
igText(s.cstring)
igText(("Input result:" & sBuf).cstring)
igCheckbox("Demo window", addr showDemoWindow)
igSliderFloat("Float", addr fval, 0.0f, 1.5f, "%.3f", 0)
igColorEdit3("Background color", win.ini.clearColor.array3, ImGuiColorEditFlags_None.ImGuiColorEditFlags)
Expand Down Expand Up @@ -110,10 +109,9 @@ proc main() =
igGetCursorScreenPos(addr imageBoxPosTop) # Get absolute pos.
igImage(cast[ImTextureID](textureId), size, uv0, uv1, tint_col, border_col);
igGetCursorScreenPos(addr imageBoxPosEnd) # Get absolute pos.
when false: # TODO WIP
# Magnifiying glass
if igIsItemHovered(ImGui_HoveredFlags_DelayNone.ImGuiHoveredFlags):
zoomGlass(zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd)
# Magnifiying glass
if igIsItemHovered(ImGui_HoveredFlags_DelayNone.ImGuiHoveredFlags):
zoomGlass(zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd)

#--------
# render
Expand Down
26 changes: 24 additions & 2 deletions examples/utils/appImGui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type IniData = object
clearColor*: ccolor
startupPosX*, startupPosY*:cint
viewportWidth*, viewportHeight*:cint
imageSaveFormatIndex*:int

type Window* = object
handle*: glfw.GLFWwindow
Expand Down Expand Up @@ -214,7 +215,7 @@ proc setClearColor*(win: var Window, col: ccolor) =
#------
proc free*(mem: pointer) {.importc,header:"<stdlib.h>".}

# Sections (Cat.)
# Sections
const scWindow = "Window"
# [Window]
const startupPosX = "startupPosX"
Expand All @@ -225,6 +226,9 @@ const colBGx = "colBGx"
const colBGy = "colBGy"
const colBGz = "colBGz"
const colBGw = "colBGw"
# [Image]
const scImage = "Image"
const imageSaveFormatIndex = "imageSaveFormatIndex"

#---------
# loadIni --- Load ini
Expand All @@ -236,15 +240,19 @@ proc loadIni*(this: var Window) =
#----------
if fileExists(iniName):
let cfg = loadConfig(iniName)
# Windows
# Window pos
this.ini.startupPosX = cfg.getSectionValue(scWindow,startupPosX).parseInt.cint
if 10 > this.ini.startupPosX: this.ini.startupPosX = 10
this.ini.startupPosY = cfg.getSectionValue(scWindow,startupPosY).parseInt.cint
if 10 > this.ini.startupPosY: this.ini.startupPosY = 10

# Window size
this.ini.viewportWidth = cfg.getSectionValue(scWindow,viewportWidth).parseInt.cint
if this.ini.viewportWidth < 100: this.ini.viewportWidth = 900
this.ini.viewportHeight = cfg.getSectionValue(scWindow,viewportHeight).parseInt.cint
if this.ini.viewportHeight < 100: this.ini.viewportHeight = 900

# Background color
var fval:float
discard parsefloat(cfg.getSectionValue(scWindow, colBGx, "0.25"), fval)
this.ini.clearColor.elm.x = fval.cfloat
Expand All @@ -254,29 +262,43 @@ proc loadIni*(this: var Window) =
this.ini.clearColor.elm.z = fval.cfloat
discard parsefloat(cfg.getSectionValue(scWindow, colBGw, "1.00"), fval)
this.ini.clearColor.elm.w = fval.cfloat

# Image format index
this.ini.imageSaveFormatIndex = cfg.getSectionValue(scImage,imageSaveFormatIndex).parseInt.cint

#----------------
# Set first defaults
#----------------
else:
this.ini.startupPosX = 100
this.ini.startupPosY = 200
this.ini.clearColor = ccolor(elm:(x:0.25f, y:0.65f, z:0.85f, w:1.0f))
this.ini.imageSaveFormatIndex = 0

#---------
# saveIni --- save iniFile
#---------
proc saveIni*(this: var Window) =
let iniName = getAppFilename().changeFileExt("ini")
var ini = newConfig()
# Window pos
getWindowPos(this.handle, addr this.ini.startupPosX,addr this.ini.startupPosY)
ini.setSectionKey(scWindow,startupPosX,$this.ini.startupPosX)
ini.setSectionKey(scWindow,startupPosY,$this.ini.startupPosY)

# Window size
let ws = igGetMainViewPort().WorkSize
ini.setSectionKey(scWindow, viewportWidth,$ws.x.cint)
ini.setSectionKey(scWindow, viewportHeight,$ws.y.cint)

# Background color
ini.setSectionKey(scWindow, colBGx, $this.ini.clearColor.elm.x)
ini.setSectionKey(scWindow, colBGy, $this.ini.clearColor.elm.y)
ini.setSectionKey(scWindow, colBGz, $this.ini.clearColor.elm.z)
ini.setSectionKey(scWindow, colBGw, $this.ini.clearColor.elm.w)

# Image format index
ini.setSectionKey(scImage, imageSaveFormatIndex, $this.ini.imageSaveFormatIndex)

# save ini file
writeFile(iniName,$ini)
2 changes: 1 addition & 1 deletion examples/utils/setupFonts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import imguin/lang/imgui_ja_gryph_ranges
import ../utils/fonticon/IconsFontAwesome6
export IconsFontAwesome6

let IconfontFullPath = "../utils/fonticon/fa6/fa-solid-900.ttf"
let IconfontFullPath = os.joinPath(os.getAppDir(),"../utils/fonticon/fa6/fa-solid-900.ttf")

#--------------
# point2px
Expand Down

0 comments on commit 700b7e0

Please sign in to comment.