forked from noisetorch/NoiseTorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.go
45 lines (32 loc) · 803 Bytes
/
views.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// This file is part of the program "NoiseTorch-ng".
// Please see the LICENSE file for copyright information.
package main
import (
"log"
"github.com/aarzilli/nucular"
)
type ViewFunc func(ctx *ntcontext, w *nucular.Window)
type ViewStack struct {
items []ViewFunc
}
func NewViewStack() *ViewStack {
return &ViewStack{make([]ViewFunc, 0)}
}
func (v *ViewStack) Push(f ViewFunc) {
v.items = append(v.items, f)
}
func (v *ViewStack) Pop() ViewFunc {
if len(v.items) == 0 {
log.Fatal("Tried to Pop an empty ViewStack")
}
item := v.items[len(v.items)-1]
// The last item gets removed
v.items = v.items[:len(v.items)-1]
return item
}
func (v *ViewStack) Peek() ViewFunc {
if len(v.items) == 0 {
log.Fatal("Tried to Peek an empty ViewStack")
}
return v.items[len(v.items)-1]
}