menu builder help please

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

menu builder help please

Post by jalz » Thu Mar 26, 2015 8:44 pm

Hi Guys,

I'm experimenting with the menu builder for my app. So far it looks straightforward even though I can't find much documentation on the tool. I've built a format menu with the following structure

Fonts
Typeface
Size
10
11
12
Style
Bold
Italic
Underline

My question is how do I get Typeface to display all the fonts on my system? I found some sample code and managed to populate an option menu called "cb_font" with all the fonts but can't get the top menu where I have the word typeface replaced with all the fonts. I'm calling this script on the open card handler as I read its best practice to load this menu up on startup.

createFontMenu
--Insert script for Font menu item here
get the fontNames ## list of installed fonts
sort lines of it
put it into button "Typeface"
--set the text of button "cb_font" to it
end createFontMenu

Many thanks as always
Jalz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: menu builder help please

Post by dunbarx » Thu Mar 26, 2015 11:04 pm

Hi.

The menuBuilder seems like a great tool, and it is. But it also is haunted.

Buttons are containers, and there is nothing special, particularly, about those buttons, except for certain properties> It is a stack property (the menuBar) that makes these grouped buttons act like a menu. You likely already know this.

Anyway, what you have started out to do should work fine. What are you seeing?

Craig Newman

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: menu builder help please

Post by jalz » Thu Mar 26, 2015 11:34 pm

Hi Craig,

Thanks for your explanation regarding menus, buttons, containers. Yes I read this in some of the other posts and articles. I've got scripts executing from my format menu, but I'm still confused on how to populate a specific menu item. The menu I am trying to populate is Format. The menu Item is Font and a submenu called Typeface (which is what I want replaced with the fonts from the system).

The code I am using seems to be erroring with a "no such object" error on line - put it into button "Typeface"

I've tried putting it in "Font|Typeface" and "Font" for the button name to no avail.

I've added a sample file of the type of structure I am using

Jalz
Attachments
menutest.livecode.zip
(3.17 KiB) Downloaded 208 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: menu builder help please

Post by dunbarx » Fri Mar 27, 2015 5:12 am

I think I know what you are asking.

In a new stack, use the menu builder to create a new menu. Add another menu and name it "test". Make a new field and place this into it:

Code: Select all

Choice1/|1
	Choice2/|2
	choice2a/|3
choice3/|4
Choice4/|5
	Choice5/|6
Choice6/|7
In the message box:

Code: Select all

 put fld 1 into btn "test"
I believe that the code section will not copy correctly. Each "space" in the indented lines is in fact a tab. You may need to reconstruct this.

If you have trouble with the formatting, take this:

Code: Select all

Choice1/|1
XChoice2/|2
Xchoice2a/|3
choice3/|4
Choice4/|5
XChoice5/|6
Choice6/|7
Replace "X" with tab in the above text, and use that. Experiment with the tags that create submenus. Try to make three-level submenus.

Craig

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: menu builder help please

Post by jalz » Fri Mar 27, 2015 7:31 pm

Thank you Craig,

Your instructions on new stack work bang on when I have a menu item (e.g. test). I'm trying to populate a submenu called "font", so I think all I need to get right is the button name of the submenu. How does the menu allocate names to containers that are 3 levels down. hope that makes sense?

All the best
Jalz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: menu builder help please

Post by dunbarx » Fri Mar 27, 2015 8:03 pm

Hi.
all I need to get right is the button name of the submenu.
There is only one button. It is the contents of that button, set up with the tab character and the tags "/" and "|" that create the hierarchy of menuItems and subMenuItems. I will still leave this to you as homework. Play with the "test" sample.

But in any case, to load the fonts, say, you should be able to pack the "item" of interest with that list, by careful parsing of the example.

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: menu builder help please

Post by kaveh1000 » Wed Nov 28, 2018 9:41 pm

Hi Craig

Great to see a trick to produce hierarchical menus. I get the multi-level menus but I am afraid I have failed the "homework" test and can't work out:
  • what the / and | signify
  • How to get the menu item that I want in the selectedtext of the button – I am getting "Option/|1" etc as the selectedText
  • I can see hierarchy in a Pulldown menu button but not in an Option menu
Any hints or pointers appreciated.

Kaveh
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: menu builder help please

Post by dunbarx » Thu Nov 29, 2018 4:20 am

Hi.

There are differences between the four types of "menu" buttons, and not all of them support subMenus. The most straightforward is the pullDown. I would start there. Name it "B1"

Place the following into the text of btn "B1":

Code: Select all

Choice1/|1
	Choice2/|2
	Choice2a/|3
Choice3/|4
Choice4/|5
	Choice5/|6
Choice6/|7
And then in the button script:

Code: Select all

on menuPick pItemName
   answer pItemName
end menuPick
The contents of the button, which can be seen to be numbered, line by line, are denoted by the number after the "|". It is this value that matters.

Now select something from the pulldown. Note that in a hierarchal menuItem, you must select a submenu item, whereas in an "ordinary" menuItem (like "choice3") you can simply select the menuItem.

What you get back needs processing. If you select the subMenu "choice2a", you will get back "1|3". The "1" is the main menuItem, and the "3" is the line containing your actual choice. So you can, again in the button script:

Code: Select all

on menuPick pItemName
   set the itemDel to "|"
   put item 2 of pItemName into tLine
     set the itemDel to "/"
   answer item 1 of line tLine of me
end menuPick
Now this all can be simplified, which is another way of saying I am not sure I know what I am talking about. In that same button, load this from the message box:

Code: Select all

put "AA" & return & tab &  "BB" & return & "CC" & return & "DD" into btn "btn1"
and this into its script:

Code: Select all

on menuPick PItemName
   answer pItemName
end menuPick
You get the main menuItem, a "|" and the subMenuItem. You can extract the submenuItem as before.

Now add an extra tab:

Code: Select all

  put "AA" & return & tab & "BB" & tab & "XX" & return & "CC" & return & "DD" into btn "btn1"
You do not get a second submenu to the menu "AA". You need those tags as set up as in the first example.

I think.

Experiment. That is what I do, and you also might look into the user guide, page 187 or so.

Craig

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: menu builder help please

Post by kaveh1000 » Thu Nov 29, 2018 3:32 pm

Thanks for taking the time, Craig. I am working on another part but will come back and use your excellent text here and report back. :-)
Kaveh

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”