Pastey terse version
- Posted by petelomax
Feb 04, 2021
include pGUIC.e
constant docs = `
Elements have a Data space
which you can use to declare and pass
multiple key/value pairs`
constant -- answers are encrypted to avoid overturning the legumes;
q1 = "What is purple and conquered the world?",
a1 = "PGk+QWxleGFuZGVyIHRoZSBHcmFwZSE8L2k+",
q2 = "What lies at the bottom of the ocean and twitches?",
a2 = "PGk+QSBuZXJ2b3VzIHdyZWNrLjwvaT4=",
q3 = "Why is Christmas just like another day at the office?",
a3 = "WW91IGRvIGFsbCBvZiB0aGUgd29yayBhbmQgdGhlIGZhdCBndXkKaW4gdGhlIHN1aXQgZ2V0cyBhbGwgdGhlIGNyZWRpdC4="
function ShowMe(Ihandle ctl)
Element button = get_element_by_handle(ctl)
string title = button.tooltip_text,
question = button.get_data("Question"), -- get data items by name;
answer = button.get_data("Answer")
answer = substitute_all(decode_base64(answer),{"<i>","</i>"},{"",""})
-- now we build our own custom dialog;
Label ans = new({answer,`FONT="Courier Bold Italic 18"`})
Hbox bx = new({{Filler(),ans,Filler()},"MARGIN=10x20"})
Expander expd = new({bx,`TITLE="Click here to see the answer...", STATE=CLOSE`})
Label icon = new({"","IMAGE=IUP_IconMessageHelp, PADDING=10x10"})
Label qlbl = new(Label,{question})
Hbox qbox = new({{Filler(),icon,qlbl,Filler()},"MARGIN=0x20, NORMALIZESIZE=VERTICAL"})
Vbox vbox = new({{qbox,expd}})
Window dlg = new({vbox})
dlg.title = title
dlg.size = "600x250"
dlg.parent = ctl
dlg.popup(IUP_LEFTPARENT,IUP_TOPPARENT)
-- delete(dlg) -- NB crashes on <= 0.8.3
return 1
end function
IupOpen()
IupImageLibOpen()
Label lbl = new({docs})
Hbox lbox = new({{Filler(),lbl,Filler()}})
Button btn1 = new({"Question _1",ShowMe,`TIP="World History", IMAGE=IUP_MessageHelp, PADDING=5x5`})
btn1.set_data("Question",q1)
btn1.set_data("Answer",a1)
Button btn2 = new({"Question _2",ShowMe,`TIP="Science", IMAGE=IUP_MessageHelp, PADDING=5x5`})
btn2.set_data("Question",q2)
btn2.set_data("Answer",a2)
Button btn3 = new({"Question _3",ShowMe,`TIP="Business", IMAGE=IUP_MessageHelp, PADDING=5x5`})
btn3.set_data("Question",q3)
btn3.set_data("Answer",a3)
Hbox box = new({{btn1,Filler(),btn2,Filler(),btn3},"GAP=5"})
Vbox pan = new({{lbox,Filler(),box},"GAP=5,MARGIN=10x10"})
Window win = new({pan,`TITLE="IupExpander and Data Passing"`})
win.show()
IupMainLoop()
--delete(win) -- (may crash on <= 0.8.3)