2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
import (
|
2023-03-03 14:41:38 -06:00
|
|
|
"embed"
|
2022-11-14 14:30:28 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
"github.com/andlabs/ui"
|
2022-11-06 12:59:24 -06:00
|
|
|
// the _ means we only need this for the init()
|
2022-10-20 06:55:42 -05:00
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
)
|
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
//go:embed resources
|
|
|
|
var res embed.FS
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func Main(f func()) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)")
|
2022-11-14 14:30:28 -06:00
|
|
|
ui.Main( func() {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)")
|
2022-11-14 14:30:28 -06:00
|
|
|
// time.Sleep(1 * time.Second)
|
|
|
|
// NewWindow2("helloworld2", 200, 100)
|
|
|
|
f()
|
|
|
|
})
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Other goroutines must use this to access the GUI
|
|
|
|
//
|
|
|
|
// You can not acess / process the GUI thread directly from
|
|
|
|
// other goroutines. This is due to the nature of how
|
|
|
|
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
|
|
|
|
//
|
|
|
|
// For example: Queue(NewWindow())
|
|
|
|
//
|
|
|
|
func Queue(f func()) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Sending function to ui.QueueMain()")
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugPlugin, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
|
2023-02-25 14:05:25 -06:00
|
|
|
ui.QueueMain(f)
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
|
2022-11-14 14:30:28 -06:00
|
|
|
func Init() {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Init()")
|
2023-03-12 08:47:16 -05:00
|
|
|
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
|
|
|
|
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
|
|
|
|
setDefaultBehavior(true)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
mapWidgets = make(map[*andlabsT]*toolkit.Widget)
|
|
|
|
mapToolkits = make(map[*toolkit.Widget]*andlabsT)
|
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// TODO: properly exit the plugin since Quit() doesn't do it
|
2022-11-14 14:30:28 -06:00
|
|
|
func Quit() {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Quit() TODO: close the toolkit cleanly")
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|