ChrisS85 / CGUI

An object-oriented GUI library for AutoHotkey
22 stars 19 forks source link

Icons of menuItems #43

Closed hoppfrosch closed 12 years ago

hoppfrosch commented 12 years ago

As you stated here in AHK-Forum setting of icons of menuItems does not work as expected and is obviously an error:

mnu := New CMenu("mnu")
mnu.AddMenuItem("item", "cbItem")

; Don't  know whether this is correct syntax - but I tried a lot variants, and none worked
mnu.item.SetIcon("test.ico")   ; does not work
mnu.item.Icon := "test.ico"     ;does also not work
ChrisS85 commented 12 years ago

You access menu items by their index, not by their name. However, there was a bug in the SetIcon() function. I uploaded a fix and it should work now.

mnu[1].SetIcon("test.ico") mnu[1].Icon := "test.ico"

hoppfrosch commented 12 years ago

It's a pity that it only works with indices. I think its much more intuitive (in an object oriented sense) to use

Menu.Main.File.SetIcon("test.ico") instead of Menu[1][1].SetIcon("test.ico") esp. when you try to add some new menuitems and have to adapt all indices ....

BTW: It works with indices as expected/designed

hoppfrosch commented 12 years ago

One more question:

From your CGui_Examples\MenuExample.ahk:

Menu1 := new CMenu("Main")

;Adding a menu item
Menu1.AddMenuItem("hello", "test")

;Accessing a menu item and setting some of its properties
Menu1[1].Text := "Test"
Menu1[1].Checked := true
Menu1[1].Enabled := false

;Adding a submenu
Menu1.AddSubMenu("sub1", "Test")

Menu1[2].AddMenuItem("blup", "blup")
Menu1[2][1].SetIcon(A_AHKPath)    ; Setting MenuIcon for "blup"  - works as expected
Menu1[2].SetIcon(A_AHKPath)        ; ???? Setting MenuIcon for "sub1" -   Should this work ????

sub2 := New CMenu("sub2")
sub2.AddMenuItem("blah", "blah")
;Adding an existing menu as submenu
Menu1.AddSubMenu("sub2", sub2)

;Setting a menu's icon
sub2.Icon := A_AHKPath      ; Setting menu icon for "sub2"
sub2[1].Icon := A_AHKPath  ; Setting menu icon for "blah"
...

See the line with '????' - Is this expected to work? (I would expect ...) - What's the correct way to set menu icon for "sub1"?

ChrisS85 commented 12 years ago

True, but what about menu items with spaces or localization? If you think it's needed feel free to submit a patch ;)