Skip to content

Commit

Permalink
Merge pull request #398 from gucio321/backend-change
Browse files Browse the repository at this point in the history
change(backend): dont take Backend as an arg to WIndowCloseCallback
  • Loading branch information
gucio321 authored Dec 17, 2024
2 parents f8b45fb + 6d94ba5 commit 3c6fe4a
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type (
SizeChangeCallback func(w, h int)
)

type WindowCloseCallback[BackendFlagsT ~int] func(b Backend[BackendFlagsT])
type WindowCloseCallback func()

//export closeCallback
func closeCallback(wnd unsafe.Pointer) {
Expand Down Expand Up @@ -161,7 +161,7 @@ type Backend[BackendFlagsT ~int] interface {
SetTargetFPS(fps uint)

SetDropCallback(DropCallback)
SetCloseCallback(WindowCloseCallback[BackendFlagsT])
SetCloseCallback(WindowCloseCallback)
SetKeyCallback(KeyCallback)
SetSizeChangeCallback(SizeChangeCallback)
// SetWindowFlags selected hint to specified value.
Expand Down
2 changes: 1 addition & 1 deletion backend/ebiten-backend/cimgui_backend_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (b *EbitenBackend) SetDropCallback(backend.DropCallback) {
panic("SetDropCallback is not implemented for Ebiten backend yet.")
}

func (b *EbitenBackend) SetCloseCallback(cb backend.WindowCloseCallback[EbitenBackendFlags]) {
func (b *EbitenBackend) SetCloseCallback(cb backend.WindowCloseCallback) {
b.closeCb = cb
}

Expand Down
4 changes: 2 additions & 2 deletions backend/ebiten-backend/ebiten_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type EbitenBackend struct {
afterRender,
beforeDestroy,
loop func()
closeCb backend.WindowCloseCallback[EbitenBackendFlags]
closeCb backend.WindowCloseCallback

// ebiten stuff
filter ebiten.Filter
Expand Down Expand Up @@ -112,7 +112,7 @@ func (e *EbitenBackend) SetContext(ctx *imgui.Context) *EbitenBackend {
// This is usually called inside the game's Update() function.
func (e *EbitenBackend) BeginFrame() {
if ebiten.IsWindowBeingClosed() && e.closeCb != nil {
e.closeCb(e)
e.closeCb()
}

if e.beforeRender != nil {
Expand Down
4 changes: 2 additions & 2 deletions backend/glfwbackend/glfw_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ func (b *GLFWBackend) SetDropCallback(cbfun backend.DropCallback) {
C.igGLFWWindow_SetDropCallbackCB(b.handle())
}

func (b *GLFWBackend) SetCloseCallback(cbfun backend.WindowCloseCallback[GLFWWindowFlags]) {
func (b *GLFWBackend) SetCloseCallback(cbfun backend.WindowCloseCallback) {
b.closeCB = func(_ unsafe.Pointer) {
cbfun(b)
cbfun()
}

C.igGLFWWindow_SetCloseCallback(b.handle())
Expand Down
4 changes: 2 additions & 2 deletions backend/sdlbackend/sdl_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ func (b *SDLBackend) SetDropCallback(cbfun backend.DropCallback) {
// C.igSDLWindow_SetDropCallbackCB(b.handle())
}

func (b *SDLBackend) SetCloseCallback(cbfun backend.WindowCloseCallback[SDLWindowFlags]) {
func (b *SDLBackend) SetCloseCallback(cbfun backend.WindowCloseCallback) {
b.closeCB = func(_ unsafe.Pointer) {
cbfun(b)
cbfun()
}

// TODO: not implemented
Expand Down
2 changes: 1 addition & 1 deletion examples/ebiten-game-in-texture/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
})
*/

currentBackend.SetCloseCallback(func(b backend.Backend[ebitenbackend.EbitenBackendFlags]) {
currentBackend.SetCloseCallback(func() {
fmt.Println("window is closing")
})

Expand Down
2 changes: 1 addition & 1 deletion examples/ebiten/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
})
*/

currentBackend.SetCloseCallback(func(b backend.Backend[ebitenbackend.EbitenBackendFlags]) {
currentBackend.SetCloseCallback(func() {
fmt.Println("window is closing")
})

Expand Down
2 changes: 1 addition & 1 deletion examples/glfw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
fmt.Printf("drop triggered: %v", p)
})

currentBackend.SetCloseCallback(func(b backend.Backend[glfwbackend.GLFWWindowFlags]) {
currentBackend.SetCloseCallback(func() {
fmt.Println("window is closing")
})

Expand Down
2 changes: 1 addition & 1 deletion examples/sdl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
fmt.Printf("drop triggered: %v", p)
})

currentBackend.SetCloseCallback(func(b backend.Backend[sdlbackend.SDLWindowFlags]) {
currentBackend.SetCloseCallback(func() {
fmt.Println("window is closing")
})

Expand Down

0 comments on commit 3c6fe4a

Please sign in to comment.