本文整理汇总了Golang中github.com/lxn/walk.Action类的典型用法代码示例。如果您正苦于以下问题:Golang Action类的具体用法?Golang Action怎么用?Golang Action使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Action类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var tool *walk.Action
var menutool *walk.Menu
var mw *walk.MainWindow
mw.SetMaximizeBox(false)
mw.SetFixedSize(true)
mw, _ = walk.NewMainWindowCody()
mw.SetTitle("测试")
mw.SetSize(walk.Size{300, 200})
menutool, _ = walk.NewMenu()
tool = walk.NewMenuAction(menutool)
tool.SetText("文件")
open := walk.NewAction()
open.SetText("打开")
exit := walk.NewAction()
exit.SetText("退出")
menutool.Actions().Add(open)
menutool.Actions().Add(exit)
men2, _ := walk.NewMenu()
too2 := walk.NewMenuAction(men2)
too2.SetText("工具")
mw.Menu().Actions().Add(tool)
mw.Menu().Actions().Add(too2)
mw.Show()
mw.Run()
}
示例2: setActionImage
func setActionImage(action *walk.Action, image interface{}) (err error) {
var img *walk.Bitmap
switch image := image.(type) {
case nil:
return nil
case *walk.Bitmap:
img = image
case string:
if img, err = walk.NewBitmapFromFile(image); err != nil {
return
}
default:
return errors.New("invalid type for Image")
}
return action.SetImage(img)
}
示例3: setActionImage
func setActionImage(action *walk.Action, image interface{}) (err error) {
var img walk.Image
switch image := image.(type) {
case nil:
return nil
case *walk.Bitmap:
img = image
case string:
if img, err = imageFromFile(image); err != nil {
return
}
}
if bmp, ok := img.(*walk.Bitmap); ok {
return action.SetImage(bmp)
}
return errors.New("invalid type for Image")
}
示例4: createAction
func (m Menu) createAction(builder *Builder, menu *walk.Menu) (*walk.Action, error) {
subMenu, err := walk.NewMenu()
if err != nil {
return nil, err
}
var action *walk.Action
if menu == nil {
action = walk.NewMenuAction(subMenu)
} else if action, err = menu.Actions().AddMenu(subMenu); err != nil {
return nil, err
}
if err := action.SetText(m.Text); err != nil {
return nil, err
}
if err := setActionImage(action, m.Image); err != nil {
return nil, err
}
for _, item := range m.Items {
if _, err := item.createAction(builder, subMenu); err != nil {
return nil, err
}
}
if m.OnTriggered != nil {
action.Triggered().Attach(m.OnTriggered)
}
if m.AssignActionTo != nil {
*m.AssignActionTo = action
}
if m.AssignTo != nil {
*m.AssignTo = subMenu
}
return action, nil
}
示例5: initAction
func (a Action) initAction(wa *walk.Action) (*walk.Action, error) {
text := a.Text
if text == "" {
text = "-"
}
if err := wa.SetText(text); err != nil {
return nil, err
}
if err := wa.SetImage(a.Image); err != nil {
return nil, err
}
if a.OnTriggered != nil {
wa.Triggered().Attach(a.OnTriggered)
}
if a.AssignTo != nil {
*a.AssignTo = wa
}
return wa, nil
}