mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-19 09:10:42 -07:00
UI prototype
This commit is contained in:
parent
d31dd1346b
commit
bcf68157f4
28
main.go
28
main.go
@ -1,29 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// "fmt"
|
||||
// "github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
var (
|
||||
// Translate
|
||||
translator Translator
|
||||
// TUI
|
||||
// UI
|
||||
app = tview.NewApplication()
|
||||
src_box = tview.NewInputField()
|
||||
src_box = tview.NewTextArea()
|
||||
dest_box = tview.NewTextView()
|
||||
window Window
|
||||
)
|
||||
|
||||
func main() {
|
||||
translator.src_lang = "English"
|
||||
translator.dest_lang = "Chinese (Traditional)"
|
||||
result, _ := translator.Translate("Hello world\nApple\nbumper")
|
||||
fmt.Println(result)
|
||||
// if err := app.SetRoot(
|
||||
// tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
// AddItem(src_box, 0, 1, true).
|
||||
// AddItem(dest_box, 0, 6, false),
|
||||
// true).EnableMouse(true).Run(); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// result, _ := translator.Translate("Hello world\nApple\nbumper")
|
||||
// fmt.Println(result)
|
||||
window.color_init()
|
||||
ui_init()
|
||||
if err := app.SetRoot(
|
||||
tview.NewFlex().SetDirection(tview.FlexColumn).
|
||||
AddItem(src_box, 0, 1, true).
|
||||
AddItem(dest_box, 0, 1, false),
|
||||
true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
43
ui.go
Normal file
43
ui.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
// "github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type Colors struct {
|
||||
background_color tcell.Color
|
||||
foreground_color tcell.Color
|
||||
border_color tcell.Color
|
||||
}
|
||||
|
||||
type Window struct {
|
||||
src Colors
|
||||
dest Colors
|
||||
}
|
||||
|
||||
func (w *Window) color_init() {
|
||||
w.src.background_color = tcell.ColorDefault
|
||||
w.src.border_color = tcell.NewHexColor(0xFBF1C7)
|
||||
w.src.foreground_color = tcell.NewHexColor(0xFBF1C7)
|
||||
w.dest.background_color = tcell.ColorDefault
|
||||
w.dest.border_color = tcell.NewHexColor(0xFBF1C7)
|
||||
w.dest.foreground_color = tcell.NewHexColor(0xFBF1C7)
|
||||
}
|
||||
|
||||
func ui_init() {
|
||||
src_box.SetBorder(true).
|
||||
SetTitle(translator.src_lang).
|
||||
SetBorderColor(window.src.border_color).
|
||||
SetTitleColor(window.src.border_color)
|
||||
src_box.SetBackgroundColor(window.src.background_color)
|
||||
src_box.SetTextStyle(tcell.StyleDefault.
|
||||
Background(window.src.background_color).
|
||||
Foreground(window.src.foreground_color))
|
||||
|
||||
dest_box.SetBorder(true).
|
||||
SetTitle(translator.dest_lang).
|
||||
SetBorderColor(window.dest.border_color).
|
||||
SetTitleColor(window.dest.border_color)
|
||||
dest_box.SetBackgroundColor(window.dest.background_color)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user