v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 00:00:16 -07:00
GTT/internal/ui/cycle.go
2022-10-24 22:38:43 +08:00

38 lines
575 B
Go

package ui
import (
"github.com/rivo/tview"
)
type UICycle struct {
widget []tview.Primitive
index int
len int
}
func NewUICycle(widgets ...tview.Primitive) *UICycle {
var w []tview.Primitive
for _, widget := range widgets {
w = append(w, widget)
}
return &UICycle{
widget: w,
index: 0,
len: len(w),
}
}
func (ui *UICycle) Increase() {
ui.index = (ui.index + 1) % ui.len
}
func (ui *UICycle) Decrease() {
ui.index = ((ui.index-1)%ui.len + ui.len) % ui.len
}
func (ui *UICycle) GetCurrentUI() tview.Primitive {
return ui.widget[ui.index]
}