继续寻找golang的gui库。今天看到了gogi。Github看起来人气不高,网上介绍也就很少,更新还算比较近。
简单看了看基础的HelloWorld
package main
import (
"github.com/goki/gi/gi"
"github.com/goki/gi/gimain"
)
func main() {
gimain.Main(func() {
mainrun()
})
}
func mainrun() {
width := 1024
height := 768
win := gi.NewMainWindow("gogi-basic", "基础窗口", width, height)
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
rlay := gi.AddNewLayout(mfr, "rowlay", gi.LayoutHoriz)
rlay.SetProp("text-align", "center")
gi.AddNewLabel(rlay, "label1", "This is test text")
edit1 := gi.AddNewTextField(rlay, "edit1")
button1 := gi.AddNewButton(rlay, "button1")
button2 := gi.AddNewButton(rlay, "button2")
slider1 := gi.AddNewSlider(rlay, "slider1")
spin1 := gi.AddNewSpinBox(rlay, "spin1")
edit1.SetText("Edit this text")
edit1.SetProp("min-width", "20em")
button1.Text = "Button 1"
button2.Text = "Button 2"
slider1.Dim = gi.X
slider1.SetProp("width", "20em")
slider1.SetValue(0.5)
spin1.SetValue(0.0)
// main menu
appnm := gi.AppName()
mmen := win.MainMenu
mmen.ConfigMenus([]string{appnm, "Edit", "Window"})
amen := win.MainMenu.ChildByName(appnm, 0).(*gi.Action)
amen.Menu = make(gi.Menu, 0, 10)
amen.Menu.AddAppMenu(win)
emen := win.MainMenu.ChildByName("Edit", 1).(*gi.Action)
emen.Menu = make(gi.Menu, 0, 10)
emen.Menu.AddCopyCutPaste(win)
win.SetCloseCleanFunc(func(w *gi.Window) {
go gi.Quit() // once main window is closed, quit
})
win.MainMenuUpdated()
vp.UpdateEndNoSig(updt)
win.StartEventLoop()
}
运行起来还是不错,可以很方便的修改样式和字体、大小等,显示中文也正常。
甚至支持Ctrl+、Ctrl-组合键实时改变字体大小,还是不错的。
比较郁闷的是不能输入中文,至少在我的Ubuntu输入法下。只能郁闷放弃。