Return channel from run method
This commit is contained in:
parent
11bdae78a0
commit
e7b5136ea6
@ -18,13 +18,13 @@ func (application *Application) SetTitle (title string) {
|
||||
application.backend.SetTitle(title)
|
||||
}
|
||||
|
||||
// Run initializes the application, and then calls callback. Operations inside
|
||||
// of callback are allowed to interact with the application. Depending on the
|
||||
// backend used, this function may bind to the main thread.
|
||||
// Run initializes the application, starts it, and then returns a channel that
|
||||
// broadcasts events. If no suitable backend can be found, an error is returned.
|
||||
func (application *Application) Run (
|
||||
callback func (application *Application),
|
||||
) (
|
||||
err error,
|
||||
channel chan(Event),
|
||||
err error,
|
||||
) {
|
||||
// default values for certain parameters
|
||||
width, height := application.Size()
|
||||
@ -44,7 +44,7 @@ func (application *Application) Run (
|
||||
|
||||
application.backend, err = instantiateBackend(application)
|
||||
if err != nil { return }
|
||||
application.backend.Run(callback)
|
||||
channel = application.backend.Run()
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package stone
|
||||
|
||||
import "time"
|
||||
import "image"
|
||||
import "errors"
|
||||
|
||||
type Backend interface {
|
||||
Run () (chan(Event))
|
||||
Run () (channel chan(Event))
|
||||
SetTitle (title string)
|
||||
SetIcon (icons []image.Image)
|
||||
}
|
||||
|
3
event.go
3
event.go
@ -1,7 +1,8 @@
|
||||
package application
|
||||
package stone
|
||||
|
||||
type Event interface { }
|
||||
|
||||
type EventQuit struct { }
|
||||
type EventPress Button
|
||||
type EventRelease Button
|
||||
type EventResize struct { }
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
import _ "git.tebibyte.media/sashakoshka/stone/backends/pixel"
|
||||
// import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
||||
|
||||
func main () {
|
||||
application := stone.Application { }
|
||||
|
Loading…
Reference in New Issue
Block a user