mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-18 00:30:40 -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()
|
dstBox = tview.NewTextView()
|
||||||
srcLangDropDown = tview.NewDropDown()
|
srcLangDropDown = tview.NewDropDown()
|
||||||
dstLangDropDown = tview.NewDropDown()
|
dstLangDropDown = tview.NewDropDown()
|
||||||
|
langCycle = NewUICycle(srcLangDropDown, dstLangDropDown)
|
||||||
themeDropDown = tview.NewDropDown()
|
themeDropDown = tview.NewDropDown()
|
||||||
transparentDropDown = tview.NewDropDown()
|
transparentDropDown = tview.NewDropDown()
|
||||||
|
styleCycle = NewUICycle(themeDropDown, transparentDropDown)
|
||||||
langButton = tview.NewButton("(1)Language")
|
langButton = tview.NewButton("(1)Language")
|
||||||
styleButton = tview.NewButton("(2)Style")
|
styleButton = tview.NewButton("(2)Style")
|
||||||
menuButton = tview.NewButton("(3)KeyMap")
|
menuButton = tview.NewButton("(3)KeyMap")
|
||||||
|
76
ui.go
76
ui.go
@ -6,6 +6,34 @@ import (
|
|||||||
"strconv"
|
"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() {
|
func updateBackgroundColor() {
|
||||||
// box
|
// box
|
||||||
srcBox.SetBackgroundColor(window.src.backgroundColor)
|
srcBox.SetBackgroundColor(window.src.backgroundColor)
|
||||||
@ -175,12 +203,14 @@ func uiInit() {
|
|||||||
langWindow.SetInputCapture(langWindowHandler)
|
langWindow.SetInputCapture(langWindowHandler)
|
||||||
styleWindow.SetInputCapture(styleWindowHandler)
|
styleWindow.SetInputCapture(styleWindowHandler)
|
||||||
translateWindow.SetInputCapture(translatePageHandler)
|
translateWindow.SetInputCapture(translatePageHandler)
|
||||||
srcLangDropDown.SetDoneFunc(srcDropDownHandler).
|
srcLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||||
SetSelectedFunc(srcLangSelected)
|
SetSelectedFunc(srcLangSelected)
|
||||||
dstLangDropDown.SetDoneFunc(dstDropDownHandler).
|
dstLangDropDown.SetDoneFunc(langDropDownHandler).
|
||||||
SetSelectedFunc(dstLangSelected)
|
SetSelectedFunc(dstLangSelected)
|
||||||
themeDropDown.SetSelectedFunc(themeSelected)
|
themeDropDown.SetDoneFunc(styleDropDownHandler).
|
||||||
transparentDropDown.SetSelectedFunc(transparentSelected)
|
SetSelectedFunc(themeSelected)
|
||||||
|
transparentDropDown.SetDoneFunc(styleDropDownHandler).
|
||||||
|
SetSelectedFunc(transparentSelected)
|
||||||
langButton.SetSelectedFunc(func() {
|
langButton.SetSelectedFunc(func() {
|
||||||
mainPage.HidePage("stylePage")
|
mainPage.HidePage("stylePage")
|
||||||
mainPage.ShowPage("langPage")
|
mainPage.ShowPage("langPage")
|
||||||
@ -301,6 +331,16 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
return event
|
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) {
|
func srcLangSelected(text string, index int) {
|
||||||
translator.srcLang = text
|
translator.srcLang = text
|
||||||
srcBox.SetTitle(text)
|
srcBox.SetTitle(text)
|
||||||
@ -313,6 +353,16 @@ func dstLangSelected(text string, index int) {
|
|||||||
dstLangDropDown.SetTitle(text)
|
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) {
|
func themeSelected(text string, index int) {
|
||||||
theme = text
|
theme = text
|
||||||
window.colorInit()
|
window.colorInit()
|
||||||
@ -330,21 +380,3 @@ func transparentSelected(text string, index int) {
|
|||||||
}
|
}
|
||||||
updateBackgroundColor()
|
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