Skip to content

Commit

Permalink
add Gopt_Game_Gopx_GetWidget in widget for ispx runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Aug 16, 2024
1 parent cb369a1 commit 72e51cd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions widget/widget.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package widget

import (
"github.com/goplus/spx"
)

func Gopt_Game_Gopx_GetWidget[T any](sg spx.ShapeGetter, name string) *T {
items := sg.GetAllShapes()
for _, item := range items {
widget, ok := item.(spx.Widget)
if ok && widget.GetName() == name {
if result, ok := widget.(interface{}).(*T); ok {
return result
} else {
panic("GetWidget: type mismatch")
}
}
}
panic("GetWidget: widget not found - " + name)
}

0 comments on commit 72e51cd

Please sign in to comment.