本文整理匯總了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
}