v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 08:10:22 -07:00

add toggle transparent

This commit is contained in:
eeeXun 2022-10-21 15:33:14 +08:00
parent 33423da3ca
commit 4b6561d3dd
3 changed files with 84 additions and 65 deletions

View File

@ -48,8 +48,6 @@ type Window struct {
} }
func (w *Window) color_init() { func (w *Window) color_init() {
theme := "Gruvbox"
transparent := true
if transparent { if transparent {
w.src.background_color = Transparent w.src.background_color = Transparent
w.dst.background_color = Transparent w.dst.background_color = Transparent

View File

@ -17,6 +17,9 @@ var (
lang_page = tview.NewFlex() lang_page = tview.NewFlex()
pages = tview.NewPages() pages = tview.NewPages()
window Window window Window
// config
theme string = "Gruvbox"
transparent bool = true
) )
func main() { func main() {

144
ui.go
View File

@ -4,69 +4,99 @@ import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
) )
func ui_init() { func update_background() {
// page
translate_page.SetInputCapture(TranslatePageHandler)
// box // box
src_box.SetBorder(true). src_box.SetBackgroundColor(window.src.background_color)
SetTitle(translator.src_lang).
SetBorderColor(window.src.border_color).
SetTitleColor(window.src.border_color).
SetBackgroundColor(window.src.background_color)
src_box.SetTextStyle(tcell.StyleDefault. src_box.SetTextStyle(tcell.StyleDefault.
Background(window.src.background_color). Background(window.src.background_color).
Foreground(window.src.foreground_color)) Foreground(window.src.foreground_color))
src_box.SetSelectedStyle(tcell.StyleDefault.
Background(window.src.selected_color).
Foreground(window.src.foreground_color))
src_box.SetInputCapture(SrcBoxHandler)
dst_box.SetBorder(true). dst_box.SetBackgroundColor(window.dst.background_color)
SetTitle(translator.dst_lang).
SetBorderColor(window.dst.border_color).
SetTitleColor(window.dst.border_color).
SetBackgroundColor(window.dst.background_color)
dst_box.SetTextColor(window.dst.foreground_color)
// dropdown // dropdown
src_dropdown.SetOptions(Lang, nil). src_dropdown.SetBackgroundColor(window.src.background_color)
SetCurrentOption(IndexOf(translator.src_lang, Lang))
src_dropdown.SetListStyles(tcell.StyleDefault. src_dropdown.SetListStyles(tcell.StyleDefault.
Background(window.src.background_color). Background(window.src.background_color).
Foreground(window.src.foreground_color), Foreground(window.src.foreground_color),
tcell.StyleDefault. tcell.StyleDefault.
Background(window.src.selected_color). Background(window.src.selected_color).
Foreground(window.src.prefix_color)) Foreground(window.src.prefix_color))
src_dropdown.SetFieldBackgroundColor(window.src.selected_color).
SetFieldTextColor(window.src.foreground_color).
SetPrefixTextColor(window.dst.prefix_color)
src_dropdown.SetBorder(true).
SetTitle(translator.src_lang).
SetBackgroundColor(window.src.background_color).
SetBorderColor(window.src.border_color).
SetTitleColor(window.src.border_color)
src_dropdown.SetSelectedFunc(SrcSelected)
src_dropdown.SetDoneFunc(SrcDropDownHandler)
dst_dropdown.SetOptions(Lang, nil). dst_dropdown.SetBackgroundColor(window.dst.background_color)
SetCurrentOption(IndexOf(translator.dst_lang, Lang)) // dst_dropdown.SetFieldBackgroundColor(window.src.selected_color)
dst_dropdown.SetListStyles(tcell.StyleDefault. dst_dropdown.SetListStyles(tcell.StyleDefault.
Background(window.src.background_color). Background(window.src.background_color).
Foreground(window.src.foreground_color), Foreground(window.src.foreground_color),
tcell.StyleDefault. tcell.StyleDefault.
Background(window.src.selected_color). Background(window.src.selected_color).
Foreground(window.src.prefix_color)) Foreground(window.src.prefix_color))
}
func ui_init() {
update_background()
// handler
pages.SetInputCapture(PagesHandler)
translate_page.SetInputCapture(TranslatePageHandler)
src_dropdown.SetDoneFunc(SrcDropDownHandler)
src_dropdown.SetSelectedFunc(SrcSelected)
dst_dropdown.SetDoneFunc(DstDropDownHandler)
dst_dropdown.SetSelectedFunc(DstSelected)
// box
src_box.SetBorder(true).
SetTitle(translator.src_lang).
SetBorderColor(window.src.border_color).
SetTitleColor(window.src.border_color)
src_box.SetSelectedStyle(tcell.StyleDefault.
Background(window.src.selected_color).
Foreground(window.src.foreground_color))
dst_box.SetBorder(true).
SetTitle(translator.dst_lang).
SetBorderColor(window.dst.border_color).
SetTitleColor(window.dst.border_color)
dst_box.SetTextColor(window.dst.foreground_color)
// dropdown
src_dropdown.SetOptions(Lang, nil).
SetCurrentOption(IndexOf(translator.src_lang, Lang))
src_dropdown.SetFieldBackgroundColor(window.src.selected_color).
SetFieldTextColor(window.src.foreground_color).
SetPrefixTextColor(window.dst.prefix_color)
src_dropdown.SetBorder(true).
SetTitle(translator.src_lang).
SetBorderColor(window.src.border_color).
SetTitleColor(window.src.border_color)
dst_dropdown.SetOptions(Lang, nil).
SetCurrentOption(IndexOf(translator.dst_lang, Lang))
dst_dropdown.SetFieldBackgroundColor(window.src.selected_color). dst_dropdown.SetFieldBackgroundColor(window.src.selected_color).
SetFieldTextColor(window.src.foreground_color). SetFieldTextColor(window.src.foreground_color).
SetPrefixTextColor(window.dst.prefix_color) SetPrefixTextColor(window.dst.prefix_color)
dst_dropdown.SetBorder(true). dst_dropdown.SetBorder(true).
SetTitle(translator.dst_lang). SetTitle(translator.dst_lang).
SetBackgroundColor(window.dst.background_color).
SetBorderColor(window.dst.border_color). SetBorderColor(window.dst.border_color).
SetTitleColor(window.dst.border_color) SetTitleColor(window.dst.border_color)
dst_dropdown.SetSelectedFunc(DstSelected) }
dst_dropdown.SetDoneFunc(DstDropDownHandler)
func PagesHandler(event *tcell.EventKey) *tcell.EventKey {
key := event.Key()
switch key {
case tcell.KeyCtrlT:
if transparent {
window.src.background_color = Themes[theme]["bg"]
window.dst.background_color = Themes[theme]["bg"]
} else {
window.src.background_color = Transparent
window.dst.background_color = Transparent
}
update_background()
transparent = !transparent
}
return event
} }
func TranslatePageHandler(event *tcell.EventKey) *tcell.EventKey { func TranslatePageHandler(event *tcell.EventKey) *tcell.EventKey {
@ -75,6 +105,21 @@ func TranslatePageHandler(event *tcell.EventKey) *tcell.EventKey {
switch key { switch key {
case tcell.KeyEsc: case tcell.KeyEsc:
pages.ShowPage("lang_page") pages.ShowPage("lang_page")
case tcell.KeyCtrlJ:
result, err := translator.Translate(src_box.GetText())
if err != nil {
dst_box.SetText(err.Error())
} else {
dst_box.SetText(result)
}
case tcell.KeyCtrlQ:
src_box.SetText("", true)
case tcell.KeyCtrlN:
translator.PlaySound(translator.src_lang, src_box.GetText())
case tcell.KeyCtrlP:
translator.PlaySound(translator.dst_lang, dst_box.GetText(false))
case tcell.KeyCtrlS:
dst_box.SetText("SSS")
} }
return event return event
@ -109,30 +154,3 @@ func DstDropDownHandler(key tcell.Key) {
pages.HidePage("lang_page") pages.HidePage("lang_page")
} }
} }
func SrcBoxHandler(event *tcell.EventKey) *tcell.EventKey {
key := event.Key()
// panic(event.Name())
switch key {
case tcell.KeyCtrlJ:
result, err := translator.Translate(src_box.GetText())
if err != nil {
dst_box.SetText(err.Error())
} else {
dst_box.SetText(result)
}
case tcell.KeyCtrlQ:
src_box.SetText("", true)
case tcell.KeyCtrlN:
translator.PlaySound(translator.src_lang, src_box.GetText())
case tcell.KeyCtrlP:
translator.PlaySound(translator.dst_lang, dst_box.GetText(false))
case tcell.KeyCtrlT:
dst_box.SetText("TTT")
case tcell.KeyCtrlS:
dst_box.SetText("SSS")
}
return event
}