ui/app,apps: unexport ChangeStage and Stage

I'm not convinced the API is right. For exmaple, an event that
notifies a program when to save its state is both smaller and
might be sufficient.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-05-11 13:50:18 +02:00
parent 314c79a725
commit f9840b0963
8 changed files with 57 additions and 62 deletions
+12 -16
View File
@@ -35,7 +35,7 @@ type Window struct {
events chan Event
mu sync.Mutex
stage Stage
stage stage
size image.Point
syncGPU bool
animating bool
@@ -62,7 +62,7 @@ func newWindow(nw *window) *Window {
w := &Window{
driver: nw,
events: make(chan Event),
stage: StageInvisible,
stage: stageInvisible,
}
return w
}
@@ -103,7 +103,7 @@ func (w *Window) Draw(root *ui.Ops) {
w.hasNextFrame = false
w.syncGPU = false
w.mu.Unlock()
if stage < StageVisible {
if stage < stageVisible {
return
}
if w.gpu != nil {
@@ -176,7 +176,7 @@ func (w *Window) updateAnimation() {
w.mu.Lock()
defer w.mu.Unlock()
animate := false
if w.stage >= StageVisible && w.hasNextFrame {
if w.stage >= stageVisible && w.hasNextFrame {
if dt := time.Until(w.nextFrame); dt <= 0 {
animate = true
} else {
@@ -208,14 +208,10 @@ func (w *Window) Size() image.Point {
return w.size
}
func (w *Window) Stage() Stage {
func (w *Window) IsAlive() bool {
w.mu.Lock()
defer w.mu.Unlock()
return w.stage
}
func (w *Window) IsAlive() bool {
return w.Stage() != StageDead && w.err == nil
return w.stage != stageDead && w.err == nil
}
func (w *Window) contextDriver() interface{} {
@@ -234,9 +230,9 @@ func (w *Window) event(e Event) {
case *Command:
needAck = true
needRedraw = true
case ChangeStage:
w.stage = e.Stage
if w.stage > StageDead {
case changeStage:
w.stage = e.stage
if w.stage > stageDead {
needAck = true
w.syncGPU = true
}
@@ -244,7 +240,7 @@ func (w *Window) event(e Event) {
if e.Size == (image.Point{}) {
panic(errors.New("internal error: zero-sized Draw"))
}
if w.stage < StageVisible {
if w.stage < stageVisible {
// No drawing if not visible.
break
}
@@ -270,14 +266,14 @@ func (w *Window) event(e Event) {
w.syncGPU = false
w.mu.Unlock()
switch {
case stage < StageVisible:
case stage < stageVisible:
w.gpu.Release()
w.gpu = nil
case sync:
w.gpu.Refresh()
}
}
if stage == StageDead {
if stage == stageDead {
close(w.events)
}
}