kemoforge/internal/KFEditor/Templates/CustomWidget/CustomWidget.got

50 lines
1.3 KiB
Plaintext

package CustomWidget
import (
"log"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"g.r-io.lu/shynd/kemoforge/pkg/KFData"
"g.r-io.lu/shynd/kemoforge/pkg/KFData/KFObjects/KFFunction"
"g.r-io.lu/shynd/kemoforge/pkg/KFData/KFObjects/KFWidget"
)
// Import is a function used to allow importing of the custom widget package
// while still allowing the package to be used normally and not be yelled at by the compiler
func Import() {}
func init() {
log.Printf("Registering ExampleWidget")
customWidget := KFWidget.Widget{
Type: "ExampleWidget",
RequiredArgs: KFData.NewNFInterfaceMap(
KFData.NewKeyVal("action", ""),
KFData.NewKeyVal("message", ""),
),
OptionalArgs: KFData.NewNFInterfaceMap(),
}
customWidget.Register(ExampleWidgetHandler)
}
func ExampleWidgetHandler(window fyne.Window, args *KFData.NFInterfaceMap, w *KFWidget.Widget) (fyne.CanvasObject, error) {
//Get the action from the args
var action string
err := args.Get("action", &action)
if err != nil {
return nil, err
}
var message string
err = args.Get("message", &message)
if err != nil {
return nil, err
}
button := widget.NewButton("Example Button", func() {
//Do something
_, _ = KFFunction.ParseAndRun(window, action, KFData.NewNFInterfaceMap(KFData.NewKeyVal("message", message)))
})
return button, nil
}