mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
app: change EndPaint to Publish.
More than a name change, the painting model changes so that the app, not the library, is responsible for driving painting. If the app is animating and wants paint events at 60 Hz, it has to ask for that. If the app is not animating and doesn't need to update its screen, it shouldn't get any paint events. Plenty of TODOs, and this CL doesn't get us to a perfect place, but it is a checkpoint along the way. The darwin_*.go code changes were minimal. I don't even have a Mac or iOS device to test that this even builds. Even so, the TODOs about not sending paint.Events unconditionally are important TODOs. That's the whole point of switching to this model. I'll leave the actual implementation to you (crawshaw). Out of all the example apps, the change to example/network/main.go is probably the most interesting. It seems like there ought to be some way to reduce the copy/paste between all of the example app code, but I'll leave that for future CLs. Change-Id: I17e11c06174110c68e17f7183b2d8af19b6a170e Reviewed-on: https://go-review.googlesource.com/14300 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
+13
-2
@@ -57,14 +57,16 @@ var (
|
||||
|
||||
func main() {
|
||||
app.Main(func(a app.App) {
|
||||
var sz size.Event
|
||||
visible, sz := false, size.Event{}
|
||||
for e := range a.Events() {
|
||||
switch e := app.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
switch e.Crosses(lifecycle.StageVisible) {
|
||||
case lifecycle.CrossOn:
|
||||
visible = true
|
||||
onStart()
|
||||
case lifecycle.CrossOff:
|
||||
visible = false
|
||||
onStop()
|
||||
}
|
||||
case size.Event:
|
||||
@@ -73,7 +75,16 @@ func main() {
|
||||
touchY = float32(sz.HeightPx / 2)
|
||||
case paint.Event:
|
||||
onPaint(sz)
|
||||
a.EndPaint(e)
|
||||
a.Publish()
|
||||
if visible {
|
||||
// Drive the animation by preparing to paint the next frame
|
||||
// after this one is shown.
|
||||
//
|
||||
// TODO: is paint.Event the right thing to send? Should we
|
||||
// have a dedicated publish.Event type? Should App.Publish
|
||||
// take an optional event sender and send a publish.Event?
|
||||
a.Send(paint.Event{})
|
||||
}
|
||||
case touch.Event:
|
||||
touchX = e.X
|
||||
touchY = e.Y
|
||||
|
||||
Reference in New Issue
Block a user