v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-18 08:40:35 -07:00

update color in function

This commit is contained in:
eeeXun 2022-10-23 21:44:07 +08:00
parent 98fbf5b91c
commit 4d80c1f06a
3 changed files with 91 additions and 57 deletions

View File

@ -5,7 +5,7 @@ import (
) )
var ( var (
themes_name = []string{"Gruvbox", "Nord"} themesName = []string{"Gruvbox", "Nord"}
Transparent tcell.Color = tcell.ColorDefault Transparent tcell.Color = tcell.ColorDefault
Themes = map[string]map[string]tcell.Color{ Themes = map[string]map[string]tcell.Color{
"Gruvbox": { "Gruvbox": {
@ -64,6 +64,7 @@ func (w *Window) colorInit() {
w.src.pressColor = Themes[theme]["purple"] w.src.pressColor = Themes[theme]["purple"]
w.src.labelColor = Themes[theme]["yellow"] w.src.labelColor = Themes[theme]["yellow"]
w.dst.foregroundColor = Themes[theme]["fg"] w.dst.foregroundColor = Themes[theme]["fg"]
w.dst.selectedColor = Themes[theme]["gray"]
w.dst.borderColor = Themes[theme]["blue"] w.dst.borderColor = Themes[theme]["blue"]
w.dst.prefixColor = Themes[theme]["cyan"] w.dst.prefixColor = Themes[theme]["cyan"]
} }

View File

@ -38,7 +38,7 @@ func main() {
mainPage.AddPage("translatePage", translateWindow, true, true) mainPage.AddPage("translatePage", translateWindow, true, true)
mainPage.AddPage("langPage", langWindow, true, false) mainPage.AddPage("langPage", langWindow, true, false)
mainPage.AddPage("stylePage", styleWindow, true, true) mainPage.AddPage("stylePage", styleWindow, true, false)
if err := app.SetRoot(mainPage, true). if err := app.SetRoot(mainPage, true).
EnableMouse(true).Run(); err != nil { EnableMouse(true).Run(); err != nil {

143
ui.go
View File

@ -3,9 +3,10 @@ package main
import ( import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/rivo/tview" "github.com/rivo/tview"
"strconv"
) )
func updateBackground() { func updateBackgroundColor() {
// box // box
srcBox.SetBackgroundColor(window.src.backgroundColor) srcBox.SetBackgroundColor(window.src.backgroundColor)
srcBox.SetTextStyle(tcell.StyleDefault. srcBox.SetTextStyle(tcell.StyleDefault.
@ -44,6 +45,64 @@ func updateBackground() {
Foreground(window.src.prefixColor)) Foreground(window.src.prefixColor))
} }
func updateBorderColor() {
// box
srcBox.SetBorderColor(window.src.borderColor).
SetTitleColor(window.src.borderColor)
dstBox.SetBorderColor(window.dst.borderColor).
SetTitleColor(window.dst.borderColor)
// dropdown
srcLangDropDown.SetBorderColor(window.src.borderColor).
SetTitleColor(window.src.borderColor)
dstLangDropDown.SetBorderColor(window.dst.borderColor).
SetTitleColor(window.dst.borderColor)
}
func updateNonConfigColor() {
// box
srcBox.SetSelectedStyle(tcell.StyleDefault.
Background(window.src.selectedColor).
Foreground(window.src.foregroundColor))
dstBox.SetTextColor(window.dst.foregroundColor)
// dropdown
srcLangDropDown.SetFieldBackgroundColor(window.src.selectedColor).
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
dstLangDropDown.SetFieldBackgroundColor(window.dst.selectedColor).
SetFieldTextColor(window.dst.foregroundColor).
SetPrefixTextColor(window.dst.prefixColor)
themeDropDown.SetLabelColor(window.src.labelColor)
themeDropDown.SetFieldBackgroundColor(window.src.selectedColor).
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
transparentDropDown.SetLabelColor(window.src.labelColor)
transparentDropDown.SetFieldBackgroundColor(window.src.selectedColor).
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
// button
langButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
styleButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
menuButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
}
func updateAllColor() {
updateBackgroundColor()
updateBorderColor()
updateNonConfigColor()
}
// update title and option // update title and option
func updateTitle() { func updateTitle() {
srcBox.SetTitle(translator.srcLang) srcBox.SetTitle(translator.srcLang)
@ -67,59 +126,22 @@ func attachButton() *tview.Flex {
func uiInit() { func uiInit() {
// box // box
srcBox.SetBorder(true). srcBox.SetBorder(true)
SetBorderColor(window.src.borderColor). dstBox.SetBorder(true)
SetTitleColor(window.src.borderColor)
srcBox.SetSelectedStyle(tcell.StyleDefault.
Background(window.src.selectedColor).
Foreground(window.src.foregroundColor))
dstBox.SetBorder(true).
SetBorderColor(window.dst.borderColor).
SetTitleColor(window.dst.borderColor)
dstBox.SetTextColor(window.dst.foregroundColor)
// dropdown // dropdown
srcLangDropDown.SetBorder(true)
srcLangDropDown.SetOptions(Lang, nil) srcLangDropDown.SetOptions(Lang, nil)
srcLangDropDown.SetFieldBackgroundColor(window.src.selectedColor). dstLangDropDown.SetBorder(true)
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
srcLangDropDown.SetBorder(true).
SetBorderColor(window.src.borderColor).
SetTitleColor(window.src.borderColor)
dstLangDropDown.SetOptions(Lang, nil) dstLangDropDown.SetOptions(Lang, nil)
dstLangDropDown.SetFieldBackgroundColor(window.src.selectedColor). themeDropDown.SetLabel("Theme: ").
SetFieldTextColor(window.src.foregroundColor). SetOptions(themesName, nil).
SetPrefixTextColor(window.src.prefixColor) SetCurrentOption(IndexOf(theme, themesName))
dstLangDropDown.SetBorder(true). transparentDropDown.SetLabel("Transparent: ").
SetBorderColor(window.dst.borderColor). SetOptions([]string{"true", "false"}, nil).
SetTitleColor(window.dst.borderColor) SetCurrentOption(
themeDropDown.SetOptions(themes_name, nil). IndexOf(strconv.FormatBool(transparent),
SetLabel("Theme: ").SetLabelColor(window.src.labelColor) []string{"true", "false"}))
themeDropDown.SetFieldBackgroundColor(window.src.selectedColor).
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
transparentDropDown.SetOptions([]string{"true", "false"}, nil).
SetLabel("Transparent: ").SetLabelColor(window.src.labelColor)
transparentDropDown.SetFieldBackgroundColor(window.src.selectedColor).
SetFieldTextColor(window.src.foregroundColor).
SetPrefixTextColor(window.src.prefixColor)
// button
langButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
styleButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
menuButton.SetLabelColor(window.src.foregroundColor).
SetBackgroundColorActivated(window.src.pressColor).
SetLabelColorActivated(window.src.foregroundColor).
SetBackgroundColor(window.src.selectedColor)
updateBackground()
updateTitle()
// window // window
translateWindow.SetDirection(tview.FlexColumn). translateWindow.SetDirection(tview.FlexColumn).
@ -145,13 +167,24 @@ func uiInit() {
AddItem(attachButton(), 1, 1, true). AddItem(attachButton(), 1, 1, true).
AddItem(nil, 0, 1, false) AddItem(nil, 0, 1, false)
updateAllColor()
updateTitle()
// handler // handler
mainPage.SetInputCapture(pagesHandler) mainPage.SetInputCapture(pagesHandler)
translateWindow.SetInputCapture(translatePageHandler) translateWindow.SetInputCapture(translatePageHandler)
srcLangDropDown.SetDoneFunc(srcDropDownHandler). srcLangDropDown.SetDoneFunc(srcDropDownHandler).
SetSelectedFunc(srcSelected) SetSelectedFunc(srcLangSelected)
dstLangDropDown.SetDoneFunc(dstDropDownHandler). dstLangDropDown.SetDoneFunc(dstDropDownHandler).
SetSelectedFunc(dstSelected) SetSelectedFunc(dstLangSelected)
langButton.SetSelectedFunc(func() {
mainPage.HidePage("stylePage")
mainPage.ShowPage("langPage")
})
styleButton.SetSelectedFunc(func() {
mainPage.HidePage("langPage")
mainPage.ShowPage("stylePage")
})
} }
func pagesHandler(event *tcell.EventKey) *tcell.EventKey { func pagesHandler(event *tcell.EventKey) *tcell.EventKey {
@ -166,7 +199,7 @@ func pagesHandler(event *tcell.EventKey) *tcell.EventKey {
window.src.backgroundColor = Transparent window.src.backgroundColor = Transparent
window.dst.backgroundColor = Transparent window.dst.backgroundColor = Transparent
} }
updateBackground() updateBackgroundColor()
transparent = !transparent transparent = !transparent
} }
@ -240,13 +273,13 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
return event return event
} }
func srcSelected(text string, index int) { func srcLangSelected(text string, index int) {
translator.srcLang = text translator.srcLang = text
srcBox.SetTitle(text) srcBox.SetTitle(text)
srcLangDropDown.SetTitle(text) srcLangDropDown.SetTitle(text)
} }
func dstSelected(text string, index int) { func dstLangSelected(text string, index int) {
translator.dstLang = text translator.dstLang = text
dstBox.SetTitle(text) dstBox.SetTitle(text)
dstLangDropDown.SetTitle(text) dstLangDropDown.SetTitle(text)