ui/app: rename Window.Redraw to Invalidate to match ui.InvalidateOp

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-18 18:41:39 +02:00
parent 8fc7a316cc
commit d9d8df989d
2 changed files with 25 additions and 22 deletions
+8 -8
View File
@@ -24,8 +24,8 @@ type Router struct {
reader ui.OpsReader reader ui.OpsReader
// InvalidateOp summary. // InvalidateOp summary.
redraw bool wakeup bool
redrawTime time.Time wakeupTime time.Time
// ProfileOp summary. // ProfileOp summary.
profHandlers []input.Key profHandlers []input.Key
@@ -42,7 +42,7 @@ func (q *Router) Events(k input.Key) []input.Event {
func (q *Router) Frame(ops *ui.Ops) { func (q *Router) Frame(ops *ui.Ops) {
q.handlers.Clear() q.handlers.Clear()
q.redraw = false q.wakeup = false
q.profHandlers = q.profHandlers[:0] q.profHandlers = q.profHandlers[:0]
q.reader.Reset(ops) q.reader.Reset(ops)
q.collect() q.collect()
@@ -71,9 +71,9 @@ func (q *Router) collect() {
case ops.TypeInvalidate: case ops.TypeInvalidate:
var op ui.InvalidateOp var op ui.InvalidateOp
op.Decode(encOp.Data) op.Decode(encOp.Data)
if !q.redraw || op.At.Before(q.redrawTime) { if !q.wakeup || op.At.Before(q.wakeupTime) {
q.redraw = true q.wakeup = true
q.redrawTime = op.At q.wakeupTime = op.At
} }
case ops.TypeProfile: case ops.TypeProfile:
var op system.ProfileOp var op system.ProfileOp
@@ -93,8 +93,8 @@ func (q *Router) Profiling() bool {
return len(q.profHandlers) > 0 return len(q.profHandlers) > 0
} }
func (q *Router) RedrawTime() (time.Time, bool) { func (q *Router) WakeupTime() (time.Time, bool) {
return q.redrawTime, q.redraw return q.wakeupTime, q.wakeup
} }
func (h *handlerEvents) init() { func (h *handlerEvents) init() {
+17 -14
View File
@@ -29,11 +29,11 @@ type Window struct {
gpu *gpu.GPU gpu *gpu.GPU
inputState key.TextInputState inputState key.TextInputState
out chan Event out chan Event
in chan Event in chan Event
ack chan struct{} ack chan struct{}
redraws chan struct{} invalidates chan struct{}
frames chan *ui.Ops frames chan *ui.Ops
stage Stage stage Stage
animating bool animating bool
@@ -81,11 +81,11 @@ func NewWindow(opts *WindowOptions) *Window {
} }
w := &Window{ w := &Window{
in: make(chan Event), in: make(chan Event),
out: make(chan Event), out: make(chan Event),
ack: make(chan struct{}), ack: make(chan struct{}),
redraws: make(chan struct{}, 1), invalidates: make(chan struct{}, 1),
frames: make(chan *ui.Ops), frames: make(chan *ui.Ops),
} }
go w.run(opts) go w.run(opts)
return w return w
@@ -133,15 +133,18 @@ func (w *Window) draw(size image.Point, frame *ui.Ops) {
w.router.AddProfile(system.ProfileEvent{Timings: timings}) w.router.AddProfile(system.ProfileEvent{Timings: timings})
w.setNextFrame(time.Time{}) w.setNextFrame(time.Time{})
} }
if t, ok := w.router.RedrawTime(); ok { if t, ok := w.router.WakeupTime(); ok {
w.setNextFrame(t) w.setNextFrame(t)
} }
w.updateAnimation() w.updateAnimation()
} }
func (w *Window) Redraw() { // Invalidate the current window such that a DrawEvent will be generated
// immediately. If the window is not active, the redraw will trigger
// when the window becomes active.
func (w *Window) Invalidate() {
select { select {
case w.redraws <- struct{}{}: case w.invalidates <- struct{}{}:
default: default:
} }
} }
@@ -217,7 +220,7 @@ func (w *Window) run(opts *WindowOptions) {
case <-timer: case <-timer:
w.setNextFrame(time.Time{}) w.setNextFrame(time.Time{})
w.updateAnimation() w.updateAnimation()
case <-w.redraws: case <-w.invalidates:
w.setNextFrame(time.Time{}) w.setNextFrame(time.Time{})
w.updateAnimation() w.updateAnimation()
case e := <-w.in: case e := <-w.in: