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:
parent
33423da3ca
commit
4b6561d3dd
2
color.go
2
color.go
@ -48,8 +48,6 @@ type Window struct {
|
||||
}
|
||||
|
||||
func (w *Window) color_init() {
|
||||
theme := "Gruvbox"
|
||||
transparent := true
|
||||
if transparent {
|
||||
w.src.background_color = Transparent
|
||||
w.dst.background_color = Transparent
|
||||
|
3
main.go
3
main.go
@ -17,6 +17,9 @@ var (
|
||||
lang_page = tview.NewFlex()
|
||||
pages = tview.NewPages()
|
||||
window Window
|
||||
// config
|
||||
theme string = "Gruvbox"
|
||||
transparent bool = true
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
144
ui.go
144
ui.go
@ -4,69 +4,99 @@ import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
func ui_init() {
|
||||
// page
|
||||
translate_page.SetInputCapture(TranslatePageHandler)
|
||||
|
||||
func update_background() {
|
||||
// box
|
||||
src_box.SetBorder(true).
|
||||
SetTitle(translator.src_lang).
|
||||
SetBorderColor(window.src.border_color).
|
||||
SetTitleColor(window.src.border_color).
|
||||
SetBackgroundColor(window.src.background_color)
|
||||
src_box.SetBackgroundColor(window.src.background_color)
|
||||
src_box.SetTextStyle(tcell.StyleDefault.
|
||||
Background(window.src.background_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).
|
||||
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)
|
||||
dst_box.SetBackgroundColor(window.dst.background_color)
|
||||
|
||||
// dropdown
|
||||
src_dropdown.SetOptions(Lang, nil).
|
||||
SetCurrentOption(IndexOf(translator.src_lang, Lang))
|
||||
src_dropdown.SetBackgroundColor(window.src.background_color)
|
||||
src_dropdown.SetListStyles(tcell.StyleDefault.
|
||||
Background(window.src.background_color).
|
||||
Foreground(window.src.foreground_color),
|
||||
tcell.StyleDefault.
|
||||
Background(window.src.selected_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).
|
||||
SetCurrentOption(IndexOf(translator.dst_lang, Lang))
|
||||
dst_dropdown.SetBackgroundColor(window.dst.background_color)
|
||||
// dst_dropdown.SetFieldBackgroundColor(window.src.selected_color)
|
||||
dst_dropdown.SetListStyles(tcell.StyleDefault.
|
||||
Background(window.src.background_color).
|
||||
Foreground(window.src.foreground_color),
|
||||
tcell.StyleDefault.
|
||||
Background(window.src.selected_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).
|
||||
SetFieldTextColor(window.src.foreground_color).
|
||||
SetPrefixTextColor(window.dst.prefix_color)
|
||||
dst_dropdown.SetBorder(true).
|
||||
SetTitle(translator.dst_lang).
|
||||
SetBackgroundColor(window.dst.background_color).
|
||||
SetBorderColor(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 {
|
||||
@ -75,6 +105,21 @@ func TranslatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch key {
|
||||
case tcell.KeyEsc:
|
||||
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
|
||||
@ -109,30 +154,3 @@ func DstDropDownHandler(key tcell.Key) {
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user