mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-17 16:20:33 -07:00
use UICycle to cycle through layout
This commit is contained in:
parent
d15257528a
commit
4bf68d1763
2
main.go
2
main.go
@ -14,8 +14,10 @@ var (
|
||||
dstBox = tview.NewTextView()
|
||||
srcLangDropDown = tview.NewDropDown()
|
||||
dstLangDropDown = tview.NewDropDown()
|
||||
langCycle = NewUICycle(srcLangDropDown, dstLangDropDown)
|
||||
themeDropDown = tview.NewDropDown()
|
||||
transparentDropDown = tview.NewDropDown()
|
||||
styleCycle = NewUICycle(themeDropDown, transparentDropDown)
|
||||
langButton = tview.NewButton("(1)Language")
|
||||
styleButton = tview.NewButton("(2)Style")
|
||||
menuButton = tview.NewButton("(3)KeyMap")
|
||||
|
76
ui.go
76
ui.go
@ -6,6 +6,34 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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) GetCurrentUI() tview.Primitive {
|
||||
return ui.widget[ui.index]
|
||||
}
|
||||
|
||||
func updateBackgroundColor() {
|
||||
// box
|
||||
srcBox.SetBackgroundColor(window.src.backgroundColor)
|
||||
@ -175,12 +203,14 @@ func uiInit() {
|
||||
langWindow.SetInputCapture(langWindowHandler)
|
||||
styleWindow.SetInputCapture(styleWindowHandler)
|
||||
translateWindow.SetInputCapture(translatePageHandler)
|
||||
srcLangDropDown.SetDoneFunc(srcDropDownHandler).
|
||||
srcLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||
SetSelectedFunc(srcLangSelected)
|
||||
dstLangDropDown.SetDoneFunc(dstDropDownHandler).
|
||||
dstLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||
SetSelectedFunc(dstLangSelected)
|
||||
themeDropDown.SetSelectedFunc(themeSelected)
|
||||
transparentDropDown.SetSelectedFunc(transparentSelected)
|
||||
themeDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(themeSelected)
|
||||
transparentDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(transparentSelected)
|
||||
langButton.SetSelectedFunc(func() {
|
||||
mainPage.HidePage("stylePage")
|
||||
mainPage.ShowPage("langPage")
|
||||
@ -301,6 +331,16 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
||||
return event
|
||||
}
|
||||
|
||||
func langDropDownHandler(key tcell.Key) {
|
||||
switch key {
|
||||
case tcell.KeyTAB:
|
||||
langCycle.Increase()
|
||||
app.SetFocus(langCycle.GetCurrentUI())
|
||||
case tcell.KeyEsc:
|
||||
mainPage.HidePage("langPage")
|
||||
}
|
||||
}
|
||||
|
||||
func srcLangSelected(text string, index int) {
|
||||
translator.srcLang = text
|
||||
srcBox.SetTitle(text)
|
||||
@ -313,6 +353,16 @@ func dstLangSelected(text string, index int) {
|
||||
dstLangDropDown.SetTitle(text)
|
||||
}
|
||||
|
||||
func styleDropDownHandler(key tcell.Key) {
|
||||
switch key {
|
||||
case tcell.KeyTAB:
|
||||
styleCycle.Increase()
|
||||
app.SetFocus(styleCycle.GetCurrentUI())
|
||||
case tcell.KeyEsc:
|
||||
mainPage.HidePage("stylePage")
|
||||
}
|
||||
}
|
||||
|
||||
func themeSelected(text string, index int) {
|
||||
theme = text
|
||||
window.colorInit()
|
||||
@ -330,21 +380,3 @@ func transparentSelected(text string, index int) {
|
||||
}
|
||||
updateBackgroundColor()
|
||||
}
|
||||
|
||||
func srcDropDownHandler(key tcell.Key) {
|
||||
switch key {
|
||||
case tcell.KeyTAB:
|
||||
app.SetFocus(dstLangDropDown)
|
||||
case tcell.KeyEsc:
|
||||
mainPage.HidePage("langPage")
|
||||
}
|
||||
}
|
||||
|
||||
func dstDropDownHandler(key tcell.Key) {
|
||||
switch key {
|
||||
case tcell.KeyTAB:
|
||||
app.SetFocus(srcLangDropDown)
|
||||
case tcell.KeyEsc:
|
||||
mainPage.HidePage("langPage")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user