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
-
Xacto
- Posts: 26
- Joined: Thu Dec 15, 2016 1:34 am
Post
by Xacto » Wed Jan 11, 2017 4:26 am
I am trying to create a menubar with multiple choices (ex: Blue, Black,Red). When selected, it changes the color of a button on the stack. What I was wondering... how can I create a "check mark" next to the menu item that was just selected?
Here is what I have:
Code: Select all
on menuPick pItemName
switch pItemName
case "Black"
set the icon of button buttonFace to Blackicon.png
// NEED TO UNCHECK PREVIOUS SELECTION AND CHECK CURRENT SELECTION
break
case "Blue"
--code here
break
case "Red"
--- code
--code here
break
end switch
end menuPick
Thanks in advance!!!
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Wed Jan 11, 2017 1:25 pm
Hi Xacto,
I always use btns for menus with this script to display a checkmark.
You may also have a look to menuhistory.
Code: Select all
on menuPick pItemName
DoMyCheckMark the label of the target
switch pItemName
case "Black"
break
case "Blue"
--code here
break
end switch
set the label of the target to pItemName
end menuPick
on DoMyCheckMark pLabel
if pLabel = empty then exit DoMyCheckMark
put the text of the target into tPrevText
replace "!c" with empty in tPrevText
replace "!c" with empty in pItemName
put lineoffset(pLabel & cr, tPrevText & cr) into tMH
put "!c" before line tMH of tPrevText
set the text of the target to tPrevText
end DoMyCheckMark
Best regards
Jean-Marc
Last edited by
jmburnod on Thu Jan 12, 2017 7:29 am, edited 1 time in total.
https://alternatic.ch
-
Xacto
- Posts: 26
- Joined: Thu Dec 15, 2016 1:34 am
Post
by Xacto » Thu Jan 12, 2017 2:43 am
Thank you so much... it is "somewhat" working. I have to select the menu item TWICE before the checkmark shows.
In your code you have:
Code: Select all
if pLabel = empty then exit FaitCheckMark
I get an error on this line. In order to make it run, I changed it to this:
Code: Select all
if pLabel = empty then exit DoMyCheckMark
Is the reason it does not always work?
Thanks again
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Thu Jan 12, 2017 5:44 pm
I have to select the menu item TWICE before the checkmark shows.
Ni idea. Do you use a btn menu ?
I get an error on this line
Yes, I changed it
https://alternatic.ch
-
Xacto
- Posts: 26
- Joined: Thu Dec 15, 2016 1:34 am
Post
by Xacto » Fri Jan 13, 2017 3:50 am
No, not a button - It is the system menubar item. Created with the "Menu Builder"
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9660
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Fri Jan 13, 2017 3:52 am
All menus in the menubar are formed from a group of buttons with certain properties set. The menu builder just helps that process along.
This may not be pertinent to the problem.
Craig
-
Xacto
- Posts: 26
- Joined: Thu Dec 15, 2016 1:34 am
Post
by Xacto » Fri Jan 13, 2017 5:15 am
Here is an example of what is happening. (see attachment)
The menu selects the color correctly, however you have to select the menu two times before it puts a check mark next to the menu item.
-
Attachments
-
- MenuExample.livecode.zip
- (2.28 KiB) Downloaded 111 times
-
jmburnod
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
-
Contact:
Post
by jmburnod » Sat Jan 14, 2017 5:06 pm
I played a bit with your stack and I discover that The target of a btn of a menu group return the name of group and not the name of the clicked btn.
Here is a stack with menu and popup btn with same behavior.
They use the same script (in stack)
Jean-Marc
-
Attachments
-
- PopuUpCheckMark001.livecode.zip
- (2.75 KiB) Downloaded 140 times
https://alternatic.ch
-
MaxV
- Posts: 1579
- Joined: Tue May 28, 2013 2:20 pm
- Location: Italy
-
Contact:
Post
by MaxV » Mon Jan 16, 2017 2:34 pm
Wow,
I tried intead of "!c" on my linux machine these:
and I got these: »
It can be handy.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
Xacto
- Posts: 26
- Joined: Thu Dec 15, 2016 1:34 am
Post
by Xacto » Wed Jan 18, 2017 2:18 am