
-----------------------------------------------------------------------
--# Custom Tooltips (with images, fancy fonts, etc...
-----------------------------------------------------------------------

include GtkEngine.e

constant docs = `<u><b>Custom Tooltip</b></u>
Mouse over (don't click) the OK button 
to see a custom-made tooltip.

<small>(Change the slider to change the tooltip contents!)</small>
`
-----------------------------------------------------
-- create a custom tooltip window;
-----------------------------------------------------

constant mytip = create(GtkWindow,
    "name=gtk-tooltip,title=My own tooltip window,size=120x80,border=10,decorated=FALSE")

constant tipanel = create(GtkGrid)
    add(mytip,tipanel)
    show(tipanel)

constant tiptxt1 = `<span><u><b>Custom Tooltip</b></u>

I made this myself! 

</span>
`
constant tiptxt2 = `<span><u><b>Custom Tooltip</b></u>

I made this myself! 

Heat Level: %d (Bwa Ha Hah!)

</span>
`
constant tip = create(GtkLabel,{
    {"markup",tiptxt1},
    {"color","white"}})
    set(tipanel,"attach",tip,1,2,1,1)
    show(tip)

constant img = create(GtkImage,"face-devilish",64)
    set(tipanel,"attach",img,1,1,1,1)
    show(img)
    
constant bkgnd = create(GtkImage,"thumbnails/fire.png")
    set(tipanel,"attach",bkgnd,1,1,2,2)
    show(bkgnd)
    
-----------------------------------------------------
-- create main window;
-----------------------------------------------------
constant win = create(GtkWindow,"size=300x100,border=10,position=1")
    connect(win,"destroy","Quit")

constant panel = create(GtkBox,VERTICAL)
    add(win,panel)

constant lbl = create(GtkLabel)
    set(lbl,"markup",docs)
    add(panel,lbl)
    
constant scale = create(GtkScale,HORIZONTAL,0,100,1)
    connect(scale,"value-changed",_("UpdateCustomToolTip"))
    set(scale,"value pos",GTK_POS_BOTTOM)
    pack(panel,scale,TRUE,TRUE)

------------------------------------------------------------
-- add scale values
------------------------------------------------------------
constant fmt = "<span size='x-small' color='red'>%d</span>"
constant min = 0, max = 100, step = 1
    for i = min to max by 10 do
        set(scale,"add mark",i,GTK_POS_TOP,sprintf(fmt,i))
    end for

-------------------------------------------
-- regular button with added custom tooltip
-------------------------------------------
constant 
    btn1 = create(GtkButton,"gtk-quit","Quit"),
    btn2 = create(GtkButton,{
        {"label","gtk-ok"},
        {"use stock",TRUE},
        {"tooltip text","-"}, -- important, window won't pop up otherwise
        {"tooltip window",mytip},
        {"has tooltip",TRUE}})
    
constant box = create(GtkButtonBox)
    add(box,{btn1,btn2})
    pack(panel,-box)

show_all(win)
main()

------------------------------
function UpdateCustomToolTip()
------------------------------
integer heat = get(scale,"value")
if heat > 0 then
    set(tip,"markup",sprintf(tiptxt2,heat))
else
    set(tip,"markup",tiptxt1)
end if
return 1
end function
