News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
callback for an individual menu entry
Author Message
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
callback for an individual menu entry

While fltk has the ability to define a callback function for every menu entry, I cannot get it to work under murgaLua. Is there a working example somewhere or is this a bug^H^H^H feature?

09-19-2007 12:55 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: callback for an individual menu entry

I haven't come to fully understand the menu classes, and haven't succeeded in setting a callback to a particular menu item. However, you can check for the menu item within the menu's callback and perform an action according to the result:

Code:
my_menu=fltk:Fl_Menu_Bar(0,0,200,30)
my_menu:add("File/Item 1")
my_menu:add("File/Item 2")
my_menu:add("File/Item 3")

my_menu:callback( -- a callback for the whole menu
function()
  if my_menu:text()=="Item 2" then
    print("this is Item 2")
  end
end
)

This post was last modified: 09-19-2007 01:34 AM by mikshaw.

09-19-2007 01:33 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #3
RE: callback for an individual menu entry

Defining a callback for a menu-item isn't implemented - Won't work currently.

mikshaw's method works, however sometimes you want menu items with the same name ...

Take a look at "sqlTool.lua" for a solution to this problem along with a few other examples of menu usage.

Cheers
JohnM

09-19-2007 01:40 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: callback for an individual menu entry

Quote:
sometimes you want menu items with the same name ...
Take a look at "sqlTool.lua" for a solution to this problem

It seems that you are using the menu item index. This works for duplicate labels but can be nearly unusable if you have dynamically created menus, or complicated if you decide to change the order of your menu items. I think either method has its benefits and drawbacks.

I was looking into something that uses the find_item() function to allow this pointer to be used, but unfortunately my_pointer:label() returns the same string as my_menu:text(), meaning that neither one uses a full pathname to the item. maybe item_pathname() could be used, but so far it hasn't shown itself to provide very helpful information.

09-19-2007 05:08 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #5
RE: callback for an individual menu entry

JohnMurga Wrote:
Defining a callback for a menu-item isn't implemented - Won't work currently.


Of course this is just a matter of taste, but I think in some cases a individual callback is preferable to a big block of if, switching through all menu items in one single callback.

JohnMurga Wrote:
mikshaw's method works, however sometimes you want menu items with the same name ...

Take a look at "sqlTool.lua" for a solution to this problem along with a few other examples of menu usage.

Cheers
JohnM


Shouldn't "item_pathname" take care of this case, when you have multiple submenus with the same item names? Unfortunately it looks like item_pathname also does (currently) not work.

Juergen

09-19-2007 06:32 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: callback for an individual menu entry

From my little bit of poking at it, it looks like item_pathname is partially implemented. It will return 0 or -2 depending on how it's used (I haven't seen it return -1), but I couldn't get it to return a string.

09-19-2007 09:49 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #7
RE: callback for an individual menu entry

item_pathname and menu item callbacks are sort of on my to-do list ...

But WAY, WAY down ... :-(

What's more I haven't had much time to do the stuff I do have planned for the 0.6 release.

Cheers
JohnM

09-19-2007 06:06 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #8
RE: callback for an individual menu entry

Another Good Thing about development of personal projects: deadlines mean only as much as you want them to =o)

It seems as though there are many separate pieces involved in putting together complete menu support. Considering that and the fact that menus are already in a mostly useable state, I'm not surprised these are low priorities.

09-19-2007 11:34 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: