diff --git a/backend.go b/backend/backend.go similarity index 93% rename from backend.go rename to backend/backend.go index d55b27a34..b0ec5e0ad 100644 --- a/backend.go +++ b/backend/backend.go @@ -1,4 +1,4 @@ -package imgui +package backend // extern void loopCallback(); // extern void beforeRender(); @@ -8,9 +8,9 @@ package imgui // extern void dropCallback(void*, int, char**); // extern void keyCallback(void*, int, int, int, int); // extern void sizeCallback(void*, int, int); -// #include "extra_types.h" -// #include "cimgui_wrapper.h" -// #include "cimgui_typedefs.h" +// #include "../extra_types.h" +// #include "../cimgui_wrapper.h" +// #include "../cimgui_typedefs.h" import "C" import ( @@ -18,6 +18,8 @@ import ( "fmt" "image" "unsafe" + + imgui "github.com/AllenDang/cimgui-go" ) type voidCallbackFunc func() @@ -143,7 +145,7 @@ type Backend[BackendFlagsT ~int] interface { SetBeforeRenderHook(func()) SetAfterRenderHook(func()) - SetBgColor(color Vec4) + SetBgColor(color imgui.Vec4) Run(func()) Refresh() @@ -180,9 +182,9 @@ type Backend[BackendFlagsT ~int] interface { // Why I separate it? Current impl of local texture.go needs to store this somewhere, and I don't want // to make Texture relate on BackendFlagsT. type TextureManager interface { - CreateTexture(pixels unsafe.Pointer, width, Height int) TextureID - CreateTextureRgba(img *image.RGBA, width, height int) TextureID - DeleteTexture(id TextureID) + CreateTexture(pixels unsafe.Pointer, width, Height int) imgui.TextureID + CreateTextureRgba(img *image.RGBA, width, height int) imgui.TextureID + DeleteTexture(id imgui.TextureID) } type backendCExpose interface { @@ -228,9 +230,3 @@ func CreateBackend[BackendFlagsT ~int](backend Backend[BackendFlagsT]) (sameBack textureManager = backend return backend, err } - -// Export some methods that are necessary for externally packaged backends - -func (i Vec4) ToC() C.ImVec4 { - return i.toC() -} diff --git a/sdlbackend/cflags.go b/backend/cflags.go similarity index 95% rename from sdlbackend/cflags.go rename to backend/cflags.go index 10e4f7867..a5393ecff 100644 --- a/sdlbackend/cflags.go +++ b/backend/cflags.go @@ -1,4 +1,4 @@ -package sdlbackend +package backend // #cgo CPPFLAGS: -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS // #cgo CXXFLAGS: --std=c++11 diff --git a/ebiten-backend/LICENSE b/backend/ebiten-backend/LICENSE similarity index 100% rename from ebiten-backend/LICENSE rename to backend/ebiten-backend/LICENSE diff --git a/ebiten-backend/README.md b/backend/ebiten-backend/README.md similarity index 100% rename from ebiten-backend/README.md rename to backend/ebiten-backend/README.md diff --git a/ebiten-backend/backend_flags.go b/backend/ebiten-backend/backend_flags.go similarity index 100% rename from ebiten-backend/backend_flags.go rename to backend/ebiten-backend/backend_flags.go diff --git a/ebiten-backend/cimgui_backend_impl.go b/backend/ebiten-backend/cimgui_backend_impl.go similarity index 93% rename from ebiten-backend/cimgui_backend_impl.go rename to backend/ebiten-backend/cimgui_backend_impl.go index b297f4f56..ac0568a9a 100644 --- a/ebiten-backend/cimgui_backend_impl.go +++ b/backend/ebiten-backend/cimgui_backend_impl.go @@ -5,6 +5,7 @@ import ( "unsafe" imgui "github.com/AllenDang/cimgui-go" + "github.com/AllenDang/cimgui-go/backend" "github.com/hajimehoshi/ebiten/v2" ) @@ -88,16 +89,16 @@ func (e *EbitenBackend) SetTargetFPS(fps uint) { } // TODO: Not implemented -func (b *EbitenBackend) SetDropCallback(imgui.DropCallback) { +func (b *EbitenBackend) SetDropCallback(backend.DropCallback) { panic("SetDropCallback is not implemented for Ebiten backend yet.") } -func (b *EbitenBackend) SetCloseCallback(cb imgui.WindowCloseCallback[EbitenBackendFlags]) { +func (b *EbitenBackend) SetCloseCallback(cb backend.WindowCloseCallback[EbitenBackendFlags]) { b.closeCb = cb } -func (b *EbitenBackend) SetKeyCallback(imgui.KeyCallback) {} // TODO -func (b *EbitenBackend) SetSizeChangeCallback(imgui.SizeChangeCallback) {} // TODO +func (b *EbitenBackend) SetKeyCallback(backend.KeyCallback) {} // TODO +func (b *EbitenBackend) SetSizeChangeCallback(backend.SizeChangeCallback) {} // TODO func (b *EbitenBackend) SetWindowFlags(flag EbitenBackendFlags, value int) { switch flag { diff --git a/ebiten-backend/clipboard.go b/backend/ebiten-backend/clipboard.go similarity index 100% rename from ebiten-backend/clipboard.go rename to backend/ebiten-backend/clipboard.go diff --git a/ebiten-backend/doc.go b/backend/ebiten-backend/doc.go similarity index 100% rename from ebiten-backend/doc.go rename to backend/ebiten-backend/doc.go diff --git a/ebiten-backend/ebiten_api.go b/backend/ebiten-backend/ebiten_api.go similarity index 100% rename from ebiten-backend/ebiten_api.go rename to backend/ebiten-backend/ebiten_api.go diff --git a/ebiten-backend/ebiten_backend.go b/backend/ebiten-backend/ebiten_backend.go similarity index 93% rename from ebiten-backend/ebiten_backend.go rename to backend/ebiten-backend/ebiten_backend.go index 731bd1c30..3772f8e93 100644 --- a/ebiten-backend/ebiten_backend.go +++ b/backend/ebiten-backend/ebiten_backend.go @@ -4,14 +4,15 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" + "github.com/AllenDang/cimgui-go/backend" "github.com/hajimehoshi/ebiten/v2" ) type getCursorFn func() (x, y float32) var ( - _ imgui.Backend[EbitenBackendFlags] = &EbitenBackend{} - _ ebiten.Game = &EbitenBackend{} + _ backend.Backend[EbitenBackendFlags] = &EbitenBackend{} + _ ebiten.Game = &EbitenBackend{} ) // EbitenBackend implements imgui.Backend and ebiten.Game. @@ -26,7 +27,7 @@ type EbitenBackend struct { afterRender, beforeDestroy, loop func() - closeCb imgui.WindowCloseCallback[EbitenBackendFlags] + closeCb backend.WindowCloseCallback[EbitenBackendFlags] // ebiten stuff filter ebiten.Filter diff --git a/ebiten-backend/imcolor/convert.go b/backend/ebiten-backend/imcolor/convert.go similarity index 100% rename from ebiten-backend/imcolor/convert.go rename to backend/ebiten-backend/imcolor/convert.go diff --git a/ebiten-backend/internal/native/float.go b/backend/ebiten-backend/internal/native/float.go similarity index 100% rename from ebiten-backend/internal/native/float.go rename to backend/ebiten-backend/internal/native/float.go diff --git a/ebiten-backend/internal/native/float.h b/backend/ebiten-backend/internal/native/float.h similarity index 100% rename from ebiten-backend/internal/native/float.h rename to backend/ebiten-backend/internal/native/float.h diff --git a/ebiten-backend/keymap.go b/backend/ebiten-backend/keymap.go similarity index 100% rename from ebiten-backend/keymap.go rename to backend/ebiten-backend/keymap.go diff --git a/ebiten-backend/render.go b/backend/ebiten-backend/render.go similarity index 98% rename from ebiten-backend/render.go rename to backend/ebiten-backend/render.go index 1f3dd5cc3..d864ebd04 100644 --- a/ebiten-backend/render.go +++ b/backend/ebiten-backend/render.go @@ -6,7 +6,7 @@ import ( "unsafe" imgui "github.com/AllenDang/cimgui-go" - "github.com/AllenDang/cimgui-go/ebiten-backend/internal/native" + "github.com/AllenDang/cimgui-go/backend/ebiten-backend/internal/native" "github.com/hajimehoshi/ebiten/v2" ) diff --git a/ebiten-backend/txcache.go b/backend/ebiten-backend/txcache.go similarity index 100% rename from ebiten-backend/txcache.go rename to backend/ebiten-backend/txcache.go diff --git a/backend/glfwbackend/cflags.go b/backend/glfwbackend/cflags.go new file mode 100644 index 000000000..3adcb9e6f --- /dev/null +++ b/backend/glfwbackend/cflags.go @@ -0,0 +1,10 @@ +package glfwbackend + +// #cgo CPPFLAGS: -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS +// #cgo CXXFLAGS: --std=c++11 +// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../../lib/linux/x64/cimgui.a +// #cgo linux CXXFLAGS: -Wno-changes-meaning -Wno-invalid-conversion -fpermissive +// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../../lib/windows/x64 -l:cimgui.a +// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/x64/cimgui.a +// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/arm64/cimgui.a +import "C" diff --git a/glfwbackend/glfw_backend.cpp b/backend/glfwbackend/glfw_backend.cpp similarity index 98% rename from glfwbackend/glfw_backend.cpp rename to backend/glfwbackend/glfw_backend.cpp index eaea973d0..5ec28fe59 100644 --- a/glfwbackend/glfw_backend.cpp +++ b/backend/glfwbackend/glfw_backend.cpp @@ -4,9 +4,9 @@ #define CIMGUI_USE_OPENGL3 #include "glfw_backend.h" -#include "../cimgui/cimgui.h" -#include "../cimgui/cimgui_impl.h" -#include "../thirdparty/glfw/include/GLFW/glfw3.h" // Will drag system OpenGL headers +#include "../../cimgui/cimgui.h" +#include "../../cimgui/cimgui_impl.h" +#include "../../thirdparty/glfw/include/GLFW/glfw3.h" // Will drag system OpenGL headers #include diff --git a/glfwbackend/glfw_backend.go b/backend/glfwbackend/glfw_backend.go similarity index 91% rename from glfwbackend/glfw_backend.go rename to backend/glfwbackend/glfw_backend.go index 9ab828ad1..fd8033af8 100644 --- a/glfwbackend/glfw_backend.go +++ b/backend/glfwbackend/glfw_backend.go @@ -1,10 +1,10 @@ package glfwbackend -// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../lib/linux/x64/libglfw3.a -ldl -lGL -lX11 -// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../lib/windows/x64 -l:libglfw3.a -lgdi32 -lopengl32 -limm32 +// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../../lib/linux/x64/libglfw3.a -ldl -lGL -lX11 +// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../../lib/windows/x64 -l:libglfw3.a -lgdi32 -lopengl32 -limm32 // #cgo darwin LDFLAGS: -framework Cocoa -framework IOKit -framework CoreVideo -// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/x64/libglfw3.a -// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/arm64/libglfw3.a +// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/x64/libglfw3.a +// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/arm64/libglfw3.a // #cgo !gles2,darwin LDFLAGS: -framework OpenGL // #cgo gles2,darwin LDFLAGS: -lGLESv2 // #cgo CPPFLAGS: -DCIMGUI_GO_USE_GLFW @@ -19,6 +19,7 @@ import ( "unsafe" imgui "github.com/AllenDang/cimgui-go" + "github.com/AllenDang/cimgui-go/backend" ) type voidCallbackFunc func() @@ -192,7 +193,7 @@ const ( GLFWModNumLock = GLFWModifierKey(C.GLFWModNumLock) ) -var _ imgui.Backend[GLFWWindowFlags] = &GLFWBackend{} +var _ backend.Backend[GLFWWindowFlags] = &GLFWBackend{} type GLFWBackend struct { afterCreateContext voidCallbackFunc @@ -200,10 +201,10 @@ type GLFWBackend struct { beforeRender voidCallbackFunc afterRender voidCallbackFunc beforeDestoryContext voidCallbackFunc - dropCB imgui.DropCallback + dropCB backend.DropCallback closeCB func(pointer unsafe.Pointer) - keyCb imgui.KeyCallback - sizeCb imgui.SizeChangeCallback + keyCb backend.KeyCallback + sizeCb backend.SizeChangeCallback window uintptr } @@ -259,14 +260,14 @@ func (b *GLFWBackend) SetBgColor(color imgui.Vec4) { func (b *GLFWBackend) Run(loop func()) { b.loop = loop - C.igGLFWRunLoop(b.handle(), C.VoidCallback(imgui.LoopCallback()), C.VoidCallback(imgui.BeforeRender()), C.VoidCallback(imgui.AfterRender()), C.VoidCallback(imgui.BeforeDestroyContext())) + C.igGLFWRunLoop(b.handle(), C.VoidCallback(backend.LoopCallback()), C.VoidCallback(backend.BeforeRender()), C.VoidCallback(backend.AfterRender()), C.VoidCallback(backend.BeforeDestroyContext())) } func (b *GLFWBackend) LoopFunc() func() { return b.loop } -func (b *GLFWBackend) DropCallback() imgui.DropCallback { +func (b *GLFWBackend) DropCallback() backend.DropCallback { return b.dropCB } @@ -344,7 +345,7 @@ func (b *GLFWBackend) CreateWindow(title string, width, height int) { (*C.char)(titleArg), C.int(width), C.int(height), - C.VoidCallback(imgui.AfterCreateContext()), + C.VoidCallback(backend.AfterCreateContext()), ))) if b.window == 0 { panic("Failed to create GLFW window") @@ -375,12 +376,12 @@ func (b *GLFWBackend) DeleteTexture(id imgui.TextureID) { // SetDropCallback sets the drop callback which is called when an object // is dropped over the window. -func (b *GLFWBackend) SetDropCallback(cbfun imgui.DropCallback) { +func (b *GLFWBackend) SetDropCallback(cbfun backend.DropCallback) { b.dropCB = cbfun C.igGLFWWindow_SetDropCallbackCB(b.handle()) } -func (b *GLFWBackend) SetCloseCallback(cbfun imgui.WindowCloseCallback[GLFWWindowFlags]) { +func (b *GLFWBackend) SetCloseCallback(cbfun backend.WindowCloseCallback[GLFWWindowFlags]) { b.closeCB = func(_ unsafe.Pointer) { cbfun(b) } @@ -442,7 +443,7 @@ func (b *GLFWBackend) SetIcons(images ...image.Image) { } } -func (b *GLFWBackend) SetKeyCallback(cbfun imgui.KeyCallback) { +func (b *GLFWBackend) SetKeyCallback(cbfun backend.KeyCallback) { b.keyCb = func(k, s, a, m int) { C.iggImplGlfw_KeyCallback(b.handle(), C.int(k), C.int(s), C.int(a), C.int(m)) cbfun(k, s, a, m) @@ -450,16 +451,16 @@ func (b *GLFWBackend) SetKeyCallback(cbfun imgui.KeyCallback) { C.igGLFWWindow_SetKeyCallback(b.handle()) } -func (b *GLFWBackend) KeyCallback() imgui.KeyCallback { +func (b *GLFWBackend) KeyCallback() backend.KeyCallback { return b.keyCb } -func (b *GLFWBackend) SetSizeChangeCallback(cbfun imgui.SizeChangeCallback) { +func (b *GLFWBackend) SetSizeChangeCallback(cbfun backend.SizeChangeCallback) { b.sizeCb = cbfun C.igGLFWWindow_SetSizeCallback(b.handle()) } -func (b *GLFWBackend) SizeCallback() imgui.SizeChangeCallback { +func (b *GLFWBackend) SizeCallback() backend.SizeChangeCallback { return b.sizeCb } diff --git a/glfwbackend/glfw_backend.h b/backend/glfwbackend/glfw_backend.h similarity index 97% rename from glfwbackend/glfw_backend.h rename to backend/glfwbackend/glfw_backend.h index 2a814c53f..469f23721 100644 --- a/glfwbackend/glfw_backend.h +++ b/backend/glfwbackend/glfw_backend.h @@ -1,8 +1,8 @@ #pragma once -#include "../cimgui_wrapper.h" -#include "../thirdparty/glfw/include/GLFW/glfw3.h" // Will drag system OpenGL headers -#include "../extra_types.h" +#include "../../cimgui_wrapper.h" +#include "../../thirdparty/glfw/include/GLFW/glfw3.h" // Will drag system OpenGL headers +#include "../../extra_types.h" #ifdef __cplusplus extern "C" { diff --git a/backend/sdlbackend/cflags.go b/backend/sdlbackend/cflags.go new file mode 100644 index 000000000..1c35025cc --- /dev/null +++ b/backend/sdlbackend/cflags.go @@ -0,0 +1,10 @@ +package sdlbackend + +// #cgo CPPFLAGS: -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS +// #cgo CXXFLAGS: --std=c++11 +// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../../lib/linux/x64/cimgui.a +// #cgo linux CXXFLAGS: -Wno-changes-meaning -Wno-invalid-conversion -fpermissive +// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../../lib/windows/x64 -l:cimgui.a +// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/x64/cimgui.a +// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/arm64/cimgui.a +import "C" diff --git a/sdlbackend/sdl_backend.cpp b/backend/sdlbackend/sdl_backend.cpp similarity index 97% rename from sdlbackend/sdl_backend.cpp rename to backend/sdlbackend/sdl_backend.cpp index 327294379..daafd1bf5 100644 --- a/sdlbackend/sdl_backend.cpp +++ b/backend/sdlbackend/sdl_backend.cpp @@ -12,21 +12,21 @@ // - Introduction, links and more at the top of imgui.cpp #include "sdl_backend.h" -#include "../cimgui/cimgui.h" -#include "../cimgui/cimgui_impl.h" +#include "../../cimgui/cimgui.h" +#include "../../cimgui/cimgui_impl.h" #include #include -#include "../thirdparty/SDL/include/SDL.h" +#include "../../thirdparty/SDL/include/SDL.h" #if defined(IMGUI_IMPL_OPENGL_ES2) -#include "../thirdparty/SDL/include/SDL_opengles2.h" +#include "../../thirdparty/SDL/include/SDL_opengles2.h" #else -#include "../thirdparty/SDL/include/SDL_opengl.h" +#include "../../thirdparty/SDL/include/SDL_opengl.h" #endif // This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details. #ifdef __EMSCRIPTEN__ -#include "../libs/emscripten/emscripten_mainloop_stub.h" +#include "../../libs/emscripten/emscripten_mainloop_stub.h" #endif ImVec4 sdl_clear_color = *ImVec4_ImVec4_Float(0.45, 0.55, 0.6, 1.0); diff --git a/sdlbackend/sdl_backend.go b/backend/sdlbackend/sdl_backend.go similarity index 91% rename from sdlbackend/sdl_backend.go rename to backend/sdlbackend/sdl_backend.go index 7bfaa250a..93b0537e5 100644 --- a/sdlbackend/sdl_backend.go +++ b/backend/sdlbackend/sdl_backend.go @@ -1,10 +1,10 @@ package sdlbackend -// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../lib/linux/x64/libSDL2.a -ldl -lGL -lX11 -// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../lib/windows/x64 -l:libSDL2.a -lgdi32 -lopengl32 -limm32 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid +// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../../lib/linux/x64/libSDL2.a -ldl -lGL -lX11 +// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../../lib/windows/x64 -l:libSDL2.a -lgdi32 -lopengl32 -limm32 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid // #cgo darwin LDFLAGS: -framework Cocoa -framework IOKit -framework CoreVideo -// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/x64/libSDL2.a -// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/arm64/libSDL2.a +// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/x64/libSDL2.a +// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../../lib/macos/arm64/libSDL2.a // #cgo !gles2,darwin LDFLAGS: -framework OpenGL // #cgo gles2,darwin LDFLAGS: -lGLESv2 // #cgo CPPFLAGS: -DCIMGUI_GO_USE_SDL2 @@ -20,6 +20,7 @@ import ( "unsafe" imgui "github.com/AllenDang/cimgui-go" + "github.com/AllenDang/cimgui-go/backend" ) type voidCallbackFunc func() @@ -213,7 +214,7 @@ const ( ) */ -var _ imgui.Backend[SDLWindowFlags] = &SDLBackend{} +var _ backend.Backend[SDLWindowFlags] = &SDLBackend{} type SDLBackend struct { afterCreateContext voidCallbackFunc @@ -221,10 +222,10 @@ type SDLBackend struct { beforeRender voidCallbackFunc afterRender voidCallbackFunc beforeDestoryContext voidCallbackFunc - dropCB imgui.DropCallback + dropCB backend.DropCallback closeCB func(pointer unsafe.Pointer) - keyCb imgui.KeyCallback - sizeCb imgui.SizeChangeCallback + keyCb backend.KeyCallback + sizeCb backend.SizeChangeCallback window uintptr } @@ -286,14 +287,14 @@ func (b *SDLBackend) SetBgColor(color imgui.Vec4) { func (b *SDLBackend) Run(loop func()) { b.loop = loop - C.igSDLRunLoop(b.handle(), C.VoidCallback(imgui.LoopCallback()), C.VoidCallback(imgui.BeforeRender()), C.VoidCallback(imgui.AfterRender()), C.VoidCallback(imgui.BeforeDestroyContext())) + C.igSDLRunLoop(b.handle(), C.VoidCallback(backend.LoopCallback()), C.VoidCallback(backend.BeforeRender()), C.VoidCallback(backend.AfterRender()), C.VoidCallback(backend.BeforeDestroyContext())) } func (b *SDLBackend) LoopFunc() func() { return b.loop } -func (b *SDLBackend) DropCallback() imgui.DropCallback { +func (b *SDLBackend) DropCallback() backend.DropCallback { return b.dropCB } @@ -372,7 +373,7 @@ func (b *SDLBackend) CreateWindow(title string, width, height int) { (*C.char)(titleArg), C.int(width), C.int(height), - C.VoidCallback(imgui.AfterCreateContext()), + C.VoidCallback(backend.AfterCreateContext()), ))) if b.window == 0 { panic("Failed to create SDL window") @@ -403,13 +404,13 @@ func (b *SDLBackend) DeleteTexture(id imgui.TextureID) { // SetDropCallback sets the drop callback which is called when an object // is dropped over the window. -func (b *SDLBackend) SetDropCallback(cbfun imgui.DropCallback) { +func (b *SDLBackend) SetDropCallback(cbfun backend.DropCallback) { b.dropCB = cbfun // TODO: not implemented // C.igSDLWindow_SetDropCallbackCB(b.handle()) } -func (b *SDLBackend) SetCloseCallback(cbfun imgui.WindowCloseCallback[SDLWindowFlags]) { +func (b *SDLBackend) SetCloseCallback(cbfun backend.WindowCloseCallback[SDLWindowFlags]) { b.closeCB = func(_ unsafe.Pointer) { cbfun(b) } @@ -477,23 +478,23 @@ func (b *SDLBackend) SetIcons(images ...image.Image) { } } -func (b *SDLBackend) SetKeyCallback(cbfun imgui.KeyCallback) { +func (b *SDLBackend) SetKeyCallback(cbfun backend.KeyCallback) { b.keyCb = cbfun // TODO: not implemented // C.igSDLWindow_SetKeyCallback(b.handle()) } -func (b *SDLBackend) KeyCallback() imgui.KeyCallback { +func (b *SDLBackend) KeyCallback() backend.KeyCallback { return b.keyCb } -func (b *SDLBackend) SetSizeChangeCallback(cbfun imgui.SizeChangeCallback) { +func (b *SDLBackend) SetSizeChangeCallback(cbfun backend.SizeChangeCallback) { b.sizeCb = cbfun // TODO: notttt pimlemented // C.igSDLWindow_SetSizeCallback(b.handle()) } -func (b *SDLBackend) SizeCallback() imgui.SizeChangeCallback { +func (b *SDLBackend) SizeCallback() backend.SizeChangeCallback { return b.sizeCb } diff --git a/sdlbackend/sdl_backend.h b/backend/sdlbackend/sdl_backend.h similarity index 97% rename from sdlbackend/sdl_backend.h rename to backend/sdlbackend/sdl_backend.h index 3ece4f56c..12405ba1a 100644 --- a/sdlbackend/sdl_backend.h +++ b/backend/sdlbackend/sdl_backend.h @@ -1,8 +1,8 @@ #pragma once -#include "../cimgui_wrapper.h" -#include "../thirdparty/SDL/include/SDL.h" // Will drag system OpenGL headers -#include "../extra_types.h" +#include "../../cimgui_wrapper.h" +#include "../../thirdparty/SDL/include/SDL.h" // Will drag system OpenGL headers +#include "../../extra_types.h" #ifdef __cplusplus extern "C" { diff --git a/texture.go b/backend/texture.go similarity index 94% rename from texture.go rename to backend/texture.go index dc3fdccac..771ab8663 100644 --- a/texture.go +++ b/backend/texture.go @@ -1,4 +1,4 @@ -package imgui +package backend import ( "fmt" @@ -9,10 +9,12 @@ import ( "os" "path/filepath" "runtime" + + imgui "github.com/AllenDang/cimgui-go" ) type Texture struct { - ID TextureID + ID imgui.TextureID Width int Height int } diff --git a/cwrappers/imnodes/vcpkg/triplets/arm-neon-android.cmake b/cwrappers/imnodes/vcpkg/triplets/arm-neon-android.cmake new file mode 100644 index 000000000..a26d9aa3e --- /dev/null +++ b/cwrappers/imnodes/vcpkg/triplets/arm-neon-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=armv7a-linux-androideabi") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON) diff --git a/cwrappers/imnodes/vcpkg/triplets/arm64-android.cmake b/cwrappers/imnodes/vcpkg/triplets/arm64-android.cmake new file mode 100644 index 000000000..784f0d39c --- /dev/null +++ b/cwrappers/imnodes/vcpkg/triplets/arm64-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=aarch64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=arm64-v8a) diff --git a/cwrappers/imnodes/vcpkg/triplets/arm64-osx.cmake b/cwrappers/imnodes/vcpkg/triplets/arm64-osx.cmake new file mode 100644 index 000000000..62325a696 --- /dev/null +++ b/cwrappers/imnodes/vcpkg/triplets/arm64-osx.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_OSX_ARCHITECTURES arm64) diff --git a/cwrappers/imnodes/vcpkg/triplets/arm64-uwp.cmake b/cwrappers/imnodes/vcpkg/triplets/arm64-uwp.cmake new file mode 100644 index 000000000..b37c34e87 --- /dev/null +++ b/cwrappers/imnodes/vcpkg/triplets/arm64-uwp.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE arm64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME WindowsStore) +set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) diff --git a/cwrappers/imnodes/vcpkg/triplets/x64-android.cmake b/cwrappers/imnodes/vcpkg/triplets/x64-android.cmake new file mode 100644 index 000000000..28404f4ed --- /dev/null +++ b/cwrappers/imnodes/vcpkg/triplets/x64-android.cmake @@ -0,0 +1,6 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Android) +set(VCPKG_MAKE_BUILD_TRIPLET "--host=x86_64-linux-android") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86_64) diff --git a/examples/ebiten/main.go b/examples/ebiten/main.go index 094f4fffe..687ca9a33 100644 --- a/examples/ebiten/main.go +++ b/examples/ebiten/main.go @@ -6,7 +6,8 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" - ebitenbackend "github.com/AllenDang/cimgui-go/ebiten-backend" + "github.com/AllenDang/cimgui-go/backend" + ebitenbackend "github.com/AllenDang/cimgui-go/backend/ebiten-backend" ) var ( @@ -22,9 +23,9 @@ var ( a float32 color4 [4]float32 = [4]float32{r, g, b, a} selected bool - backend imgui.Backend[ebitenbackend.EbitenBackendFlags] + currentBackend backend.Backend[ebitenbackend.EbitenBackendFlags] img *image.RGBA - texture *imgui.Texture + texture *backend.Texture barValues []int64 ) @@ -41,7 +42,7 @@ func showWidgetsDemo() { imgui.SetNextWindowSizeV(imgui.NewVec2(300, 300), imgui.CondOnce) imgui.Begin("Window 1") if imgui.ButtonV("Click Me", imgui.NewVec2(80, 20)) { - w, h := backend.DisplaySize() + w, h := currentBackend.DisplaySize() fmt.Println(w, h) } imgui.TextUnformatted("Unformatted text") @@ -97,7 +98,7 @@ func showImPlotDemo() { } func afterCreateContext() { - texture = imgui.NewTextureFromRgba(img) + texture = backend.NewTextureFromRgba(img) imgui.PlotCreateContext() } @@ -117,7 +118,7 @@ func init() { func main() { var err error - img, err = imgui.LoadImage("../assets/test.jpeg") + img, err = backend.LoadImage("../assets/test.jpeg") if err != nil { panic("Failed to load test.jpeg") } @@ -126,13 +127,13 @@ func main() { barValues = append(barValues, int64(i+1)) } - backend, _ = imgui.CreateBackend(ebitenbackend.NewEbitenBackend()) - backend.SetAfterCreateContextHook(afterCreateContext) - backend.SetBeforeDestroyContextHook(beforeDestroyContext) + currentBackend, _ = backend.CreateBackend(ebitenbackend.NewEbitenBackend()) + currentBackend.SetAfterCreateContextHook(afterCreateContext) + currentBackend.SetBeforeDestroyContextHook(beforeDestroyContext) - backend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) + currentBackend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) - backend.CreateWindow("Hello from cimgui-go", 1200, 900) + currentBackend.CreateWindow("Hello from cimgui-go", 1200, 900) // TODO: not implemented /* @@ -141,11 +142,11 @@ func main() { }) */ - backend.SetCloseCallback(func(b imgui.Backend[ebitenbackend.EbitenBackendFlags]) { + currentBackend.SetCloseCallback(func(b backend.Backend[ebitenbackend.EbitenBackendFlags]) { fmt.Println("window is closing") }) - backend.SetIcons(img) + currentBackend.SetIcons(img) - backend.Run(loop) + currentBackend.Run(loop) } diff --git a/examples/glfw/main.go b/examples/glfw/main.go index 4d9dea9ff..f4fc1c16b 100644 --- a/examples/glfw/main.go +++ b/examples/glfw/main.go @@ -6,7 +6,8 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" - "github.com/AllenDang/cimgui-go/glfwbackend" + "github.com/AllenDang/cimgui-go/backend" + "github.com/AllenDang/cimgui-go/backend/glfwbackend" ) var ( @@ -22,9 +23,9 @@ var ( a float32 color4 [4]float32 = [4]float32{r, g, b, a} selected bool - backend imgui.Backend[glfwbackend.GLFWWindowFlags] + currentBackend backend.Backend[glfwbackend.GLFWWindowFlags] img *image.RGBA - texture *imgui.Texture + texture *backend.Texture barValues []int64 ) @@ -41,7 +42,7 @@ func showWidgetsDemo() { imgui.SetNextWindowSizeV(imgui.NewVec2(300, 300), imgui.CondOnce) imgui.Begin("Window 1") if imgui.ButtonV("Click Me", imgui.NewVec2(80, 20)) { - w, h := backend.DisplaySize() + w, h := currentBackend.DisplaySize() fmt.Println(w, h) } imgui.TextUnformatted("Unformatted text") @@ -97,7 +98,7 @@ func showImPlotDemo() { } func afterCreateContext() { - texture = imgui.NewTextureFromRgba(img) + texture = backend.NewTextureFromRgba(img) imgui.PlotCreateContext() } @@ -117,7 +118,7 @@ func init() { func main() { var err error - img, err = imgui.LoadImage("../assets/test.jpeg") + img, err = backend.LoadImage("../assets/test.jpeg") if err != nil { panic("Failed to load test.jpeg") } @@ -126,23 +127,23 @@ func main() { barValues = append(barValues, int64(i+1)) } - backend, _ = imgui.CreateBackend(glfwbackend.NewGLFWBackend()) - backend.SetAfterCreateContextHook(afterCreateContext) - backend.SetBeforeDestroyContextHook(beforeDestroyContext) + currentBackend, _ = backend.CreateBackend(glfwbackend.NewGLFWBackend()) + currentBackend.SetAfterCreateContextHook(afterCreateContext) + currentBackend.SetBeforeDestroyContextHook(beforeDestroyContext) - backend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) + currentBackend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) - backend.CreateWindow("Hello from cimgui-go", 1200, 900) + currentBackend.CreateWindow("Hello from cimgui-go", 1200, 900) - backend.SetDropCallback(func(p []string) { + currentBackend.SetDropCallback(func(p []string) { fmt.Printf("drop triggered: %v", p) }) - backend.SetCloseCallback(func(b imgui.Backend[glfwbackend.GLFWWindowFlags]) { + currentBackend.SetCloseCallback(func(b backend.Backend[glfwbackend.GLFWWindowFlags]) { fmt.Println("window is closing") }) - backend.SetIcons(img) + currentBackend.SetIcons(img) - backend.Run(loop) + currentBackend.Run(loop) } diff --git a/examples/sdl/main.go b/examples/sdl/main.go index 4be1a5bb6..c4c56c32d 100644 --- a/examples/sdl/main.go +++ b/examples/sdl/main.go @@ -8,7 +8,8 @@ import ( "runtime" imgui "github.com/AllenDang/cimgui-go" - "github.com/AllenDang/cimgui-go/sdlbackend" + "github.com/AllenDang/cimgui-go/backend" + "github.com/AllenDang/cimgui-go/backend/sdlbackend" ) var ( @@ -24,9 +25,9 @@ var ( a float32 color4 [4]float32 = [4]float32{r, g, b, a} selected bool - backend imgui.Backend[sdlbackend.SDLWindowFlags] + currentBackend backend.Backend[sdlbackend.SDLWindowFlags] img *image.RGBA - texture *imgui.Texture + texture *backend.Texture barValues []int64 ) @@ -43,7 +44,7 @@ func showWidgetsDemo() { imgui.SetNextWindowSizeV(imgui.NewVec2(300, 300), imgui.CondOnce) imgui.Begin("Window 1") if imgui.ButtonV("Click Me", imgui.NewVec2(80, 20)) { - w, h := backend.DisplaySize() + w, h := currentBackend.DisplaySize() fmt.Println(w, h) } imgui.TextUnformatted("Unformatted text") @@ -99,7 +100,7 @@ func showImPlotDemo() { } func afterCreateContext() { - texture = imgui.NewTextureFromRgba(img) + texture = backend.NewTextureFromRgba(img) imgui.PlotCreateContext() } @@ -119,7 +120,7 @@ func init() { func main() { var err error - img, err = imgui.LoadImage("../assets/test.jpeg") + img, err = backend.LoadImage("../assets/test.jpeg") if err != nil { panic("Failed to load test.jpeg") } @@ -128,23 +129,23 @@ func main() { barValues = append(barValues, int64(i+1)) } - backend, _ = imgui.CreateBackend(sdlbackend.NewSDLBackend()) - backend.SetAfterCreateContextHook(afterCreateContext) - backend.SetBeforeDestroyContextHook(beforeDestroyContext) + currentBackend, _ = backend.CreateBackend(sdlbackend.NewSDLBackend()) + currentBackend.SetAfterCreateContextHook(afterCreateContext) + currentBackend.SetBeforeDestroyContextHook(beforeDestroyContext) - backend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) + currentBackend.SetBgColor(imgui.NewVec4(0.45, 0.55, 0.6, 1.0)) - backend.CreateWindow("Hello from cimgui-go", 1200, 900) + currentBackend.CreateWindow("Hello from cimgui-go", 1200, 900) - backend.SetDropCallback(func(p []string) { + currentBackend.SetDropCallback(func(p []string) { fmt.Printf("drop triggered: %v", p) }) - backend.SetCloseCallback(func(b imgui.Backend[sdlbackend.SDLWindowFlags]) { + currentBackend.SetCloseCallback(func(b backend.Backend[sdlbackend.SDLWindowFlags]) { fmt.Println("window is closing") }) - backend.SetIcons(img) + currentBackend.SetIcons(img) - backend.Run(loop) + currentBackend.Run(loop) } diff --git a/extra_types.go b/extra_types.go index a50833413..4f9867fe7 100644 --- a/extra_types.go +++ b/extra_types.go @@ -62,6 +62,11 @@ func (i Vec4) toC() C.ImVec4 { return C.ImVec4{x: C.float(i.X), y: C.float(i.Y), z: C.float(i.Z), w: C.float(i.W)} } +// TODO: remove this +func (i Vec4) ToC() C.ImVec4 { + return i.toC() +} + var _ wrappableType[C.ImColor, *Color] = &Color{} type Color struct { diff --git a/glfwbackend/cflags.go b/glfwbackend/cflags.go deleted file mode 100644 index 5e5f50500..000000000 --- a/glfwbackend/cflags.go +++ /dev/null @@ -1,10 +0,0 @@ -package glfwbackend - -// #cgo CPPFLAGS: -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS -// #cgo CXXFLAGS: --std=c++11 -// #cgo amd64,linux LDFLAGS: ${SRCDIR}/../lib/linux/x64/cimgui.a -// #cgo linux CXXFLAGS: -Wno-changes-meaning -Wno-invalid-conversion -fpermissive -// #cgo amd64,windows LDFLAGS: -L${SRCDIR}/../lib/windows/x64 -l:cimgui.a -// #cgo amd64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/x64/cimgui.a -// #cgo arm64,darwin LDFLAGS: ${SRCDIR}/../lib/macos/arm64/cimgui.a -import "C"