代码拉取完成,页面将自动刷新
package main
import (
"github.com/conformal/gotk3/gtk"
)
// Setup the Window.
func setupWindow() *gtk.Window {
w, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
w.Connect("destroy", gtk.MainQuit)
w.SetDefaultSize(500, 300)
w.SetPosition(gtk.WIN_POS_CENTER)
w.SetTitle("TextView properties example")
return w
}
// Setup the TextView, put it in a ScrolledWindow, and add both to box.
func setupTextView(box *gtk.Box) *gtk.TextView {
sw, _ := gtk.ScrolledWindowNew(nil, nil)
tv, _ := gtk.TextViewNew()
sw.Add(tv)
box.PackStart(sw, true, true, 0)
return tv
}
type BoolProperty struct {
Name string
Get func() bool
Set func(bool)
}
func setupPropertyCheckboxes(tv *gtk.TextView, outer *gtk.Box, props []*BoolProperty) {
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
for _, prop := range props {
chk, _ := gtk.CheckButtonNewWithLabel(prop.Name)
// initialize the checkbox with the property's current value
chk.SetActive(prop.Get())
p := prop // w/o this all the checkboxes will toggle the last property in props
chk.Connect("toggled", func() {
p.Set(chk.GetActive())
})
box.PackStart(chk, true, true, 0)
}
outer.PackStart(box, false, false, 0)
}
func main() {
gtk.Init(nil)
win := setupWindow()
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
win.Add(box)
tv := setupTextView(box)
props := []*BoolProperty{
&BoolProperty{"cursor visible", (*tv).GetCursorVisible, (*tv).SetCursorVisible},
&BoolProperty{"editable", (*tv).GetEditable, (*tv).SetEditable},
&BoolProperty{"overwrite", (*tv).GetOverwrite, (*tv).SetOverwrite},
&BoolProperty{"accepts tab", (*tv).GetAcceptsTab, (*tv).SetAcceptsTab},
}
setupPropertyCheckboxes(tv, box, props)
win.ShowAll()
gtk.Main()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。