Popup menu alternative (Looks decent on android etc.)
Posted: Thu Jan 14, 2016 3:59 pm
Needed a 'popup selector thing' for my current android project and after reminding myself of how the livecode versions looked I wrote a 'self-contained' alternative.
Add the following script to an "field" control and your desired list into the params of the function call.
By default the the list controls use the same properties as the parent but, you can feed an alternate into the altTemplate param.
Hope it helps someone.
EditEdit:
What it actually looks like and added some stuff to make it less crummy.

Add the following script to an "field" control and your desired list into the params of the function call.
By default the the list controls use the same properties as the parent but, you can feed an alternate into the altTemplate param.
Hope it helps someone.
Code: Select all
on mouseDown
if (the short name of me = "choice") then
get the parent of the owner of the owner of me
put it into parent
set the text of parent to the text of me
set the visible of grp "popup" to false
else if (the short name of me = "background") then
set the visible of grp "popup" to false
end if
set the colorOverlay["color"] of me to black
set the colorOverlay["opacity"] of me to 100
end mouseDown
on mouseEnter
set the colorOverlay["opacity"] of me to 25
end mouseEnter
on mouseLeave
set the colorOverLay["opacity"] of me to 0
end mouseLeave
on mouseUp
set the colorOverlay["opacity"] of me to 0
//change the first param to your list
get PopupButton("Choice 1;Choice 2;Choice 3;Choice 4", "parent")
end mouseUp
//inList = semicolon delimited list of items
//align = positioning mode, "parent" list is positioned under the parent, "center" list is centered on the card
//altTemplate = reference to the object/field to use as the template, default is none i.e. same properties as this field
function PopupButton listIn, align, altTemplate
lock screen
if (the backgroundColor of me = empty) then set the backgroundColor of me to white
if (exists(grp "popup")) then delete grp "popup"
create grp "popup"
put line 1 to 20 of the script of me into tempScript
set the parent of grp "popup" to the long id of me
set the width of templateGraphic to the width of this card
set the height of templateGraphic to the height of this card
set the left of templateGraphic to 0
set the top of templateGraphic to 0
set the opaque of templateGraphic to true
set the backgroundColor of templateGraphic to black
set the blendLevel of templateGraphic to 50
set the lineSize of templateGraphic to 0
set the threeD of templateGraphic to false
set the traversalOn of templateGraphic to false
set the script of templateGraphic to tempScript
create grc "background" in grp "popup"
create grp "list" in grp "popup"
set the outerGlow["opacity"] of grp "list" of grp "popup" to 255
if (altTemplate <> empty) then
//change according to your needs
set the properties of templateField to the properties of fld altTemplate
else
set the properties of templateField to the properties of me
end if
set the showBorder of templateField to false
set the dropShadow["opacity"] of templateField to 0
set the innerShadow["opacity"] of templateField to 0
set the outerGlow["opacity"] of templateField to 0
set the innerGlow["opacity"] of templateField to 0
set the textSize of templateField to the textSize of me - (the textSize of me /15)
set the script of templateField to tempScript
put the num of lines in inList into buttonCount
put 0 into buttonOffset
put the height of me + buttonOffset into buttonHeight
if (align = "center") then
put (the height of this card - (buttonHeight*buttonCount))/2 into y
put the width of this card/2 into x
else if (align = "parent") then
put the bottom of me + (buttonHeight/2) + buttonOffset into y
put item 1 of the loc of me into x
end if
set the blendLevel of templateGraphic to 0
put the backgroundColor of me into tempColor
put empty into lineColor
repeat for each item c in tempColor
if (lineColor <> empty) then put "," after lineColor
put round(c/1.1) after lineColor
end repeat
answer lineColor
set the backgroundColor of templateGraphic to lineColor
set the width of templateGraphic to the width of me
set the height of templateGraphic to 1
set itemDel to ";"
repeat for each item i in listIn
set the text of templateField to i
set the loc of templateField to x, y
create fld "choice" in grp "list" of grp "popup"
add buttonHeight/2 to y
set the loc templateGraphic to x, y
create grc "filler_1" in grp "list" of grp "popup"
add buttonHeight/2+1 to y
end repeat
delete the last graphic
reset the templateGraphic
reset the templateField
end PopupButton
What it actually looks like and added some stuff to make it less crummy.
